Changeset 6412
- Timestamp:
- 09/24/07 15:28:23 (1 year ago)
- Files:
-
- django/branches/gis/django/contrib/gis/gdal/error.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/geometries.py (modified) (8 diffs)
- django/branches/gis/django/contrib/gis/gdal/__init__.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/srs.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/error.py
r6059 r6412 8 8 class OGRException(Exception): pass 9 9 class SRSException(Exception): pass 10 class OGRIndexError(OGRException, KeyError): 11 """ 12 This exception is raised when an invalid index is encountered, and has 13 the 'silent_variable_feature' attribute set to true. This ensures that 14 django's templates proceed to use the next lookup type gracefully when 15 an Exception is raised. Fixes ticket #4740. 16 """ 17 silent_variable_failure = True 10 18 11 19 # OGR Error Codes django/branches/gis/django/contrib/gis/gdal/geometries.py
r5754 r6412 6 6 from django.contrib.gis.gdal.libgdal import lgdal 7 7 from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope 8 from django.contrib.gis.gdal.error import check_err, OGRException 8 from django.contrib.gis.gdal.error import check_err, OGRException, OGRIndexError 9 9 from django.contrib.gis.gdal.geomtype import OGRGeomType 10 10 from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform … … 73 73 74 74 #### OGRGeometry Class #### 75 class OGRGeometryIndexError(OGRException, KeyError):76 """This exception is raised when an invalid index is encountered, and has77 the 'silent_variable_feature' attribute set to true. This ensures that78 django's templates proceed to use the next lookup type gracefully when79 an Exception is raised. Fixes ticket #4740.80 """81 silent_variable_failure = True82 83 75 class OGRGeometry(object): 84 76 "Generally encapsulates an OGR geometry." … … 88 80 89 81 self._g = 0 # Initially NULL 82 self._init_srs(srs) 90 83 91 84 if isinstance(input, StringType): 92 # Getting the spatial reference93 self._init_srs(srs)94 95 85 # First, trying the input as WKT 96 86 buf = c_char_p(input) … … 106 96 raise OGRException, 'Could not initialize on WKT "%s"' % input 107 97 elif isinstance(input, OGRGeomType): 108 self._init_srs(srs)109 98 g = lgdal.OGR_G_CreateGeometry(input.num) 110 99 lgdal.OGR_G_AssignSpatialReference(g, self._s._srs) … … 238 227 # Closing the open rings. 239 228 lgdal.OGR_G_CloseRings(self._g) 240 # This "fixes" a GDAL bug. See http://trac.osgeo.org/gdal/ticket/1673241 foo = self.wkt242 229 243 230 def transform(self, coord_trans): … … 382 369 return (x.value, y.value, z.value) 383 370 else: 384 raise OGR GeometryIndexError, 'index out of range: %s' % str(index)371 raise OGRIndexError, 'index out of range: %s' % str(index) 385 372 386 373 def __iter__(self): … … 415 402 "Gets the ring at the specified index." 416 403 if index < 0 or index >= self.geom_count: 417 raise OGR GeometryIndexError, 'index out of range: %s' % str(index)404 raise OGRIndexError, 'index out of range: %s' % str(index) 418 405 else: 419 406 return OGRGeometry(lgdal.OGR_G_Clone(lgdal.OGR_G_GetGeometryRef(self._g, c_int(index)))) … … 451 438 "Gets the Geometry at the specified index." 452 439 if index < 0 or index >= self.geom_count: 453 raise OGR GeometryIndexError, 'index out of range: %s' % str(index)440 raise OGRIndexError, 'index out of range: %s' % str(index) 454 441 else: 455 442 return OGRGeometry(lgdal.OGR_G_Clone(lgdal.OGR_G_GetGeometryRef(self._g, c_int(index)))) django/branches/gis/django/contrib/gis/gdal/__init__.py
r6059 r6412 1 from django.contrib.gis.gdal.driver import Driver 2 from django.contrib.gis.gdal.envelope import Envelope 3 from django.contrib.gis.gdal.datasource import DataSource 4 from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform 5 from django.contrib.gis.gdal.geometries import OGRGeometry 6 from django.contrib.gis.gdal.geomtype import OGRGeomType 7 from django.contrib.gis.gdal.error import check_err, OGRException, SRSException 1 try: 2 from django.contrib.gis.gdal.driver import Driver 3 from django.contrib.gis.gdal.envelope import Envelope 4 from django.contrib.gis.gdal.datasource import DataSource 5 from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform 6 from django.contrib.gis.gdal.geometries import OGRGeometry 7 from django.contrib.gis.gdal.geomtype import OGRGeomType 8 from django.contrib.gis.gdal.error import check_err, OGRException, SRSException 9 HAS_GDAL = True 10 except: 11 HAS_GDAL = False 8 12 django/branches/gis/django/contrib/gis/gdal/srs.py
r6018 r6412 1 # Getting what we need from ctypes2 1 import re 3 2 from types import StringType, UnicodeType, TupleType … … 40 39 NAD83 / Texas South Central 41 40 """ 42 43 44 41 #### ctypes function prototypes #### 45 42 def ellipsis_func(f): 46 """Creates a ctypes function prototype for OSR ellipsis property functions, 47 e.g., OSRGetSemiMajor, OSRGetSemiMinor, OSRGetInvFlattening.""" 43 """ 44 Creates a ctypes function prototype for OSR ellipsis property functions, e.g., 45 OSRGetSemiMajor, OSRGetSemiMinor, OSRGetInvFlattening. 46 """ 48 47 f.restype = c_double 49 48 f.argtypes = [c_void_p, POINTER(c_int)] … … 56 55 57 56 def units_func(f): 58 """Creates a ctypes function prototype for OSR units functions, 59 e.g., OSRGetAngularUnits, OSRGetLinearUnits.""" 57 """ 58 Creates a ctypes function prototype for OSR units functions, e.g., 59 OSRGetAngularUnits, OSRGetLinearUnits. 60 """ 60 61 f.restype = c_double 61 62 f.argtypes = [c_void_p, POINTER(c_char_p)] … … 68 69 #### Spatial Reference class. #### 69 70 class SpatialReference(object): 70 """A wrapper for the OGRSpatialReference object. According to the GDAL website, 71 the SpatialReference object 'provide[s] services to represent coordinate systems 72 (projections and datums) and to transform between them.'""" 71 """ 72 A wrapper for the OGRSpatialReference object. According to the GDAL website, 73 the SpatialReference object 'provide[s] services to represent coordinate 74 systems (projections and datums) and to transform between them.' 75 """ 73 76 74 77 # Well-Known Geographical Coordinate System Name … … 130 133 131 134 def __getitem__(self, target): 132 """Returns the value of the given string attribute node, None if the node doesn't exist. 133 Can also take a tuple as a parameter, (target, child), where child is the child index to get.""" 135 """ 136 Returns the value of the given string attribute node, None if the node 137 doesn't exist. Can also take a tuple as a parameter, (target, child), 138 where child is the child index to get. 139 """ 134 140 if isinstance(target, TupleType): 135 141 return self.attr_value(*target) … … 142 148 143 149 def _string_ptr(self, ptr): 144 "Returns the string at the pointer if it is valid, None if the pointer is NULL." 150 """ 151 Returns the string at the pointer if it is valid, None if the pointer 152 is NULL. 153 """ 145 154 if not ptr: return None 146 155 else: return string_at(ptr) … … 158 167 159 168 def attr_value(self, target, index=0): 160 """The attribute value for the given target node (e.g. 'PROJCS'). The index keyword 161 specifies an index of the child node to return.""" 169 """ 170 The attribute value for the given target node (e.g. 'PROJCS'). The index 171 keyword specifies an index of the child node to return. 172 """ 162 173 ptr = lgdal.OSRGetAttrValue(self._srs, c_char_p(target), c_int(index)) 163 174 return self._string_ptr(ptr) … … 221 232 @property 222 233 def ellipsoid(self): 223 """Returns a tuple of the ellipsoid parameters: 224 (semimajor axis, semiminor axis, and inverse flattening).""" 234 """ 235 Returns a tuple of the ellipsoid parameters: 236 (semimajor axis, semiminor axis, and inverse flattening) 237 """ 225 238 return (self.semi_major, self.semi_minor, self.inverse_flattening) 226 239 227 240 @property 228 241 def semi_major(self): 229 " Gets the Semi Major Axis for this Spatial Reference."242 "Returns the Semi Major Axis for this Spatial Reference." 230 243 err = c_int(0) 231 244 sm = semi_major(self._srs, byref(err)) … … 235 248 @property 236 249 def semi_minor(self): 237 " Gets the Semi Minor Axis for this Spatial Reference."250 "Returns the Semi Minor Axis for this Spatial Reference." 238 251 err = c_int() 239 252 sm = semi_minor(self._srs, byref(err)) … … 243 256 @property 244 257 def inverse_flattening(self): 245 " Gets the Inverse Flattening for this Spatial Reference."258 "Returns the Inverse Flattening for this Spatial Reference." 246 259 err = c_int() 247 260 inv_flat = invflattening(self._srs, byref(err)) … … 252 265 @property 253 266 def geographic(self): 254 "Returns True if this SpatialReference is geographic (root node is GEOGCS)." 267 """ 268 Returns True if this SpatialReference is geographic 269 (root node is GEOGCS). 270 """ 255 271 if lgdal.OSRIsGeographic(self._srs): return True 256 272 else: return False … … 264 280 @property 265 281 def projected(self): 266 "Returns True if this SpatialReference is a projected coordinate system (root node is PROJCS)." 282 """ 283 Returns True if this SpatialReference is a projected coordinate system 284 (root node is PROJCS). 285 """ 267 286 if lgdal.OSRIsProjected(self._srs): return True 268 287 else: return False … … 341 360 def __str__(self): 342 361 return 'Transform from "%s" to "%s"' % (str(self._srs1_name), str(self._srs2_name)) 343
