[gdal-dev] Unable to get features from OpenFileGDB data source

Even Rouault even.rouault at mines-paris.org
Thu Jul 10 02:44:18 PDT 2014


Nik,

By using GetFeature() the way you do, you assume that the passed parameter is an
index number whereas it is a feature identifier. In most drivers that don't
really support the concept of feature identifier, both concepts are identical.
But in FileGDB, Feature Identifiers start at 1, and not 0. And you can have
holes in the numbering due to deleted records (this is the case with layer
PointBonnetHill that has a single feature whose FID is 2)
For efficiency and robustness with all formats, I'd encourage you to use
GetNextFeature() instead. And you don't need to call OGR_L_GetFeatureCount()
which can be a slow operation on some drivers. Just iterate over features with
GetNextFeature() until it returns a NULL pointer.

Best regards,

Even


> Hi GDAL devs,
>
> I'm trying to support ESRI File Geodatabase support (read-only) in my iOS app
> and have recently got GDAL 1.11.0 compiled and running in the app for its new
> OpenFileGDB driver.  However, I've been unable to extract features from GDBs
> using the exact same code that works fine for other formats/drivers.
>
> An extract of the code in question is:
>
> ------------------------
> 	ds = OGROpen(path, FALSE, NULL);
> 	layerCount = OGR_DS_GetLayerCount(ds);
>
> 	for ( int i = 0; i < layerCount; i++ )
> 	{
> 		OGRLayerH sourceLayer = OGR_DS_GetLayer(ds, i);
> 		int sourceFeatureCount = OGR_L_GetFeatureCount(sourceLayer, YES);
>
> 		for ( long j = 0; j < sourceFeatureCount; j++ )
> 		{
> 			OGRFeatureH sourceFeature = OGR_L_GetFeature(sourceLayer, j);
>
> 			if ( ! sourceFeature )
> 				NSLog(@"Failed to get feature at index '%ld' from layer at index '%d'!",
> j, i);
> ------------------------
>
> The NSLog line is always run for my GDB data sources but never for data
> sources of other formats.  So for GDB data sources 'sourceFeature' is always
> NULL and of course this causes all subsequent OGR functions to which
> 'sourceFeature' is passed to fail with errors like:
>
> 	ERROR 10: Pointer 'hFeat' is NULL in 'OGR_...'.
>
> Using the CLI utility 'ogrinfo' (different build of GDAL) on the same
> datasource works fine showing all the features are there as expected and it
> works fine in ESRI ArcGIS.  And the fact that it gets into the second 'for'
> loop at all indicates that there are features there, and yet it cannot get
> the feature at index '0'.
>
> The File Geodatabase datasource can be downloaded for testing from:
>
> 	https://dl.dropboxusercontent.com/u/12436846/Bandicoots.gdb.zip
>
> Can anybody advise me on how I should trouble shoot this further, or how the
> problem can be resolved?
>
> Cheers,
> Nik.
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>




More information about the gdal-dev mailing list