ITADN

GeoPackage support

#3Pull Requestrcoup 创建于 2023-09-26
R
rcoupcommented
Here's a really rough cut at GeoPackage support Why? GeoPackage is missing a lightweight implementation IMO: libgpkg isn't maintained, Spatialite is really complex and includes all sorts of other stuff; GDAL's implementation is internal. ### What does this do right now? * detects and parses GeoPackage geometries to TG geometries * implements functions as required by the spec for updating spatial indexes: `ST_IsEmpty`, `ST_MinX`, `ST_MaxX`, `ST_MinY`, `ST_MaxY` * outputs geopackage geometries via `tg_to_gpkg()` * check whether a DB is a geopackage via `tg_is_geopackage_db()` ### Demo ```console $ sqlite3 sample1_2.gpkg sqlite> .load ./dist/tg0 sqlite> PRAGMA trusted_schema=1; sqlite> SELECT tg_is_geopackage_db(); tg_is_geopackage_db() --------------------- 1 sqlite> SELECT objectid, name, tg_to_geojson(shape) FROM counties WHERE objectid=1; OBJECTID NAME tg_to_geojson(shape) -------- ----------------- ------------------------------------------------------------ 1 Lake of the Woods {"type":"MultiPolygon","coordinates":[[[[-95.34283129299996, 48.54667929400006],[-95.21983979799995,48.54435776100007],[- 95.21178801599996,48.36900473700007],[-94.43169004799995,48. 36821245400006],[-94.43063447299994,48.71078528100003],[-94. 57031273699994,48.71367626400007],[-94.69443202199994,48.777 61553000005],[-94.68124994599998,48.877161311000066],[-94.83 203926099998,49.33080591700008],[-95.15186733499996,49.37173 0144000026],[-95.15774988899994,48.999995915000056],[-95.276 65711499998,48.999991212000054],[-95.31012057999999,48.99339 545600003],[-95.32323587299999,48.97895633500008],[-95.32091 643199999,48.96097701200006],[-95.30375729499997,48.94593892 000006],[-95.31417174699999,48.93207200400008],[-95.29026019 099996,48.902949584000055],[-95.21957849499995,48.8794465170 00076],[-95.13382122699994,48.89448477500008],[-95.094910358 99998,48.91176241000005],[-95.09435904099996,48.717357531000 06],[-95.34105289899998,48.71517198200007],[-95.342831292999 96,48.54667929400006]]]]} sqlite> UPDATE counties SET shape = tg_to_gpkg('{ "type": "Polygon", "coordinates": [[[30.0, 10.0], [40.0, 40.0], [20.0, 40.0], [10.0, 20.0], [30.0, 10.0]]] }') WHERE objectid=1; sqlite> SELECT objectid, name, tg_to_geojson(shape) FROM counties WHERE objectid=1; OBJECTID NAME tg_to_geojson(shape) -------- ----------------- ------------------------------------------------------------ 1 Lake of the Woods {"type":"Polygon","coordinates":[[[30,10],[40,40],[20,40],[1 0,20],[30,10]]]} ``` ### Where to next? Obviously you have some more you want to do. With respect to GeoPackage support (if you're interested in adopting it): 1. I wonder if there's a way to avoid the `tg_to_gpkg()` method for UPDATEs & INSERTs. One ideais to go into some sort of auto-geopackage mode where the extension operates natively using GPKG geometries rather than TG geometries. 2. Probably needs some lightweight functions for setting up geopackage tables with indexes/triggers.
合并状态:未合并 4 条评论