<s> import json <EOL> from django . contrib . gis import geos <EOL> from django . contrib . gis . db import models <EOL> from spillway . models import AbstractRasterStore <EOL> from spillway . query import GeoQuerySet , RasterQuerySet <EOL> _geom = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ [ <EOL> [ - <NUM_LIT> , - <NUM_LIT> ] , <EOL> [ - <NUM_LIT> , - <NUM_LIT> ] , <EOL> [ - <NUM_LIT> , - <NUM_LIT> ] , <EOL> [ - <NUM_LIT> , - <NUM_LIT> ] <EOL> ] ] <EOL> } <EOL> class AbstractLocation ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:30> ) <EOL> geom = models . GeometryField ( ) <EOL> class Meta : <EOL> abstract = True <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name , self . geom ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> @ classmethod <EOL> def create ( cls , ** data ) : <EOL> geom = data . pop ( '<STR_LIT>' , _geom ) <EOL> if isinstance ( geom , dict ) : <EOL> geom = json . dumps ( geom ) <EOL> defaults = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : geom } <EOL> defaults . update ( ** data ) <EOL> obj = cls ( ** defaults ) <EOL> obj . save ( ) <EOL> return obj <EOL> @ classmethod <EOL> def add_buffer ( cls , coord , radius , ** data ) : <EOL> return cls . create ( geom = geos . Point ( * coord ) . buffer ( radius ) , ** data ) <EOL> class Location ( AbstractLocation ) : <EOL> objects = GeoQuerySet . as_manager ( ) <EOL> class GeoLocation ( AbstractLocation ) : <EOL> objects = models . GeoManager ( ) <EOL> class RasterStore ( AbstractRasterStore ) : <EOL> objects = RasterQuerySet . as_manager ( ) </s>
