[gdal-dev] 1.11 OGR_F_SetFieldDouble() then OGR_F_GetFieldAsDouble() always returns zero

Nik Sands nik at nixanz.com
Mon Jan 2 16:24:32 PST 2017


Hi List.  I'm using GDAL/OGR 1.11 in an Objective-C (iOS)
application.

I'm attempting to store double values in an OFTReal field using
OGR_F_SetFieldDouble() and then to retrieve these values later using
OGR_F_GetFieldAsDouble().  If I retrieve the value immediately, it
works fine.  However, after closing and re-opening the
datasource/layer, I only ever get zero (0.0) values.  I am running
syncToDisk() after writing values.

I'm using the Esri Shapefile driver.

The code used for writing is:
-----------------------------------------------------------------------

i = OGR_F_GetFieldIndex(feature.feature, "Time");

if ( i > -1 ) {

OGR_F_SetFieldDouble(feature.feature, i, [[NSDate date]
timeIntervalSince1970]);

NSLog(@"Wrote %ld Date  %f", OGR_F_GetFID(feature.feature),
OGR_F_GetFieldAsDouble(feature.feature, i));

//  LOGS EXPECTED NON-ZERO VALUE HERE

}

OGR_L_SyncToDisk(_layer);
-----------------------------------------------------------------------

The code used for reading after re-opening the data source is:
-----------------------------------------------------------------------

i = OGR_F_GetFieldIndex(_feature, "Time");

if ( i > -1 ) {

NSLog(@"Got %ld Cell Date:  %f", OGR_F_GetFID(_feature),
OGR_F_GetFieldAsDouble(_feature, i));

//  ALWAYS LOGS 0.0 HERE (logs a valid FID)

}
------------------------------------------------------------------------

Am I doing anything obviously wrong?  Any ideas why this is not
working as I expected?

Let me know if there is any more code that would make it more clear.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170103/8737f5a7/attachment.html>


More information about the gdal-dev mailing list