connect¶
connect
¶
Open a GeoPackage with SpatiaLite loaded.
| PARAMETER | DESCRIPTION |
|---|---|
gpkg_path
|
Path to the GeoPackage file.
TYPE:
|
enable_gpkg_mode
|
Enable GeoPackage mode (default True). Set to False when you need ST_AsText/ST_AsBinary to work reliably after close/reopen cycles (SpatiaLite 5.1.0 bug).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Connection
|
sqlite3.Connection with SpatiaLite extension loaded. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the GeoPackage file does not exist. |
RuntimeError
|
If SpatiaLite cannot be loaded. |
Example
con = connect("data.gpkg") con.execute("SELECT COUNT(*) FROM buildings").fetchone()[0] 515013
Source code in geopkgtoolkit/_spatialite.py
list_layers
¶
List all feature layers in a GeoPackage connection.
| PARAMETER | DESCRIPTION |
|---|---|
con
|
A sqlite3 connection with SpatiaLite loaded.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict]
|
List of dicts with keys: table_name, column_name, geometry_type, srs_id. |