[gdal-dev] Writting a shapefile from C++ API: case a field of the OFTReal type

Roland Baviere roland.baviere at districtlab.eu
Sat Oct 14 07:16:42 PDT 2023


Hi all,

I've just found that a declaration of this type solved my problem:

OGRFieldDefn oField( "Val dbl", OFTReal );

// oField.SetWidth(64);


I have no idea why.

I suggest that the tutorial is updated to reflect this (common) case.


Kind regards,


Roland




Le sam. 14 oct. 2023 à 16:12, Roland Baviere <roland.baviere at districtlab.eu>
a écrit :

> Dear Community,
>
> I hope this e-mel finds you well.
>
> I am trying to write a shaprfile from a C++ application (windows),
> following the tutorial found here:
> https://gdal.org/tutorials/vector_api_tut.html#writing-to-ogr
>
> Everything works fine except for Fields of the OFTReal type, which are
> systematically truncated in the produced shapefile, as if they were
> declared as integer.
>
> The example illustrates the declaration of a string type:
>
> OGRFieldDefn oField( "Name", OFTString );
> oField.SetWidth(32);
>
> I tried to adapt it to the case were I want to serialize a field of the double type:
>
>
> OGRFieldDefn oField( "Val dbl", OFTReal );
>
> oField.SetWidth(64);
>
>
>
> but the aforementionned truncation error occurs.
>
>
> What am I doing wrong?
>
>
> Thanks a lot for your help and time.
>
>
> Kind regards,
>
>
> Roland BAVIERE
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231014/e8ed7aff/attachment.htm>


More information about the gdal-dev mailing list