How to write non-spatial records to GPKG? #1286
Replies: 3 comments
-
Diving into the code, the error I get comes from the way Adding a 'type:feature' field avoids the error but the table is then still written as 'spatial' with a geom field set to null, rather than a non-spatial table. I'm not sure what the GPKG standard say but I think this is not the intended behaviour. crs = fiona.crs.from_epsg(4326)
schema = {
'type': 'Feature',
'properties': {'schema_version': 'int',
'source': 'str',
'heating_degree_days': 'float',
'cooling_degree_days': 'float'}}
data = {
'type': 'Feature',
'properties': {'schema_version': 1,
'source': 'OneBuilding TMY',
'heating_degree_days': 3322.016666666667,
'cooling_degree_days': 6781.799999999999}}
with fiona.open("package.gpkg", 'w', driver='GPKG', crs=crs, schema=schema, layer='climate',
OVERWRITE='YES',
SPATIAL_INDEX='NO'
) as package:
package.write(data) |
Beta Was this translation helpful? Give feedback.
-
@mangecoeur Fiona doesn't permit reading and writing non spatial data. It's not this way intentionally, but I am reluctant to add this because I don't want users to begin to depend on fiona for something that it isn't even second best at. It's my recommendation that one use, for example, sqlite3 for managing complex Geopackage databases. That said, I'm not very opposed to letting fiona write non-spatial tables if the changes to the codebase aren't complicating, and I'd be happy to review a PR. |
Beta Was this translation helpful? Give feedback.
-
Makes sense, AFAIU the GDAL GPKG driver should allow writing non spatial tables, so I think its possible without adding complexity. I will see if I can make it work. |
Beta Was this translation helpful? Give feedback.
-
Expected behavior and actual behavior.
The GPKG format allows to also add records without spatial data, however it's not clear how this can be done in fiona. Simply ommiting the geometry field causes an error (See below). Adding a geometry field with a value of None instead adds a geometry column filled with None
Steps to reproduce the problem.
Result
Fiona and GDAL version and provenance
Fiona 1.9.3 from pip, GDAL from homebrew
Beta Was this translation helpful? Give feedback.
All reactions