Geodata extensions for Django REST Framework

Overview

Django-Spillway

https://travis-ci.org/bkg/django-spillway.svg?branch=master https://coveralls.io/repos/bkg/django-spillway/badge.svg?branch=master&service=github

Django and Django REST Framework integration of raster and feature based geodata.

Spillway builds on the immensely marvelous Django REST Framework by providing facilities for the handling of geospatial formats such as GeoTIFF, GeoJSON, and KML/KMZ.

Specific attention has been paid to speedy serialization of geometries from spatial backends which avoids the cost of unnecessary re-serialization in Python.

Basic Usage

Add vector response formats such as GeoJSON, KML/KMZ, and SVG to your API.

# models.py
from django.contrib.gis.db import models
from spillway.query import GeoQuerySet

class Location(models.Model):
    slug = models.SlugField()
    geom = models.GeometryField()
    objects = GeoQuerySet.as_manager()

# urls.py
from django.conf.urls import url
from spillway import generics
from .models import Location

urlpatterns = [
    url(r'^locations/(?P<slug>[\w-]+)/$',
        generics.GeoDetailView.as_view(queryset=Location.objects.all()),
        name='location'),
    url(r'^locations/$',
        generics.GeoListView.as_view(queryset=Location.objects.all()),
        name='location-list'),
]

Retrieve all locations as GeoJSON:

curl -H 'Accept: application/vnd.geo+json' 127.0.0.1:8000/locations/

Simplify and reproject the geometries to another coordinate system:

curl -H 'Accept: application/vnd.geo+json' '127.0.0.1:8000/locations/?srs=3857&simplify=100'

Any spatial lookup supported by the backend is available to search on. For instance, find the location which intersects a particular point:

curl -g '127.0.0.1:8000/locations/?intersects={"type":"Point","coordinates":[-120,38]}'

Raster data support is provided as well.

# models.py
from spillway.models import AbstractRasterStore
from spillway.query import GeoQuerySet

class RasterStore(AbstractRasterStore):
    objects = GeoQuerySet.as_manager()

# urls.py
from django.conf.urls import url
from spillway import generics
from .models import RasterStore

urlpatterns = [
    url(r'^rstores/(?P<slug>[\w-]+)/$',
        generics.RasterDetailView.as_view(queryset=RasterStore.objects.all()),
        name='rasterstore'),
    url(r'^rstores/$',
        generics.RasterListView.as_view(queryset=RasterStore.objects.all()),
        name='rasterstore-list'),
]

Return JSON containing a 2D array of pixel values for a given bounding box:

curl 'http://127.0.0.1:8000/rstores/tasmax/?bbox=-107.74,37.39,-106.95,38.40'

One can crop raster images with a geometry and return a .zip archive of the results:

curl  -H 'Accept: application/zip' 'http://127.0.0.1:8000/rstores/?g=-107.74,37.39,-106.95,38.40'

Generic Views

Spillway extends REST framework generic views with GeoJSON and KML/KMZ renderers for geographic data. This includes pagination of features and all available spatial lookups/filters for the spatial backend in use.

ViewSets

View sets exist for geo and raster enabled models following the familiar usage pattern of Django REST Framework. Currently, a writable raster viewset needs to be added and tested though the read-only variety is available.

from spillway import viewsets
from .models import Location, RasterStore

class LocationViewSet(viewsets.GeoModelViewSet):
    queryset = Location.objects.all()

class RasterViewSet(viewsets.ReadOnlyRasterModelViewSet):
    queryset = RasterStore.objects.all()

Map Tiles

TileView and RasterTileView are available respectively for generating vector or image map tiles. Image tiles require the optional dependency Mapnik, so be sure to have that installed. In this example, GeoJSON or PNG tiles can be requested for the Location geo model, or PNG tiles for RasterStore data sets. The urls presented here use a scheme of "/{z}/{x}/{y}.{format}".

from django.conf.urls import url
from spillway import views, urls
from .models import Location, RasterStore

