[gdal-dev] GetFeatures 1-indexed for spatialite?

Even Rouault even.rouault at spatialys.com
Mon Feb 23 12:46:26 PST 2015


Le lundi 23 février 2015 19:40:42, Matt Perry a écrit :
> I'm running into some strange behavior with the Spatialite driver,
> accessing features through the ogr python bindings.
> 
>     layer.GetFeature(0) == None
>     layer.GetFeature(1) == ...   # first feature
> 
> for spatialite layers only; all other drivers appear to be 0-indexed.
> 
> More details and code to reproduce:
> https://github.com/perrygeo/python-raster-stats/issues/55#issuecomment-7560
> 2253
> 
> I'm using GDAL 1.11.1 on OS X via homebrew and the latest python
> bindings from pypi. Is this a bug or undocumented behavior?

Matt,

I'd say driver specific behaviour. Drivers for DBMS should return a feature ID 
that is the value of the integer primary key of the table (generally starting 
at 1). For other drivers shch as shapefile etc, the convention may change 
according to the driver.
Anyway in the general case there might be holes in numbering in case of 
deleted features. So the recommanded way of interating over features is to 
call GetNextFeature(), as GetFeature() might be slow in some drivers due to 
the lack of indexing or proper method to seek to an arbitrary feature.

Even

> 
> Matt Perry
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list