Quantcast

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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Nik Sands-3
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.

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 1.11 OGR_F_SetFieldDouble() then OGR_F_GetFieldAsDouble() always returns zero

Even Rouault-2

Nik,

 

Using OGR_F_SetFieldXXXXX() only modifies the in-memory value, but has no effect on serialization. You have to use OGR_L_SetFeature() to make sure that the modified feature is written back to the datasource.

 

As it seems to be a common pitfall, I'm going to improve the doc of the OGR_F_SetFieldXXXX functions to make that clear.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 1.11 OGR_F_SetFieldDouble() then OGR_F_GetFieldAsDouble() always returns zero

Nik Sands-3
Hey, thanks for this advice Even.  I think I may have actually stumbled on a similar issue in the past (with setting geometry) so I really should have known better.  

Thanks for the reminder.   Yes, an update to the doco would help newbies as well as people like me who only dabble around the edges.  

Cheers,
Nik.

-----------------------------------------
NIK SANDS
Line Tamer | Time Traveller | Space Cadet

> On 3 Jan 2017, at 6:40 pm, Even Rouault <[hidden email]> wrote:
>
> Nik,
>  
> Using OGR_F_SetFieldXXXXX() only modifies the in-memory value, but has no effect on serialization. You have to use OGR_L_SetFeature() to make sure that the modified feature is written back to the datasource.
>  
> As it seems to be a common pitfall, I'm going to improve the doc of the OGR_F_SetFieldXXXX functions to make that clear.
>  
> Even
>  
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Loading...