1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

gis: Added the add_postgis_srs utility to ease the creation of spatial_ref_sys table entries.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7399 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2008-04-04 12:32:58 +00:00
parent 282bccfbc1
commit 17baee8789
2 changed files with 24 additions and 0 deletions

View File

@ -20,3 +20,4 @@ try:
except:
HAS_GEOIP = False
from django.contrib.gis.utils.srs import add_postgis_srs

View File

@ -0,0 +1,23 @@
def add_postgis_srs(srs):
"""
This function takes a GDAL SpatialReference system and adds its
information to the PostGIS `spatial_ref_sys` table -- enabling
spatial transformations with PostGIS. This is handy for adding
spatial reference systems not included by default with PostGIS.
For example, the following adds the so-called "Google Maps Mercator
Projection" (available in GDAL 1.5):
>>> add_postgis_srs(SpatialReference(900913))
Note: By default, the `auth_name` is set to 'EPSG' -- this should
probably be changed.
"""
from django.contrib.gis.models import SpatialRefSys
if srs.srid is None:
raise Exception('Spatial reference requires an SRID to be compatible with PostGIS.')
# Creating the spatial_ref_sys model.
sr, created = SpatialRefSys.objects.get_or_create(
srid=srs.srid, auth_name='EPSG', auth_srid=srs.srid,
srtext=srs.wkt, proj4text=srs.proj4)