def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None, database=None):
 from django.db import connections, DEFAULT_DB_ALIAS
 if (not database):
  database = DEFAULT_DB_ALIAS
 connection = connections[database]
 if (not hasattr(connection.ops, 'spatial_version')):
  raise Exception('The `add_srs_entry` utility only works with spatial backends.')
 if (connection.ops.oracle or connection.ops.mysql):
  raise Exception('This utility does not support the Oracle or MySQL spatial backends.')
 SpatialRefSys = connection.ops.spatial_ref_sys()
 if (not isinstance(srs, SpatialReference)):
  srs = SpatialReference(srs)
 if (srs.srid is None):
  raise Exception('Spatial reference requires an SRID to be compatible with the spatial backend.')
 kwargs = {'srid': srs.srid, 'auth_name': auth_name, 'auth_srid': (auth_srid or srs.srid), 'proj4text': srs.proj4}
 if connection.ops.postgis:
  kwargs['srtext'] = srs.wkt
 if connection.ops.spatialite:
  kwargs['ref_sys_name'] = (ref_sys_name or srs.name)
 try:
  sr = SpatialRefSys.objects.using(database).get(srid=srs.srid)
 except SpatialRefSys.DoesNotExist:
  sr = SpatialRefSys.objects.using(database).create(**kwargs)

def add_srs_entry ( srs , auth_name = 'EPSG' , auth_srid = None , ref_sys_name = None , database = None ) : from django . db import connections , DEFAULT_DB_ALIAS if ( not database ) : database = DEFAULT_DB_ALIAS connection = connections [ database ] if ( not hasattr ( connection . ops , 'spatial_version' ) ) : raise Exception ( 'The `add_srs_entry` utility only works with spatial backends.' ) if ( connection . ops . oracle or connection . ops . mysql ) : raise Exception ( 'This utility does not support the Oracle or MySQL spatial backends.' ) SpatialRefSys = connection . ops . spatial_ref_sys ( ) if ( not isinstance ( srs , SpatialReference ) ) : srs = SpatialReference ( srs ) if ( srs . srid is None ) : raise Exception ( 'Spatial reference requires an SRID to be compatible with the spatial backend.' ) kwargs = { 'srid' : srs . srid , 'auth_name' : auth_name , 'auth_srid' : ( auth_srid or srs . srid ) , 'proj4text' : srs . proj4 } if connection . ops . postgis : kwargs [ 'srtext' ] = srs . wkt if connection . ops . spatialite : kwargs [ 'ref_sys_name' ] = ( ref_sys_name or srs . name ) try : sr = SpatialRefSys . objects . using ( database ) . get ( srid = srs . srid ) except SpatialRefSys . DoesNotExist : sr = SpatialRefSys . objects . using ( database ) . create ( ** kwargs )
this function takes a gdal spatialreference system and adds its information to the spatial_ref_sys table of the spatial backend .