Changeset 7102
- Timestamp:
- 02/08/08 13:10:00 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/srs.py
r6862 r7102 28 28 """ 29 29 import re 30 from types import StringType,UnicodeType, TupleType30 from types import UnicodeType, TupleType 31 31 from ctypes import byref, c_char_p, c_int, c_void_p 32 32 … … 45 45 # Well-Known Geographical Coordinate System Name 46 46 _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') 48 49 49 50 #### Python 'magic' routines #### 50 51 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 """ 53 58 # Intializing pointer and string buffer. 54 59 self._ptr = None 55 60 buf = c_char_p('') 56 61 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: 64 70 # Is this an EPSG well known name? 65 71 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' 67 76 elif srs_input in self._well_known: 68 77 # Is this a short-hand well known name? django/branches/gis/django/contrib/gis/tests/test_gdal_srs.py
r6862 r7102 78 78 if s.proj: 79 79 srs1 = SpatialReference(s.wkt) 80 srs2 = SpatialReference(s.proj , 'proj')80 srs2 = SpatialReference(s.proj) 81 81 self.assertEqual(srs1.proj, srs2.proj) 82 82 83 83 def test05_epsg(self): 84 84 "Test EPSG import." … … 86 86 if s.epsg: 87 87 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) 89 91 #self.assertEqual(srs1.wkt, srs2.wkt) 90 for srs in (srs1, srs2 ):92 for srs in (srs1, srs2, srs3, srs4): 91 93 for attr, expected in s.attr: 92 94 self.assertEqual(expected, srs[attr])
