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

Matt Perry perrygeo at gmail.com
Mon Feb 23 13:49:58 PST 2015


On Mon, Feb 23, 2015 at 12:46 PM, Even Rouault
<even.rouault at spatialys.com> wrote:
> 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.
>

Sounds like a good idea to rewrite with GetNextFeaure(). Thanks!


More information about the gdal-dev mailing list