# Path: spillway/query.py
# def filter_geometry(queryset, **filters):
# def geo_field(queryset):
# def get_srid(queryset):
# def agg_dims(arr, stat):
#     def _trans_scale(self, colname, deltax, deltay, xfactor, yfactor):
#     def extent(self, srid=None):
#     def filter_geometry(self, **kwargs):
#     def geo_field(self):
#     def pbf(self, bbox, geo_col=None, scale=4096):
#     def tile(self, bbox, z=0, format=None, clip=True):
#     def arrays(self, field_name=None):
#     def aggregate_periods(self, periods):
#     def get(self, *args, **kwargs):
#     def raster_field(self):
#     def summarize(self, geom, stat=None):
#     def warp(self, srid=None, format=None, geom=None):
#     def zipfiles(self, path=None, arcdirname='data'):
# class AsText(geofn.GeoFunc):
# class Simplify(geofn.GeoFunc):
# class SimplifyPreserveTopology(geofn.GeoFunc):
# class TransScale(geofn.GeoFunc):
# class GeoQuerySet(query.QuerySet):
# class RasterQuerySet(GeoQuerySet):
# 
# Path: spillway/collections.py
# def as_feature(data):
# def has_coordinates(geometry):
# def has_features(fcollection):
# def is_featurelike(feature):
# def has_layer(fcollection):
#     def __init__(self, srid=4326, iterable=(), **kwargs):
#     def __init__(self, srid=4326, iterable=(), **kwargs):
#     def __geo_interface__(self):
#     def __str__(self):
#     def _dumps(self):
#     def geojson(self):
#     def is_serialized(self, key):
#     def copy(self):
#     def srs(self):
#     def __init__(self, id=None, geometry=None, properties=None,
#                  crs=None, iterable=(), **kwargs):
#     def geojson(self):
#     def __init__(self, features=None, crs=None, iterable=(), **kwargs):
#     def geojson(self):
#     def has_serialized_geom(self):
#     def __init__(self, iterable=(), **kwargs):
#     def geojson(self):
# class LinkedCRS(dict):
# class NamedCRS(dict):
# class AbstractFeature(dict):
# class Feature(AbstractFeature):
# class FeatureCollection(AbstractFeature):
# class LayerCollection(AbstractFeature):
# 
# Path: spillway/compat.py
# class JSONEncoder(json.JSONEncoder):
# class Mapnik(object):
#     def __getattr__(self, attr):


import os
import collections
import shutil
import tempfile
import zipfile
from django.utils.six.moves import reduce
from django.contrib.gis import forms, gdal
from django.contrib.gis.db.models import functions
from django.contrib.gis.gdal.srs import SpatialReference, SRSException
from django.utils.translation import ugettext_lazy as _
from greenwich.geometry import Envelope
from rest_framework import renderers
from spillway import query, collections as sc
from spillway.compat import json
            if not geom.srs:
                raise gdal.GDALException('Cannot determine SRS')
        except (gdal.GDALException, IndexError):
            raise forms.ValidationError(
                GeometryField.default_error_messages['invalid_geom'],
                code='invalid_geom')
        return geom

    def to_python(self, value):
        value = super(GeometryFileField, self).to_python(value)
        if value is None:
            return value
        try:
            tmpdir = tempfile.mkdtemp()
            return self._from_file(value, tmpdir)
        finally:
            shutil.rmtree(tmpdir)


class OGRGeometryField(forms.GeometryField):
    """A form Field for creating OGR geometries."""

    def to_python(self, value):
        if value in self.empty_values:
            return None
        sref = None
        # Work with a single GeoJSON geometry or a Feature.
        value = json.loads(value) if '"Feature"' in value else value
        if isinstance(value, collections.Mapping):
            feat = sc.as_feature(value)

# Path: spillway/query.py
# def filter_geometry(queryset, **filters):
# def geo_field(queryset):
# def get_srid(queryset):
# def agg_dims(arr, stat):
#     def _trans_scale(self, colname, deltax, deltay, xfactor, yfactor):
#     def extent(self, srid=None):
#     def filter_geometry(self, **kwargs):
#     def geo_field(self):
#     def pbf(self, bbox, geo_col=None, scale=4096):
#     def tile(self, bbox, z=0, format=None, clip=True):
#     def arrays(self, field_name=None):
#     def aggregate_periods(self, periods):
#     def get(self, *args, **kwargs):
#     def raster_field(self):
#     def summarize(self, geom, stat=None):
#     def warp(self, srid=None, format=None, geom=None):
#     def zipfiles(self, path=None, arcdirname='data'):
# class AsText(geofn.GeoFunc):
# class Simplify(geofn.GeoFunc):
# class SimplifyPreserveTopology(geofn.GeoFunc):
# class TransScale(geofn.GeoFunc):
# class GeoQuerySet(query.QuerySet):
# class RasterQuerySet(GeoQuerySet):
# 
# Path: spillway/collections.py
# def as_feature(data):
# def has_coordinates(geometry):
# def has_features(fcollection):
# def is_featurelike(feature):
# def has_layer(fcollection):
#     def __init__(self, srid=4326, iterable=(), **kwargs):
#     def __init__(self, srid=4326, iterable=(), **kwargs):
#     def __geo_interface__(self):
#     def __str__(self):
#     def _dumps(self):
#     def geojson(self):
#     def is_serialized(self, key):
#     def copy(self):
#     def srs(self):
#     def __init__(self, id=None, geometry=None, properties=None,
#                  crs=None, iterable=(), **kwargs):
#     def geojson(self):
#     def __init__(self, features=None, crs=None, iterable=(), **kwargs):
#     def geojson(self):
#     def has_serialized_geom(self):
#     def __init__(self, iterable=(), **kwargs):
#     def geojson(self):
# class LinkedCRS(dict):
# class NamedCRS(dict):
# class AbstractFeature(dict):
# class Feature(AbstractFeature):
# class FeatureCollection(AbstractFeature):
# class LayerCollection(AbstractFeature):
# 
# Path: spillway/compat.py
# class JSONEncoder(json.JSONEncoder):
# class Mapnik(object):
#     def __getattr__(self, attr):


# Path: spillway/forms/fields.py
import os
import collections
import shutil
import tempfile
import zipfile
from django.utils.six.moves import reduce
from django.contrib.gis import forms, gdal
from django.contrib.gis.db.models import functions
from django.contrib.gis.gdal.srs import SpatialReference, SRSException
from django.utils.translation import ugettext_lazy as _
from greenwich.geometry import Envelope
from rest_framework import renderers
from spillway import query, collections as sc
from spillway.compat import json

            if not geom.srs:
                raise gdal.GDALException('Cannot determine SRS')
        except (gdal.GDALException, IndexError):
            raise forms.ValidationError(
                GeometryField.default_error_messages['invalid_geom'],
                code='invalid_geom')
        return geom

    def to_python(self, value):
        value = super(GeometryFileField, self).to_python(value)
        if value is None:
            return value
        try:
            tmpdir = tempfile.mkdtemp()
            return self._from_file(value, tmpdir)
        finally:
            shutil.rmtree(tmpdir)


class OGRGeometryField(forms.GeometryField):
    """A form Field for creating OGR geometries."""

    def to_python(self, value):
        if value in self.empty_values:
            return None
        sref = None
        # Work with a single GeoJSON geometry or a Feature.
        value = json.loads(value) if '"Feature"' in value else value
        if isinstance(value, collections.Mapping):
            feat = sc.as_feature(value)

            value = json.dumps(feat.get('geometry') or value)