Skip to main content

datasette-geojson-map

PyPI Changelog Tests License

Render a map for any query with a geometry column

Installation

Install this plugin in the same environment as Datasette.

$ datasette install datasette-geojson-map

Usage

Start by loading a GIS file.

For example, you might use geojson-to-sqlite or shapefile-to-sqlite to load neighborhood boundaries into a SQLite database.

wget -O neighborhoods.geojson https://opendata.arcgis.com/datasets/3525b0ee6e6b427f9aab5d0a1d0a1a28_0.geojson
geojson-to-sqlite boston.db neighborhoods neighborhoods.geojson

(The command above uses Spatialite, but that's not required.)

Start up datasette and navigate to the neighborhoods table.

datasette serve boston.db

# in another terminal tab
open http://localhost:8001/boston/neighborhoods

You should see a map centered on Boston with each neighborhood outlined. Clicking a boundary will bring up a popup with details on that feature.

Boston neighbhorhoods map

This plugin relies on (and will install) datasette-geojson. Any query that includes a geometry column will produce a map of the results. This also includes single row views.

Run the included demo project to see it live.

Configuration

This project uses the same map configuration as datasette-cluster-map. Here's how you would use Stamen's terrain tiles:

plugins:
  datasette-geojson-map:
    tile_layer: https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.{ext}
    tile_layer_options:
      attribution: >-
        Map tiles by <a href="http://stamen.com">Stamen Design</a>, 
        under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. 
        Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, 
        under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.
      subdomains: abcd
      minZoom: 1
      maxZoom: 16
      ext: jpg

Options:

  • tile_layer: Use a URL template that can be passed to a Leaflet Tilelayer
  • tile_layer_options: All options will be passed to the tile layer. See Leaflet documentation for more on possible values here.

Styling map features

Map features can be styled using the simplestyle-spec. This requires setting specific fields on returned rows. Here's an example:

SELECT Name, geometry, "#ff0000" as fill, "#0000ff" as stroke, 0.2 as stroke-width,  from neighborhoods

That will render a neighborhood map where each polygon is filled in red, outlined in blue and lines are 0.2 pixels wide.

A more useful approach would use the CASE statement to color features based on data:

SELECT
  Name,
  geometry,
  CASE
    Name
    WHEN "Roslindale" THEN "#ff0000"
    WHEN "Dorchester" THEN "#0000ff"
    ELSE "#dddddd"
  END fill
FROM
  neighborhoods

This will fill Roslindale in red, Dorchester in blue and all other neighborhoods in gray.

Development

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

cd datasette-geojson-map
python3 -mvenv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Metadata

Release files for datasette-geojson-map 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datasette-geojson-map 0.5.0
File Size Uploaded Provenance Actions
datasette-geojson-map-0.5.0.tar.gz 10.0 kB Without provenance Details for datasette-geojson-map-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datasette-geojson-map 0.5.0
File Interpreter ABI Platform Actions
datasette_geojson_map-0.5.0-py3-none-any.whl Python 3 none any Details for datasette_geojson_map-0.5.0-py3-none-any.whl

Total release size: 20.9 kB

Release files / datasette-geojson-map-0.5.0.tar.gz

Download URL datasette-geojson-map-0.5.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c463744c2a13ac4dedb7830545223e3966e901842daebaad62271ba9abb727e3
BLAKE2b-256 checksum
How to use checksums
4d59de3e4cce5efd0f759a1ee56a641383b424b81749e2574cfd9870df00638f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / datasette_geojson_map-0.5.0-py3-none-any.whl

Download URL datasette_geojson_map-0.5.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bbc8380687a7c00ec9a11a8a2cc8102da89d3143d5eed4e4d4b0f8f66b9d4a7
BLAKE2b-256 checksum
How to use checksums
ff63223c02f61926436cc752ecec11e0a93cf43197b5985eeb1f4cd2ea22c682
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Security for datasette-geojson-map 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page