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
Helping data scientists better understand their datasets and models in text classification. With love from ServiceNow.

Azimuth, an open-source dataset and error analysis tool for text classification, with love from ServiceNow. Overview Azimuth is an open source applica

ServiceNow 145 Dec 23, 2022
A Python interface between Earth Engine and xarray

eexarray A Python interface between Earth Engine and xarray Description eexarray was built to make processing gridded, mesoscale time series data quic

Aaron Zuspan 159 Dec 23, 2022
Python renderer for OpenStreetMap with custom icons intended to display as many map features as possible

Map Machine project consists of Python OpenStreetMap renderer: SVG map generation, SVG and PNG tile generation, Röntgen icon set: unique CC-BY 4.0 map

Sergey Vartanov 0 Dec 18, 2022
A light-weight, versatile XYZ tile server, built with Flask and Rasterio :earth_africa:

Terracotta is a pure Python tile server that runs as a WSGI app on a dedicated webserver or as a serverless app on AWS Lambda. It is built on a modern

DHI GRAS 531 Dec 28, 2022
A short term landscape evolution using a path sampling method to solve water and sediment flow continuity equations and model mass flows over complex topographies.

r.sim.terrain A short-term landscape evolution model that simulates topographic change for both steady state and dynamic flow regimes across a range o

Brendan Harmon 7 Oct 21, 2022
Python script to locate mobile number

Python script to locate mobile number How to use this script run the command to install the required libraries pip install -r requirements.txt run the

Shekhar Gupta 8 Oct 10, 2022
Python module to access the OpenCage geocoding API

OpenCage Geocoding Module for Python A Python module to access the OpenCage Geocoder. Build Status / Code Quality / etc Usage Supports Python 3.6 or n

OpenCage GmbH 57 Nov 01, 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
Calculate & view the trajectory and live position of any earth-orbiting satellite

satellite-visualization A cross-platform application to calculate & view the trajectory and live position of any earth-orbiting satellite in 3D. This

Space Technology and Astronomy Cell - Open Source Society 3 Jan 08, 2022
Bacon - Band-limited Coordinate Networks for Multiscale Scene Representation

BACON: Band-limited Coordinate Networks for Multiscale Scene Representation Project Page | Video | Paper Official PyTorch implementation of BACON. BAC

Stanford Computational Imaging Lab 144 Dec 29, 2022
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
Water Detect Algorithm

WaterDetect Synopsis WaterDetect is an end-to-end algorithm to generate open water cover mask, specially conceived for L2A Sentinel 2 imagery from MAJ

142 Dec 30, 2022
PySAL: Python Spatial Analysis Library Meta-Package

Python Spatial Analysis Library PySAL, the Python spatial analysis library, is an open source cross-platform library for geospatial data science with

Python Spatial Analysis Library 1.1k Dec 18, 2022
Stitch image tiles into larger composite TIFs

untiler Utility to take a directory of {z}/{x}/{y}.(jpg|png) tiles, and stitch into a scenetiff (tif w/ exact merc tile bounds). Future versions will

Mapbox 38 Dec 16, 2022
This app displays interesting statistical weather records and trends which can be used in climate related research including study of global warming.

This app displays interesting statistical weather records and trends which can be used in climate related research including study of global warming.

0 Dec 27, 2021
A Jupyter - Leaflet.js bridge

ipyleaflet A Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook. Usage Selecting a basemap for a leaflet map: Loading a geojso

Jupyter Widgets 1.3k Dec 27, 2022
A simple python script that, given a location and a date, uses the Nasa Earth API to show a photo taken by the Landsat 8 satellite. The script must be executed on the command-line.

What does it do? Given a location and a date, it uses the Nasa Earth API to show a photo taken by the Landsat 8 satellite. The script must be executed

Caio 42 Nov 26, 2022
A Python package for delineating nested surface depressions from digital elevation data.

Welcome to the lidar package lidar is Python package for delineating the nested hierarchy of surface depressions in digital elevation models (DEMs). I

Qiusheng Wu 166 Jan 03, 2023
A set of utility functions for working with GeoJSON annotations in Kaibu

kaibu-utils A set of utility functions for working with Kaibu. Create a new repository Create a new repository and select imjoy-team/imjoy-python-temp

ImJoy Team 0 Dec 12, 2021
Platform for building statistical models of cities and regions

UrbanSim UrbanSim is a platform for building statistical models of cities and regions. These models help forecast long-range patterns in real estate d

Urban Data Science Toolkit 419 Dec 30, 2022