Skip to main content

Geodata extensions for Django REST Framework

Project description

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.

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()

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

urlpatterns = [

Retrieve all locations as GeoJSON:

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

Simplify and reproject the geometries to another coordinate system:

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

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

curl -g '{"type":"Point","coordinates":[-120,38]}'

Raster data support is provided as well.

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

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

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

urlpatterns = [

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

curl ',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' ',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.


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 = [

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


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.


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

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

django-spillway-0.8.1.tar.gz (29.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page