TransWikia.com

Writing Non Spatial Table into Geopackage - Python

Geographic Information Systems Asked by JamesLeversha on December 30, 2020

Just wondering how to write a non spatial (aspatial) table to geopackage using python. I have attempted using Fiona,

geopackage = 'some_geo.gpkg'    
layer = 'test_layer'
schema = {'geometry': {'type': 'aspatial'}, 'properties': [('filename', 'str')]}

with fiona.open(geopackage, 'w', layer=layer, driver='GPKG', schema=schema) as db:
    record = {'geometry': {'type': 'aspatial'},
              'properties': {'filename': filename[:-4]}}
    db.write(record)

This comes up with a Attribute Error because its trying to strip a dict, but I dont think thats the real issue here.

2 Answers

Regular SQLITE3 you can use the .dump command to copy data from one database to another.

Answered by GeospatialInformationTech on December 30, 2020

Yes looks like 'aspatial' was deprecated in geopackage v1.2 https://gdal.org/drivers/vector/geopackage_aspatial.html

Have you tried simply not specifying the geometry field.

geopackage = 'some_geo.gpkg'    
layer = 'test_layer'
schema = {'properties': [('filename', 'str')]}

with fiona.open(geopackage, 'w', layer=layer, driver='GPKG', schema=schema) as db:
    record = {'properties': {'filename': filename[:-4]}}
    db.write(record)

Also here https://fiona.readthedocs.io/en/latest/manual.html#records under the 'writing records from scratch' section, it suggests using the output_driver = geojson maybe in your instance you need to specify json ? geojson my force a geometry field name in the record.

Answered by nr_aus on December 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP