Package: django-spillway
DjangoandDjango REST Frameworkintegration 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 UsageAdd vector response formats such as GeoJSON, KML/KMZ, and SVG to your API.# models.pyfromdjango.contrib.gis.dbimportmodelsfromspillway.queryimportGeoQuerySetclassLocation(models.Model):slug=models.SlugField()geom=models.GeometryField()objects=GeoQuerySet.as_manager()# urls.pyfromdjango.conf.urlsimporturlfromspillwayimportgenericsfrom.modelsimportLocationurlpatterns=[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'Anyspatial lookupsupported 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.pyfromspillway.modelsimportAbstractRasterStorefromspillway.queryimportGeoQuerySetclassRasterStore(AbstractRasterStore):objects=GeoQuerySet.as_manager()# urls.pyfromdjango.conf.urlsimporturlfromspillwayimportgenericsfrom.modelsimportRasterStoreurlpatterns=[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 ViewsSpillway 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.ViewSetsView 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.fromspillwayimportviewsetsfrom.modelsimportLocation,RasterStoreclassLocationViewSet(viewsets.GeoModelViewSet):queryset=Location.objects.all()classRasterViewSet(viewsets.ReadOnlyRasterModelViewSet):queryset=RasterStore.objects.all()Map TilesTileViewandRasterTileVieware 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}”.fromdjango.conf.urlsimporturlfromspillwayimportviews,urlsfrom.modelsimportLocation,RasterStoreurlpatterns=[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.RenderersSo 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.TestsCreate avirtualenvwithvirtualenvwrapper,
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.mkvirtualenvspillway# Only the following when testing on 2.7, not needed with 3.x.pipinstall--global-option=build_ext--global-option='-USQLITE_OMIT_LOAD_EXTENSION'pysqlitepipinstall-rrequirements.txtPillowmakecheck