Opened 6 months ago

Closed 6 months ago

Last modified 6 months ago

#6799 closed defect (fixed)

layer.GetFeature() failing

Reported by: jivan Owned by: warmerdam
Priority: normal Milestone: 2.1.4
Component: default Version: 2.1.0
Severity: normal Keywords:
Cc:

Description (last modified by jivan)

Works correctly:

from osgeo import ogr

geopackage = 'rosarito-osm-20170131.gpkg'
layer_name = 'amenities_all_points'

driver = ogr.GetDriverByName("GPKG")
dataSource = driver.Open(geopackage)
print dataSource
layer = dataSource.GetLayer(layer_name)

for feature in layer:
    print feature
layer.ResetReading()

Returns None for every feature:

from osgeo import ogr

geopackage = 'rosarito-osm-20170131.gpkg'
layer_name = 'amenities_all_points'

driver = ogr.GetDriverByName("GPKG")
dataSource = driver.Open(geopackage)
print dataSource
layer = dataSource.GetLayer(layer_name)

for i in range(layer.GetFeatureCount()):
    feature = layer.GetFeature(i)
    print feature

Attachments (1)

rosarito-osm-20170131.gpkg (611.0 KB) - added by jivan 6 months ago.
Geopackage file with data from OSM.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 months ago by jivan

Description: modified (diff)

Changed 6 months ago by jivan

Attachment: rosarito-osm-20170131.gpkg added

Geopackage file with data from OSM.

comment:2 Changed 6 months ago by bitner

Just to add a bit of context, this appears to be the case with geopackages. If you convert the gpkg to a shapefile and rerun the two examples that Jivan pointed out both approaches work as expected.

comment:3 Changed 6 months ago by Even Rouault

Resolution: fixed
Status: newclosed

In 37266:

GPKG: make GetFeature?() works on non conformant tables that have no integer primary key field (fixes #6799), and be robust to non standard column types

comment:4 Changed 6 months ago by Even Rouault

In 37267:

GPKG: make GetFeature?() works on non conformant tables that have no integer primary key field (fixes #6799), and be robust to non standard column types

comment:5 Changed 6 months ago by Even Rouault

Milestone: 2.1.4

The tables in the geopackage are non compliant with the specification, as they lack a INTEGER PRIMARY KEY field

http://www.geopackage.org/spec/#feature_user_tables: """ Requirement 29

A GeoPackage MAY contain tables or updateable views containing vector features. Every such feature table or view in a GeoPackage SHALL have a column with column type INTEGER and PRIMARY KEY AUTOINCREMENT column constraints

"""

I've nevertheless fixed GetFeature?() to work in the case such a column is missing

Note: See TracTickets for help on using tickets.