urlpatterns = [
    url(urls.tilepath('^locations/),
        views.TileView.as_view(queryset=Location.objects.all()),
        name='location-tiles'),
    url(urls.tilepath('^tiles/(?P<slug>\d+)/'),
        views.RasterTileView.as_view(queryset=RasterStore.objects.all()),
        name='map-tiles'),
]

Be sure to cache map tiles through configuration of your web server or Django's cache framework when serving outside of development environments.

Renderers

So far there are renderers for common raster and vector data formats, namely zipped GeoTIFF, JPEG, PNG, and Erdas Imagine, plus GeoJSON, KML/KMZ, and SVG.

Tests

Create a virtualenv with virtualenvwrapper, install dependencies, and run the tests. On Python 2.7, running tests with SpatiaLite requires a build of pysqlite with extension loading enabled. On 3.x, all is well without it.

mkvirtualenv spillway
# Only the following when testing on 2.7, not needed with 3.x.
pip install --global-option=build_ext --global-option='-USQLITE_OMIT_LOAD_EXTENSION' pysqlite
pip install -r requirements.txt Pillow
make check
Owner
Brian Galey
Brian Galey
Python script that can be used to generate latitude/longitude coordinates for GOES-16 full-disk extent.

goes-latlon Python script that can be used to generate latitude/longitude coordinates for GOES-16 full-disk extent. 🌎 🛰️ The grid files can be acces

Douglas Uba 3 Apr 06, 2022
Daily social mapping project in November 2021. Maps made using PyGMT whenever possible.

Daily social mapping project in November 2021. Maps made using PyGMT whenever possible.

Wei Ji 20 Nov 24, 2022
EOReader is a multi-satellite reader allowing you to open optical and SAR data.

Remote-sensing opensource python library reading optical and SAR sensors, loading and stacking bands, clouds, DEM and index.

ICube-SERTIT 152 Dec 30, 2022
A service to auto provision devices in Aruba Central based on the Geo-IP location

Location Based Provisioning Service for Aruba Central A service to auto provision devices in Aruba Central based on the Geo-IP location Geo-IP auto pr

Will Smith 3 Mar 22, 2022
h3-js provides a JavaScript version of H3, a hexagon-based geospatial indexing system.

h3-js The h3-js library provides a pure-JavaScript version of the H3 Core Library, a hexagon-based geographic grid system. It can be used either in No

Uber Open Source 648 Jan 07, 2023
Python tools for geographic data

GeoPandas Python tools for geographic data Introduction GeoPandas is a project to add support for geographic data to pandas objects. It currently impl

GeoPandas 3.5k Jan 03, 2023
Build, deploy and extract satellite public constellations with one command line.

SatExtractor Build, deploy and extract satellite public constellations with one command line. Table of Contents About The Project Getting Started Stru

Frontier Development Lab 70 Nov 18, 2022
Python library to visualize circular plasmid maps

Plasmidviewer Plasmidviewer is a Python library to visualize plasmid maps from GenBank. This library provides only the function to visualize circular

Mori Hideto 9 Dec 04, 2022
Spatial Interpolation Toolbox is a Python-based GUI that is able to interpolate spatial data in vector format.

Spatial Interpolation Toolbox This is the home to Spatial Interpolation Toolbox, a graphical user interface (GUI) for interpolating geographic vector

Michael Ward 2 Nov 01, 2021
Create Siege configuration files from Cloud Optimized GeoTIFF.

cogeo-siege Documentation: Source Code: https://github.com/developmentseed/cogeo-siege Description Create siege configuration files from Cloud Optimiz

Development Seed 3 Dec 01, 2022
Fiona reads and writes geographic data files

Fiona Fiona reads and writes geographic data files and thereby helps Python programmers integrate geographic information systems with other computer s

987 Jan 04, 2023
Deal with Bing Maps Tiles and Pixels / WGS 84 coordinates conversions, and generate grid Shapefiles

PyBingTiles This is a small toolkit in order to deal with Bing Tiles, used i.e. by Facebook for their Data for Good datasets. Install Clone this repos

Shoichi 1 Dec 08, 2021
List of Land Cover datasets in the GEE Catalog

List of Land Cover datasets in the GEE Catalog A list of all the Land Cover (or discrete) datasets in Google Earth Engine. Values, Colors and Descript

David Montero Loaiza 5 Aug 24, 2022
glTF to 3d Tiles Converter. Convert glTF model to Glb, b3dm or 3d tiles format.

gltf-to-3d-tiles glTF to 3d Tiles Converter. Convert glTF model to Glb, b3dm or 3d tiles format. Usage λ python main.py --help Usage: main.py [OPTION

58 Dec 27, 2022
Focal Statistics

Focal-Statistics The Focal statistics tool in many GIS applications like ArcGIS, QGIS and GRASS GIS is a standard method to gain a local overview of r

Ifeanyi Nwasolu 1 Oct 21, 2021
A public data repository for datasets created from TransLink GTFS data.

TransLink Spatial Data What: TransLink is the statutory public transit authority for the Metro Vancouver region. This GitHub repository is a collectio

Henry Tang 3 Jan 14, 2022
Histogram matching plugin for rasterio

rio-hist Histogram matching plugin for rasterio. Provides a CLI and python module for adjusting colors based on histogram matching in a variety of col

Mapbox 75 Sep 23, 2022
🌐 Local tile server for viewing geospatial raster files with ipyleaflet

🌐 Local Tile Server for Geospatial Rasters Need to visualize a rather large raster (gigabytes) you have locally? This is for you. A Flask application

Bane Sullivan 192 Jan 04, 2023
Zora is a python program that searches for GeoLocation info for given CIDR networks , with options to search with API or without API

Zora Zora is a python program that searches for GeoLocation info for given CIDR networks , with options to search with API or without API Installing a

z3r0day 1 Oct 26, 2021
ProjPicker (projection picker) is a Python module that allows the user to select all coordinate reference systems (CRSs)

ProjPicker ProjPicker (projection picker) is a Python module that allows the user to select all coordinate reference systems (CRSs) whose extent compl

Huidae Cho 4 Feb 06, 2022