datasette-geojson-map
datasette-geojson-map copied to clipboard
Search based on map bounds
Right now, I run a query and the map fits the bounds of the returned features. But, if I have a bounding box, I could go the other way and search features within that box. This is especially fast if I have a spatial index.
Depending on the size of the dataset, this might run into the max rows setting.
Here's the hook to use: https://docs.datasette.io/en/stable/plugin_hooks.html#filters-from-request-request-database-table-datasette
This probably has to be SpatiaLite only, and might be worth requiring a spatial index.
What's the best way to do a bbox query? Some comparisons:
- full scan is slow but simple to write (have to filter out null geometries, or things get weird)
- Spatial index with a subquery is fast but feels like a weird way to do it
This has to work with any geometry type, so I can't assume anything about the geometry
itself.
Here's how datasette-leaflet-freedraw does it: https://github.com/simonw/datasette-leaflet-freedraw/blob/main/datasette_leaflet_freedraw/init.py#L26-L62