Add GeoJSON as an output option
Project description
datasette-geojson
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
.
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
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
Built Distribution
File details
Details for the file datasette-geojson-0.4.0.tar.gz
.
File metadata
- Download URL: datasette-geojson-0.4.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecf7ca75b084b57d0a8007cfb9965cdae53fbb29fe8f0a41feffff941a23da8a |
|
MD5 | 1001d985f01458079d2f0edf24df44f4 |
|
BLAKE2b-256 | f6d3a2cc7e759ca701e403bb2470f9fce14170ead6fc0a309061edac2b9aa0e3 |
File details
Details for the file datasette_geojson-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: datasette_geojson-0.4.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6de231185b40d1ea07775f0e09d15ac2d9879685b8b683a84442a96371b971f4 |
|
MD5 | 3a665a3f61354003716e5d8a28bebf95 |
|
BLAKE2b-256 | 39f7ecc8fd2265efe8e0866b34e0e7ecb7ce08e5559d466f8e9dbe6360f151eb |