Changeset 6460
- Timestamp:
- 10/06/07 23:21:31 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/geometries.py
r6440 r6460 40 40 """ 41 41 # types & ctypes 42 from types import IntType, StringType 42 from types import IntType, StringType, UnicodeType 43 43 from ctypes import byref, string_at, c_char_p, c_double, c_int, c_void_p 44 44 … … 182 182 return self.point_count 183 183 184 @property185 def srs(self):184 # The SRS property 185 def get_srs(self): 186 186 "Returns the Spatial Reference for this Geometry." 187 187 srs_ptr = lgdal.OGR_G_GetSpatialReference(self._g) … … 190 190 else: 191 191 return None 192 193 def set_srs(self, srs): 194 "Sets the SpatialReference for this geometry." 195 if isinstance(srs, SpatialReference): 196 srs_ptr = lgdal.OSRClone(srs._srs) 197 elif isinstance(srs, (StringType, UnicodeType, IntType)): 198 sr = SpatialReference(srs) 199 srs_ptr = lgdal.OSRClone(sr._srs) 200 else: 201 raise TypeError('Cannot assign spatial reference with object of type: %s' % type(srs)) 202 lgdal.OGR_G_AssignSpatialReference(self._g, srs_ptr) 203 204 srs = property(get_srs, set_srs) 205 206 # The SRID property 207 def get_srid(self): 208 if self.srs: return self.srs.srid 209 else: return None 210 211 def set_srid(self, srid): 212 if isinstance(srid, IntType): 213 self.srs = srid 214 else: 215 raise TypeError('SRID must be set with an integer.') 216 217 srid = property(get_srid, set_srid) 192 218 193 219 @property django/branches/gis/django/contrib/gis/gdal/srs.py
r6436 r6460 1 import re2 from types import StringType, UnicodeType, TupleType3 from ctypes import \4 c_char_p, c_int, c_double, c_void_p, POINTER, \5 byref, string_at, create_string_buffer6 7 # Getting the GDAL C Library8 from django.contrib.gis.gdal.libgdal import lgdal9 10 # Getting the error checking routine and exceptions11 from django.contrib.gis.gdal.error import check_err, OGRException, SRSException12 13 1 """ 14 2 The Spatial Reference class, represensents OGR Spatial Reference objects. … … 39 27 NAD83 / Texas South Central 40 28 """ 29 import re 30 from types import StringType, UnicodeType, TupleType 31 from ctypes import \ 32 c_char_p, c_int, c_double, c_void_p, POINTER, \ 33 byref, string_at, create_string_buffer 34 35 # Getting the GDAL C Library 36 from django.contrib.gis.gdal.libgdal import lgdal 37 38 # Getting the error checking routine and exceptions 39 from django.contrib.gis.gdal.error import check_err, OGRException, SRSException 40 41 41 #### ctypes function prototypes #### 42 42 def ellipsis_func(f): … … 205 205 if undefined. 206 206 """ 207 return self.srs['AUTHORITY', 1] 207 try: 208 return int(self.attr_value('AUTHORITY', 1)) 209 except ValueError: 210 return None 208 211 209 212 #### Unit Properties #### … … 328 331 w = c_char_p() 329 332 check_err(lgdal.OSRExportToWkt(self._srs, byref(w))) 330 return string_at(w)333 if w: return string_at(w) 331 334 332 335 @property … … 335 338 w = c_char_p() 336 339 check_err(lgdal.OSRExportToPrettyWkt(self._srs, byref(w), c_int(simplify))) 337 return string_at(w)340 if w: return string_at(w) 338 341 339 342 @property … … 342 345 w = c_char_p() 343 346 check_err(lgdal.OSRExportToProj4(self._srs, byref(w))) 344 return string_at(w)347 if w: return string_at(w) 345 348 346 349 @property django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py
r6440 r6460 149 149 self.assertEqual(sr.wkt, ring.srs.wkt) 150 150 151 mpoly = OGRGeometry(mp.wkt, 4326) 152 self.assertEqual(4326, mpoly.srid) 153 mpoly.srs = SpatialReference(4269) 154 self.assertEqual(4269, mpoly.srid) 155 self.assertEqual('NAD83', mpoly.srs.name) 156 for poly in mpoly: 157 self.assertEqual(mpoly.srs.wkt, poly.srs.wkt) 158 poly.srs = 32140 159 for ring in poly: 160 self.assertEqual(32140, ring.srs.srid) 161 self.assertEqual('NAD83 / Texas South Central', ring.srs.name) 162 ring.srs = str(SpatialReference(4326)) # back to WGS84 163 self.assertEqual(4326, ring.srs.srid) 164 165 # Using the `srid` property. 166 ring.srid = 4322 167 self.assertEqual('WGS 72', ring.srs.name) 168 self.assertEqual(4322, ring.srid) 169 170 171 151 172 def suite(): 152 173 s = unittest.TestSuite()
