eyeseast / datasette-geojson-map

Render a map for any query with a geometry column
23 stars 1 forks source link

Search based on map bounds #15

Open eyeseast opened 2 years ago

eyeseast commented 2 years ago

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.

eyeseast commented 2 years ago

Depending on the size of the dataset, this might run into the max rows setting.

eyeseast commented 2 years ago

Here's the hook to use: https://docs.datasette.io/en/stable/plugin_hooks.html#filters-from-request-request-database-table-datasette

eyeseast commented 2 years ago

This probably has to be SpatiaLite only, and might be worth requiring a spatial index.

eyeseast commented 2 years ago

What's the best way to do a bbox query? Some comparisons:

This has to work with any geometry type, so I can't assume anything about the geometry itself.

eyeseast commented 2 years ago

Here's how datasette-leaflet-freedraw does it: https://github.com/simonw/datasette-leaflet-freedraw/blob/main/datasette_leaflet_freedraw/__init__.py#L26-L62