<s> from django . contrib . gis . gdal import SpatialReference <EOL> def add_srs_entry ( srs , auth_name = '<STR_LIT>' , auth_srid = None , ref_sys_name = None , <EOL> database = None ) : <EOL> """<STR_LIT>""" <EOL> from django . db import connections , DEFAULT_DB_ALIAS <EOL> if not database : <EOL> database = DEFAULT_DB_ALIAS <EOL> connection = connections [ database ] <EOL> if not hasattr ( connection . ops , '<STR_LIT>' ) : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if connection . ops . oracle or connection . ops . mysql : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> SpatialRefSys = connection . ops . spatial_ref_sys ( ) <EOL> if not isinstance ( srs , SpatialReference ) : <EOL> srs = SpatialReference ( srs ) <EOL> if srs . srid is None : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> kwargs = { '<STR_LIT>' : srs . srid , <EOL> '<STR_LIT>' : auth_name , <EOL> '<STR_LIT>' : auth_srid or srs . srid , <EOL> '<STR_LIT>' : srs . proj4 , <EOL> } <EOL> if connection . ops . postgis : <EOL> kwargs [ '<STR_LIT>' ] = srs . wkt <EOL> if connection . ops . spatialite : <EOL> kwargs [ '<STR_LIT>' ] = ref_sys_name or srs . name <EOL> try : <EOL> sr = SpatialRefSys . objects . using ( database ) . get ( srid = srs . srid ) <EOL> except SpatialRefSys . DoesNotExist : <EOL> sr = SpatialRefSys . objects . using ( database ) . create ( ** kwargs ) <EOL> add_postgis_srs = add_srs_entry </s>
