Skip to main content

datasette-geojson

PyPI Changelog Tests License

Add GeoJSON as an output option for datasette queries.

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-geojson

Usage

To render GeoJSON, add a .geojson extension to any query URL that includes a geometry column. That column should be a valid GeoJSON geometry.

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 --spatial-index # create a spatial index
datasette serve boston.db --load-extension spatialite

If you're using Spatialite, the geometry column will be in a binary format. If not, make sure the geometry column is a well-formed GeoJSON geometry. If you used geojson-to-sqlite or shapefile-to-sqlite, you should be all set.

Run this query in Datasette and you'll see a link to download GeoJSON:

select
  rowid,
  OBJECTID,
  Name,
  Acres,
  Neighborhood_ID,
  SqMiles,
  ShapeSTArea,
  ShapeSTLength,
  geometry
from
  neighborhoods
order by
  rowid
limit
  101

Note that the geometry column needs to be explicitly named geometry or you won't get the option to export GeoJSON. If you want to use a different column, rename it with AS: SELECT other AS geometry FROM my_table.

export geojson

Development

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

cd datasette-geojson
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

Metadata

Release files for datasette-geojson 0.4.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 0.4.0
File Size Uploaded Provenance
datasette-geojson-0.4.0.tar.gz 3.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for datasette-geojson 0.4.0
File Interpreter ABI Platform
datasette_geojson-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.1 kB

Release files / datasette-geojson-0.4.0.tar.gz

Download URL datasette-geojson-0.4.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ecf7ca75b084b57d0a8007cfb9965cdae53fbb29fe8f0a41feffff941a23da8a
BLAKE2b-256 checksum
How to use checksums
f6d3a2cc7e759ca701e403bb2470f9fce14170ead6fc0a309061edac2b9aa0e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / datasette_geojson-0.4.0-py3-none-any.whl

Download URL datasette_geojson-0.4.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6de231185b40d1ea07775f0e09d15ac2d9879685b8b683a84442a96371b971f4
BLAKE2b-256 checksum
How to use checksums
39f7ecc8fd2265efe8e0866b34e0e7ecb7ce08e5559d466f8e9dbe6360f151eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Security for datasette-geojson 0.4.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