~ubuntu-branches/ubuntu/jaunty/python-django/jaunty

« back to all changes in this revision

Viewing changes to django/contrib/gis/utils/srs.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
def add_postgis_srs(srs):
 
2
    """
 
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):
 
9
    
 
10
    >>> add_postgis_srs(SpatialReference(900913))
 
11
 
 
12
    Note: By default, the `auth_name` is set to 'EPSG' -- this should
 
13
    probably be changed.
 
14
    """
 
15
    from django.contrib.gis.models import SpatialRefSys
 
16
    from django.contrib.gis.gdal import SpatialReference
 
17
 
 
18
    if not isinstance(srs, SpatialReference):
 
19
        srs = SpatialReference(srs)
 
20
 
 
21
    if srs.srid is None:
 
22
        raise Exception('Spatial reference requires an SRID to be compatible with PostGIS.')
 
23
   
 
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)