[gdal-dev] How to assign a new eType to a feature

Abel Pau a.pau at creaf.uab.cat
Wed Dec 20 12:50:23 PST 2023


Even,
thanks for the answer.

I saw it recently in the list but I didn’t relate with that!
Thanks. I understand! I think it’s a good idea have al sealed before. And as you can remember I would seal the number of features also :p

Thanks :)

De: Even Rouault <even.rouault at spatialys.com>
Enviado el: dimecres, 20 de desembre de 2023 21:06
Para: Abel Pau <a.pau at creaf.uab.cat>; gdal-dev at lists.osgeo.org
Asunto: Re: [gdal-dev] How to assign a new eType to a feature


Abel,

You should not change the type of field types (or the number of fields) once GetLayerDefn() has been called on the layer, after which the layer definition must be considered as sealed (cf recent RFC https://gdal.org/development/rfc/rfc97_feature_and_fielddefn_sealing.html), until potential calls from the user to CreateField()/DeleteField()/etc. which might unseal it. Changing field types during feature iteration would break expectations from users of the GDAL API (included GDAL tools such as ogr2ogr) and could cause nasty crashing bugs.

If you don't have a way to figure out the field type by looking at the header of your dataset, then you need to do a first reading pass to establish it (like done for example in the GeoJSON driver)

Even
Le 20/12/2023 à 20:58, Abel Pau via gdal-dev a écrit :
HI,
In the GetNewtRawFeature() I am processing all fields and a previusly OFTString type field has to be changed into OFTStringList type. After that, It’ll be probably a OFTString again.

I try to do that:
poFeature->GetDefnRef()->GetFieldDefn(nIField)->SetType(OFTStringList);

And when the destination driver gets it, the OFTStringList is again OFTString. I’ve lost the property by magic.

The line that does that is poDstFeature->SetFDefnUnsafe(poDstFDefn); in Translate() line5746 (probably).

So, there is a good way to change the type I’ve assigned in the constructor by the same but a “List” instead in the GetNextRawFeature()?

Sorry for asking a question (again) but I’ve been a long time trying to figure out what happens!

Thanks!

Abel Pau Garcia
GIS developer
[https://www.creaf.cat/sites/default/files/creaf-signature.png]
a.pau at creaf.uab.cat<mailto:a.pau at creaf.uab.cat>
Let's chat on Teams!<https://teams.microsoft.com/l/chat/0/0?users=a.pau@creaf.uab.cat>
Tel. +34 934814277
[https://www.creaf.cat/sites/default/files/so-en-signature.png]
[https://www.creaf.cat/sites/default/files/twitter-icon-signature.png]<https://twitter.com/CREAF_ecologia>[https://www.creaf.cat/sites/default/files/linkedin-icon-signature.png]<https://www.linkedin.com/company/1363052?trk=tyah&trkInfo=clickedVertical:company,clickedEntityId:1363052,idx:2-1-2,tarId:1465807877789,tas:creaf>[https://www.creaf.cat/sites/default/files/youtube-icon-signature.png]<https://www.youtube.com/c/creafecologia>[https://www.creaf.cat/sites/default/files/instagram-icon-signature.png]<https://www.instagram.com/CREAF_ecologia/>
www.creaf.cat<http://www.creaf.cat> | http://blog.creaf.cat
[https://www.creaf.cat/sites/default/files/uab_logo_signatura.png]
CREAF. Campus UAB. Edifici C. 08193 Bellaterra (Barcelona)

Before printing this electronic message, think about the environment.






_______________________________________________

gdal-dev mailing list

gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>

https://lists.osgeo.org/mailman/listinfo/gdal-dev

--

http://www.spatialys.com

My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 3657 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 2547 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 505 bytes
Desc: image003.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 446 bytes
Desc: image004.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 553 bytes
Desc: image005.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.png
Type: image/png
Size: 582 bytes
Desc: image006.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0011.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image007.jpg
Type: image/jpeg
Size: 2208 bytes
Desc: image007.jpg
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image008.jpg
Type: image/jpeg
Size: 1111 bytes
Desc: image008.jpg
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/7f946545/attachment-0003.jpg>


More information about the gdal-dev mailing list