#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 )
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)
Change History (6)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
by , 8 years ago
Attachment: | rosarito-osm-20170131.gpkg added |
---|
comment:2 by , 8 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:5 by , 8 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
Geopackage file with data from OSM.