Git Product home page Git Product logo

datasette-leaflet-geojson's Introduction

datasette-leaflet-geojson

PyPI Changelog Tests License

Datasette plugin that replaces any GeoJSON column values with a Leaflet map

Installation

Install this plugin in the same environment as Datasette.

$ datasette install datasette-leaflet-geojson

Usage

Any columns containing valid GeoJSON strings will have their contents replaced with a Leaflet map when they are displayed in the Datasette interface.

Demo

You can try this plugin out at https://calands.datasettes.com/calands/superunits_with_maps

datasette-leaflet-geojson in action

Configuration

By default this plugin displays maps for the first ten rows, and shows a "Click to load map" prompt for rows past the first ten.

You can change this limit using the default_maps_to_load plugin configuration setting. Add this to your metadata.json:

{
    "plugins": {
        "datasette-leaflet-geojson": {
            "default_maps_to_load": 20
        }
    }
}

Then run Datasette with datasette mydb.db -m metadata.json.

datasette-leaflet-geojson's People

Contributors

asg017 avatar chris48s avatar simonw avatar the-kenny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

datasette-leaflet-geojson's Issues

Option to simplify large GeoJSON before rendering

GeoJSON can get big. It would be neat if this library could simplify giant GeoJSON shapes before attempting to render them.

Leaflet ships with a simplify() helper function: https://leafletjs.com/reference-1.3.0.html#lineutil-simplify

Also available as a separate library (with a really nice interactive demo): http://mourner.github.io/simplify-js/

Turf has a version of this that can be applied to GeoJSON documents directly: http://turfjs.org/docs/#simplify

The tricky part is picking the right tolerance value.

Plugin broken because of a wrong mime type error

Hi,
I'm trying to get to know some of your awesome plugins for datasette.

But when I try to use this plugin (or https://github.com/eyeseast/datasette-geojson-map) and run datasette locally, the maps never show up. I only see the error:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
in the console.
This happens with Firefox as well as with Chromium browsers.

Error when installing

Hi,
I face an error when installing the plugin:

  1. From the console, as a standard user (non root), I execute datasette install datasette-leaflet-geojson
  2. The following error is thrown:
File "/home/stsinc/.local/bin/datasette", line 5, in <module>
    from datasette.cli import cli
  File "/home/stsinc/.local/lib/python3.10/site-packages/datasette/cli.py", line 17, in <module>
    from .app import (
  File "/home/stsinc/.local/lib/python3.10/site-packages/datasette/app.py", line 39, in <module>
    from .views.database import database_download, DatabaseView, TableCreateView
  File "/home/stsinc/.local/lib/python3.10/site-packages/datasette/views/database.py", line 33, in <module>
    from datasette.plugins import pm
  File "/home/stsinc/.local/lib/python3.10/site-packages/datasette/plugins.py", line 27, in <module>
    pm.load_setuptools_entrypoints("datasette")
  File "/usr/local/lib/python3.10/dist-packages/pluggy/_manager.py", line 398, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/stsinc/.local/lib/python3.10/site-packages/datasette_geojson_map/__init__.py", line 5, in <module>
    from datasette_geojson import can_render_geojson
ModuleNotFoundError: No module named 'datasette_geojson'

My hunch is that there is a naming error with a dependency: 'datasette_geojson' instead of 'datasette-geojson'

GeoJSON Doesn't Render?

Does the plugin need enabling somewhere in order to use it?

I'm trying to render a shapefile column in a SpatiaLite table using a query of the form:

SELECT name, AsGeoJSON(wgs84) FROM adminboundaries LIMIT 3

but all I get is the text output?

I tried a local install:

pip install --upgrade datasette
pip install --upgrade datasette-leaflet-geojson

datasette -p 8003 adminboundaries.db  --load-extension=/usr/local/lib/mod_spatialite.dylib

and a Docker install:

docker run datasetteproject/datasette pip install datasette-leaflet-geojson

docker commit $(docker ps -lq) psychemedia/geodatasette

docker run -d -p 8002:8001 -v `pwd`:/mnt psychemedia/geodatasette \
    datasette -p 8001 -h 0.0.0.0 /mnt/adminboundaries.db  --load-extension=/usr/local/lib/mod_spatialite.so

and got the same result in each case (OS/X, Chrome)?

500 Error: TypeError unhashable type: 'dict'

Just got this error on a table page that didn't hold any GeoJSON. I think it's because that table has a properties column containing JSON that isn't a fit for GeoJSON.

Table schema (from datasette-extract):

CREATE TABLE [_datasette_extract] (
   [id] TEXT PRIMARY KEY,
   [database_name] TEXT,
   [table_name] TEXT,
   [created] TEXT,
   [properties] TEXT,
   [completed] TEXT,
   [error] TEXT,
   [num_items] INTEGER
, [instructions] TEXT)

Example record:

{
    "id": "01HRCSG2XC60AK6E3PNRFBJ1RX",
    "database_name": "data",
    "table_name": "new_york_state_rfps",
    "created": "2024-03-07 15:46:18",
    "properties": "{\"award_number\": {\"type\": \"integer\"}, \"group\": {\"type\": \"integer\"}, \"award_title\": {\"type\": \"string\"}, \"type\": {\"type\": \"string\"}, \"keywords\": {\"type\": \"string\"}}",
    "completed": "2024-03-07 15:46:37",
    "error": "table new_york_state_rfps has no column named group...,",
    "num_items": 7,
    "instructions": null
}

SpatiaLite + Leaflet not displaying maps

I think I must be misunderstanding something about how the GeoJSON based maps are meant to interact with SpatiaLite.

In order to get familiar with the spatial possibilities of Datasette, I used ogr2ogr to convert the US Census DP1 state/county/tract level geodatabase into an SQLite database, with the SpatiaLite extensions installed:

ogr2ogr -f SQLite census2010.db census2010.gdb

Then I attempted to serve this SpatiaLite database using Datasette, with the datasette-leaflet-geojson plugin installed:

datasette serve census2010.db --load-extension=spatialite

The geometry column (named shape) shows up as downloadable binaries, rather than maps, but I think this is maybe the expected behavior, as the datasette-leaflet-geojson plugin will only render maps if GeoJSON is found, right? So then I did a query, and used AsGeoJSON(shape) to try and create a GeoJSON column which would trigger map creation by the plugin, but instead all I got was a blank column...

select shape, AsGeoJSON(shape), geoid10, stusps10, name10 from state_2010census_dp1 order by stusps10

I went ahead and published it to GCP using:

datasette publish cloudrun \
    --memory=2Gi \
    --install=datasette-leaflet-geojson \
    --spatialite \
    --name censusdp1-datasette \
    census2010.db

and you can see the results of the query here.

None of this seems to have generated any visible errors in my browser on in the logs.

The behavior I expected was that the AsGeoJSON() call would convert the WKB geometry to a GeoJSON object, and then the datasette-leaflet-geojson plugin would pick it up and render maps of the converted geometries.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.