diff options
| author | Justin Bronn <jbronn@gmail.com> | 2008-04-04 12:32:58 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2008-04-04 12:32:58 +0000 |
| commit | 17baee878918a0b9cc7fab49ebdf010e1d557630 (patch) | |
| tree | 68ac3d53d8fa7b44d4574cfaa72de28a10603b8a | |
| parent | 282bccfbc17d22f52b213d21cae07d2c9f0d0b08 (diff) | |
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
| -rw-r--r-- | django/contrib/gis/utils/__init__.py | 1 | ||||
| -rw-r--r-- | django/contrib/gis/utils/srs.py | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/django/contrib/gis/utils/__init__.py b/django/contrib/gis/utils/__init__.py index 2acbc0ab60..1dca849718 100644 --- a/django/contrib/gis/utils/__init__.py +++ b/django/contrib/gis/utils/__init__.py @@ -20,3 +20,4 @@ try: except: HAS_GEOIP = False +from django.contrib.gis.utils.srs import add_postgis_srs diff --git a/django/contrib/gis/utils/srs.py b/django/contrib/gis/utils/srs.py new file mode 100644 index 0000000000..f9783b94ac --- /dev/null +++ b/django/contrib/gis/utils/srs.py @@ -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) |
