datasette-geojson


Namedatasette-geojson JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/eyeseast/datasette-geojson
SummaryAdd GeoJSON as an output option
upload_time2023-01-06 21:24:40
maintainer
docs_urlNone
authorChris Amico
requires_python>=3.7
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # datasette-geojson

[![PyPI](https://img.shields.io/pypi/v/datasette-geojson.svg)](https://pypi.org/project/datasette-geojson/)
[![Changelog](https://img.shields.io/github/v/release/eyeseast/datasette-geojson?include_prereleases&label=changelog)](https://github.com/eyeseast/datasette-geojson/releases)
[![Tests](https://github.com/eyeseast/datasette-geojson/workflows/Test/badge.svg)](https://github.com/eyeseast/datasette-geojson/actions?query=workflow%3ATest)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/eyeseast/datasette-geojson/blob/main/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](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1).

For example, you might use [geojson-to-sqlite](https://pypi.org/project/geojson-to-sqlite/) or [shapefile-to-sqlite](https://pypi.org/project/shapefile-to-sqlite/) to load [neighborhood boundaries](https://bostonopendata-boston.opendata.arcgis.com/datasets/3525b0ee6e6b427f9aab5d0a1d0a1a28_0/explore) into a SQLite database.

```sh
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](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1). 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:

```sql
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](img/export-options.png)

## 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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eyeseast/datasette-geojson",
    "name": "datasette-geojson",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Chris Amico",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/f6/d3/a2cc7e759ca701e403bb2470f9fce14170ead6fc0a309061edac2b9aa0e3/datasette-geojson-0.4.0.tar.gz",
    "platform": null,
    "description": "# datasette-geojson\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-geojson.svg)](https://pypi.org/project/datasette-geojson/)\n[![Changelog](https://img.shields.io/github/v/release/eyeseast/datasette-geojson?include_prereleases&label=changelog)](https://github.com/eyeseast/datasette-geojson/releases)\n[![Tests](https://github.com/eyeseast/datasette-geojson/workflows/Test/badge.svg)](https://github.com/eyeseast/datasette-geojson/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/eyeseast/datasette-geojson/blob/main/LICENSE)\n\nAdd GeoJSON as an output option for datasette queries.\n\n## Installation\n\nInstall this plugin in the same environment as Datasette.\n\n    datasette install datasette-geojson\n\n## Usage\n\nTo render GeoJSON, add a `.geojson` extension to any query URL that includes a `geometry` column. That column should be a valid [GeoJSON geometry](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1).\n\nFor example, you might use [geojson-to-sqlite](https://pypi.org/project/geojson-to-sqlite/) or [shapefile-to-sqlite](https://pypi.org/project/shapefile-to-sqlite/) to load [neighborhood boundaries](https://bostonopendata-boston.opendata.arcgis.com/datasets/3525b0ee6e6b427f9aab5d0a1d0a1a28_0/explore) into a SQLite database.\n\n```sh\nwget -O neighborhoods.geojson https://opendata.arcgis.com/datasets/3525b0ee6e6b427f9aab5d0a1d0a1a28_0.geojson\ngeojson-to-sqlite boston.db neighborhoods neighborhoods.geojson --spatial-index # create a spatial index\ndatasette serve boston.db --load-extension spatialite\n```\n\nIf 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](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1). If you used `geojson-to-sqlite` or `shapefile-to-sqlite`, you should be all set.\n\nRun this query in Datasette and you'll see a link to download GeoJSON:\n\n```sql\nselect\n  rowid,\n  OBJECTID,\n  Name,\n  Acres,\n  Neighborhood_ID,\n  SqMiles,\n  ShapeSTArea,\n  ShapeSTLength,\n  geometry\nfrom\n  neighborhoods\norder by\n  rowid\nlimit\n  101\n```\n\nNote 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`.\n\n![export geojson](img/export-options.png)\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n\n    cd datasette-geojson\n    python3 -mvenv venv\n    source venv/bin/activate\n\nOr if you are using `pipenv`:\n\n    pipenv shell\n\nNow install the dependencies and tests:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Add GeoJSON as an output option",
    "version": "0.4.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "39f7ecc8fd2265efe8e0866b34e0e7ecb7ce08e5559d466f8e9dbe6360f151eb",
                "md5": "3a665a3f61354003716e5d8a28bebf95",
                "sha256": "6de231185b40d1ea07775f0e09d15ac2d9879685b8b683a84442a96371b971f4"
            },
            "downloads": -1,
            "filename": "datasette_geojson-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3a665a3f61354003716e5d8a28bebf95",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 3668,
            "upload_time": "2023-01-06T21:24:39",
            "upload_time_iso_8601": "2023-01-06T21:24:39.591225Z",
            "url": "https://files.pythonhosted.org/packages/39/f7/ecc8fd2265efe8e0866b34e0e7ecb7ce08e5559d466f8e9dbe6360f151eb/datasette_geojson-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f6d3a2cc7e759ca701e403bb2470f9fce14170ead6fc0a309061edac2b9aa0e3",
                "md5": "1001d985f01458079d2f0edf24df44f4",
                "sha256": "ecf7ca75b084b57d0a8007cfb9965cdae53fbb29fe8f0a41feffff941a23da8a"
            },
            "downloads": -1,
            "filename": "datasette-geojson-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1001d985f01458079d2f0edf24df44f4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 3428,
            "upload_time": "2023-01-06T21:24:40",
            "upload_time_iso_8601": "2023-01-06T21:24:40.825892Z",
            "url": "https://files.pythonhosted.org/packages/f6/d3/a2cc7e759ca701e403bb2470f9fce14170ead6fc0a309061edac2b9aa0e3/datasette-geojson-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-06 21:24:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "eyeseast",
    "github_project": "datasette-geojson",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "datasette-geojson"
}
        
Elapsed time: 0.02479s