Django

Code

Changeset 7102

Show
Ignore:
Timestamp:
02/08/08 13:10:00 (5 months ago)
Author:
jbronn
Message:

gis: gdal: SpatialReference objects may now be constructed with PROJ.4 strings without specifying a keyword.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/gdal/srs.py

    r6862 r7102  
    2828""" 
    2929import re 
    30 from types import StringType, UnicodeType, TupleType 
     30from types import UnicodeType, TupleType 
    3131from ctypes import byref, c_char_p, c_int, c_void_p 
    3232 
     
    4545    # Well-Known Geographical Coordinate System Name 
    4646    _well_known = {'WGS84':4326, 'WGS72':4322, 'NAD27':4267, 'NAD83':4269} 
    47     _epsg_regex = re.compile('^EPSG:(?P<epsg>\d+)$', re.I) 
     47    _epsg_regex = re.compile('^(EPSG:)?(?P<epsg>\d+)$', re.I) 
     48    _proj_regex = re.compile(r'^\+proj') 
    4849 
    4950    #### Python 'magic' routines #### 
    5051    def __init__(self, srs_input='', srs_type='wkt'): 
    51         "Creates a spatial reference object from the given OGC Well Known Text (WKT)." 
    52  
     52        """ 
     53        Creates a GDAL OSR Spatial Reference object from the given input. 
     54        The input may be string of OGC Well Known Text (WKT), an integer  
     55        EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand  
     56        string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83'). 
     57        """ 
    5358        # Intializing pointer and string buffer. 
    5459        self._ptr = None 
    5560        buf = c_char_p('') 
    5661 
    57         # Encoding to ASCII if unicode passed in. 
    58         if isinstance(srs_input, UnicodeType): 
    59             srs_input = srs_input.encode('ascii') 
    60  
    61         if isinstance(srs_input, StringType): 
    62             m = self._epsg_regex.match(srs_input) 
    63             if m: 
     62        if isinstance(srs_input, basestring): 
     63            # Encoding to ASCII if unicode passed in. 
     64            if isinstance(srs_input, UnicodeType): 
     65                srs_input = srs_input.encode('ascii') 
     66 
     67            epsg_m = self._epsg_regex.match(srs_input) 
     68            proj_m = self._proj_regex.match(srs_input) 
     69            if epsg_m: 
    6470                # Is this an EPSG well known name?     
    6571                srs_type = 'epsg' 
    66                 srs_input = int(m.group('epsg')) 
     72                srs_input = int(epsg_m.group('epsg')) 
     73            elif proj_m: 
     74                # Is the string a PROJ.4 string? 
     75                srs_type = 'proj' 
    6776            elif srs_input in self._well_known: 
    6877                # Is this a short-hand well known name?   
  • django/branches/gis/django/contrib/gis/tests/test_gdal_srs.py

    r6862 r7102  
    7878            if s.proj: 
    7979                srs1 = SpatialReference(s.wkt) 
    80                 srs2 = SpatialReference(s.proj, 'proj'
     80                srs2 = SpatialReference(s.proj
    8181                self.assertEqual(srs1.proj, srs2.proj) 
    82  
     82         
    8383    def test05_epsg(self): 
    8484        "Test EPSG import." 
     
    8686            if s.epsg: 
    8787                srs1 = SpatialReference(s.wkt) 
    88                 srs2 = SpatialReference(s.epsg, 'epsg') 
     88                srs2 = SpatialReference(s.epsg) 
     89                srs3 = SpatialReference(str(s.epsg)) 
     90                srs4 = SpatialReference('EPSG:%d' % s.epsg) 
    8991                #self.assertEqual(srs1.wkt, srs2.wkt) 
    90                 for srs in (srs1, srs2): 
     92                for srs in (srs1, srs2, srs3, srs4): 
    9193                    for attr, expected in s.attr: 
    9294                        self.assertEqual(expected, srs[attr])