1
def add_postgis_srs(srs):
3
This function takes a GDAL SpatialReference system and adds its
4
information to the PostGIS `spatial_ref_sys` table -- enabling
5
spatial transformations with PostGIS. This is handy for adding
6
spatial reference systems not included by default with PostGIS.
7
For example, the following adds the so-called "Google Maps Mercator
8
Projection" (available in GDAL 1.5):
10
>>> add_postgis_srs(SpatialReference(900913))
12
Note: By default, the `auth_name` is set to 'EPSG' -- this should
15
from django.contrib.gis.models import SpatialRefSys
16
from django.contrib.gis.gdal import SpatialReference
18
if not isinstance(srs, SpatialReference):
19
srs = SpatialReference(srs)
22
raise Exception('Spatial reference requires an SRID to be compatible with PostGIS.')
24
# Creating the spatial_ref_sys model.
25
sr, created = SpatialRefSys.objects.get_or_create(
26
srid=srs.srid, auth_name='EPSG', auth_srid=srs.srid,
27
srtext=srs.wkt, proj4text=srs.proj4)