I create an example GPKG file, example.gpkg
, with layer our_layer
:
import geopandas as gpd
import shapely.geometry
gpd.GeoSeries(
[
shapely.geometry.Polygon([[0, 0], [1, 0], [1, 1]]),
shapely.geometry.Polygon([[1, 2], [3, 4], [5, 0]]),
]
).to_file("example.gpkg", layer="our_layer")
Using this answer, I check if our_layer
has a spatial index:
ogrinfo -sql "SELECT HasSpatialIndex('our_layer', 'geom')" example.gpkg
Output:
INFO: Open of `example.gpkg'
using driver `GPKG' successful.
Layer name: SELECT
Geometry: Unknown (any)
Feature Count: 1
Layer SRS WKT:
(unknown)
HasSpatialIndex: Integer (0.0)
OGRFeature(SELECT):0
HasSpatialIndex (Integer) = 1
So our_layer
's geometry column, geom
has a spatial index. I would like to view the contents of this index. About SpatialIndex
, this says:
SpatialIndex simply is a generic virtual table wrapping any Spatial Index defined into the current DB-file.
I would like to view the contents of the SpatialIndex on our_layer
. Naively, I try:
ogrinfo -al -so example.gpkg SpatialIndex
Output:
INFO: Open of `example.gpkg'
using driver `GPKG' successful.
ERROR 1: Couldn't fetch requested layer SpatialIndex.
and:
ogrinfo -sql "SELECT * FROM SpatialIndex" example.gpkg
Output:
INFO: Open of `example.gpkg'
using driver `GPKG' successful.
ERROR 1: In ExecuteSQL(): sqlite3_prepare_v2(SELECT * FROM SpatialIndex):
no such table: SpatialIndex
Which raises the question:
How do I view the contents of spatial indexes within a GPKG file?