Skip to main content

Draw polygons on maps in Datasette

Project description

datasette-leaflet-freedraw

PyPI Changelog Tests License

Draw polygons on maps in Datasette

Project background: Drawing shapes on a map to query a SpatiaLite database.

Installation

Install this plugin in the same environment as Datasette.

$ datasette install datasette-leaflet-freedraw

Usage

If a table has a SpatiaLite geometry column, the plugin will add a map interface to the table page allowing users to draw a shape on the map to find rows with a geometry that intersects that shape.

The plugin can also work with arbitrary SQL queries. There it looks for input fields with a name of freedraw or that ends in _freedraw and replaces them with a map interface.

The map interface uses the FreeDraw Leaflet plugin.

Demo

You can try out this plugin to run searches against the GreenInfo Network California Protected Areas Database. Here's an example query showing mini parks in San Francisco:

select
  AsGeoJSON(geometry), *
from
  CPAD_2020a_SuperUnits
where
  PARK_NAME like '%mini%' and
  Intersects(GeomFromGeoJSON(:freedraw), geometry) = 1
  and CPAD_2020a_SuperUnits.rowid in (
    select
      rowid
    from
      SpatialIndex
    where
      f_table_name = 'CPAD_2020a_SuperUnits'
      and search_frame = GeomFromGeoJSON(:freedraw)
  )

Screenshot of the plugin in action

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-leaflet-freedraw
python3 -mvenv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and tests:

pip install -e '.[test]'

To run the tests:

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datasette-leaflet-freedraw-0.3.1.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datasette_leaflet_freedraw-0.3.1-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file datasette-leaflet-freedraw-0.3.1.tar.gz.

File metadata

  • Download URL: datasette-leaflet-freedraw-0.3.1.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for datasette-leaflet-freedraw-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7ee5d14a5804f834e2ee3b8e07e4fc6faa8725ae0cf9707f51a4b9ed3217454a
MD5 518ebd680b4b17b341f93e50764269ac
BLAKE2b-256 7d396bed00aa8b0937dab22533ed0bfa7df6eb79d353ffbdec2b0bd3b683915b

See more details on using hashes here.

File details

Details for the file datasette_leaflet_freedraw-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: datasette_leaflet_freedraw-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for datasette_leaflet_freedraw-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa2043b3318d3a44509d783596b90acd2e0ca0d9bd446033ed518249f995bef9
MD5 3291045585fd431f9fe36f9f3c42b0d6
BLAKE2b-256 e5d1b1f34ad7116e980d0921b2f5025c02e37decf5603b97fede43d51fe989a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page