<s> """<STR_LIT>""" <EOL> import re <EOL> from django . conf import settings <EOL> from django . contrib . gis import gdal <EOL> class BaseSpatialOperations ( object ) : <EOL> """<STR_LIT>""" <EOL> distance_functions = { } <EOL> geometry_functions = { } <EOL> geometry_operators = { } <EOL> geography_operators = { } <EOL> geography_functions = { } <EOL> gis_terms = { } <EOL> truncate_params = { } <EOL> postgis = False <EOL> spatialite = False <EOL> mysql = False <EOL> oracle = False <EOL> spatial_version = None <EOL> select = None <EOL> geography = False <EOL> area = False <EOL> centroid = False <EOL> difference = False <EOL> distance = False <EOL> distance_sphere = False <EOL> distance_spheroid = False <EOL> envelope = False <EOL> force_rhr = False <EOL> mem_size = False <EOL> bounding_circle = False <EOL> num_geom = False <EOL> num_points = False <EOL> perimeter = False <EOL> perimeter3d = False <EOL> point_on_surface = False <EOL> polygonize = False <EOL> reverse = False <EOL> scale = False <EOL> snap_to_grid = False <EOL> sym_difference = False <EOL> transform = False <EOL> translate = False <EOL> union = False <EOL> collect = False <EOL> extent = False <EOL> extent3d = False <EOL> make_line = False <EOL> unionagg = False <EOL> geohash = False <EOL> geojson = False <EOL> gml = False <EOL> kml = False <EOL> svg = False <EOL> from_text = False <EOL> from_wkb = False <EOL> def convert_extent ( self , box ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def convert_extent3d ( self , box ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def convert_geom ( self , geom_val , geom_field ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def geo_quote_name ( self , name ) : <EOL> if isinstance ( name , unicode ) : <EOL> name = name . encode ( '<STR_LIT:ascii>' ) <EOL> return "<STR_LIT>" % name <EOL> def geo_db_type ( self , f ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def get_distance ( self , f , value , lookup_type ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def get_geom_placeholder ( self , f , value ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def spatial_aggregate_sql ( self , agg ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def spatial_lookup_sql ( self , lvalue , lookup_type , value , field ) : <EOL> raise NotImplmentedError <EOL> def geometry_columns ( self ) : <EOL> raise NotImplementedError <EOL> def spatial_ref_sys ( self ) : <EOL> raise NotImplementedError <EOL> class SpatialRefSysMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> spheroid_regex = re . compile ( r'<STR_LIT>' ) <EOL> units_regex = re . compile ( r'<STR_LIT>' ) <EOL> @ property <EOL> def srs ( self ) : <EOL> """<STR_LIT>""" <EOL> if gdal . HAS_GDAL : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return self . _srs . clone ( ) <EOL> else : <EOL> try : <EOL> self . _srs = gdal . SpatialReference ( self . wkt ) <EOL> return self . srs <EOL> except Exception , msg : <EOL> pass <EOL> try : <EOL> self . _srs = gdal . SpatialReference ( self . proj4text ) <EOL> return self . srs <EOL> except Exception , msg : <EOL> pass <EOL> raise Exception ( '<STR_LIT>' % ( self . wkt , msg ) ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> @ property <EOL> def ellipsoid ( self ) : <EOL> """<STR_LIT>""" <EOL> if gdal . HAS_GDAL : <EOL> return self . srs . ellipsoid <EOL> else : <EOL> m = self . spheroid_regex . match ( self . wkt ) <EOL> if m : return ( float ( m . group ( '<STR_LIT>' ) ) , float ( m . group ( '<STR_LIT>' ) ) ) <EOL> else : return None <EOL> @ property <EOL> def name ( self ) : <EOL> "<STR_LIT>" <EOL> return self . srs . name <EOL> @ property <EOL> def spheroid ( self ) : <EOL> "<STR_LIT>" <EOL> return self . srs [ '<STR_LIT>' ] <EOL> @ property <EOL> def datum ( self ) : <EOL> "<STR_LIT>" <EOL> return self . srs [ '<STR_LIT>' ] <EOL> @ property <EOL> def projected ( self ) : <EOL> "<STR_LIT>" <EOL> if gdal . HAS_GDAL : <EOL> return self . srs . projected <EOL> else : <EOL> return self . wkt . startswith ( '<STR_LIT>' ) <EOL> @ property <EOL> def local ( self ) : <EOL> "<STR_LIT>" <EOL> if gdal . HAS_GDAL : <EOL> return self . srs . local <EOL> else : <EOL> return self . wkt . startswith ( '<STR_LIT>' ) <EOL> @ property <EOL> def geographic ( self ) : <EOL> "<STR_LIT>" <EOL> if gdal . HAS_GDAL : <EOL> return self . srs . geographic <EOL> else : <EOL> return self . wkt . startswith ( '<STR_LIT>' ) <EOL> @ property <EOL> def linear_name ( self ) : <EOL> "<STR_LIT>" <EOL> if gdal . HAS_GDAL : <EOL> return self . srs . linear_name <EOL> elif self . geographic : <EOL> return None <EOL> else : <EOL> m = self . units_regex . match ( self . wkt ) <EOL> return m . group ( '<STR_LIT>' ) <EOL> @ property <EOL> def linear_units ( self ) : <EOL> "<STR_LIT>" <EOL> if gdal . HAS_GDAL : <EOL> return self . srs . linear_units <EOL> elif self . geographic : <EOL> return None <EOL> else : <EOL> m = self . units_regex . match ( self . wkt ) <EOL> return m . group ( '<STR_LIT>' ) <EOL> @ property <EOL> def angular_name ( self ) : <EOL> "<STR_LIT>" <EOL> if gdal . HAS_GDAL : <EOL> return self . srs . angular_name <EOL> elif self . projected : <EOL> return None <EOL> else : <EOL> m = self . units_regex . match ( self . wkt ) <EOL> return m . group ( '<STR_LIT>' ) <EOL> @ property <EOL> def angular_units ( self ) : <EOL> "<STR_LIT>" <EOL> if gdal . HAS_GDAL : <EOL> return self . srs . angular_units <EOL> elif self . projected : <EOL> return None <EOL> else : <EOL> m = self . units_regex . match ( self . wkt ) <EOL> return m . group ( '<STR_LIT>' ) <EOL> @ property <EOL> def units ( self ) : <EOL> "<STR_LIT>" <EOL> if self . projected or self . local : <EOL> return ( self . linear_units , self . linear_name ) <EOL> elif self . geographic : <EOL> return ( self . angular_units , self . angular_name ) <EOL> else : <EOL> return ( None , None ) <EOL> @ classmethod <EOL> def get_units ( cls , wkt ) : <EOL> """<STR_LIT>""" <EOL> if gdal . HAS_GDAL : <EOL> return gdal . SpatialReference ( wkt ) . units <EOL> else : <EOL> m = cls . units_regex . match ( wkt ) <EOL> return m . group ( '<STR_LIT>' ) , m . group ( '<STR_LIT>' ) <EOL> @ classmethod <EOL> def get_spheroid ( cls , wkt , string = True ) : <EOL> """<STR_LIT>""" <EOL> if gdal . HAS_GDAL : <EOL> srs = gdal . SpatialReference ( wkt ) <EOL> sphere_params = srs . ellipsoid <EOL> sphere_name = srs [ '<STR_LIT>' ] <EOL> else : <EOL> m = cls . spheroid_regex . match ( wkt ) <EOL> if m : <EOL> sphere_params = ( float ( m . group ( '<STR_LIT>' ) ) , float ( m . group ( '<STR_LIT>' ) ) ) <EOL> sphere_name = m . group ( '<STR_LIT:name>' ) <EOL> else : <EOL> return None <EOL> if not string : <EOL> return sphere_name , sphere_params <EOL> else : <EOL> if len ( sphere_params ) == <NUM_LIT:3> : <EOL> radius , flattening = sphere_params [ <NUM_LIT:0> ] , sphere_params [ <NUM_LIT:2> ] <EOL> else : <EOL> radius , flattening = sphere_params <EOL> return '<STR_LIT>' % ( sphere_name , radius , flattening ) <EOL> def __unicode__ ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return unicode ( self . srs ) <EOL> except : <EOL> return unicode ( self . wkt ) </s>
