Opened 7 years ago

Closed 7 years ago

Last modified 7 years 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 7 years ago.
Geopackage file with data from OSM.

Download all attachments as: .zip

Change History (6)

comment:1 by jivan, 7 years ago

Description: modified (diff)

by jivan, 7 years ago

Attachment: rosarito-osm-20170131.gpkg added

Geopackage file with data from OSM.

comment:2 by bitner, 7 years ago

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 by Even Rouault, 7 years ago

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 by Even Rouault, 7 years ago

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 by Even Rouault, 7 years ago

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.