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

Even Rouault even.rouault at spatialys.com
Wed Dec 20 12:05:38 PST 2023


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* 
> <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.
>
> http://www.creaf.uab.cat/_signatura/line.gif
>
>
> _______________________________________________
> gdal-dev mailing list
> 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/e920137d/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 3657 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/e920137d/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 2547 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/e920137d/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 505 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/e920137d/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 446 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/e920137d/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 553 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/e920137d/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.png
Type: image/png
Size: 582 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/e920137d/attachment-0011.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image007.jpg
Type: image/jpeg
Size: 2208 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/e920137d/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image008.jpg
Type: image/jpeg
Size: 1111 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231220/e920137d/attachment-0003.jpg>


More information about the gdal-dev mailing list