Changeset 5587
- Timestamp:
- 07/02/07 18:47:40 (1 year ago)
- Files:
-
- django/branches/gis/django/contrib/gis/gdal/Feature.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/Layer.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/gdal/OGRGeometry.py (modified) (4 diffs)
- django/branches/gis/django/contrib/gis/geos/GEOSGeometry.py (modified) (6 diffs)
- django/branches/gis/django/contrib/gis/models.py (modified) (3 diffs)
- django/branches/gis/django/contrib/gis/tests/test_gdal_ds.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/Feature.py
r5478 r5587 94 94 95 95 #### Feature Methods #### 96 def get(self, field_name): 97 "Returns the value of the field, instead of an instance of the Field object." 98 return self.__getitem__(field_name).value 99 96 100 def index(self, field_name): 97 101 "Returns the index of the given field name." django/branches/gis/django/contrib/gis/gdal/Layer.py
r5527 r5587 8 8 from django.contrib.gis.gdal.Envelope import Envelope, OGREnvelope 9 9 from django.contrib.gis.gdal.Feature import Feature 10 from django.contrib.gis.gdal.OGRGeometry import OGRGeomType 10 11 from django.contrib.gis.gdal.OGRError import OGRException, check_err 11 12 from django.contrib.gis.gdal.SpatialReference import SpatialReference … … 84 85 def geom_type(self): 85 86 "Returns the geometry type (OGRGeomType) of the Layer." 86 return lgdal.OGR_FD_GetGeomType(self._ldefn)87 return OGRGeomType(lgdal.OGR_FD_GetGeomType(self._ldefn)) 87 88 88 89 @property 89 90 def srs(self): 90 91 "Returns the Spatial Reference used in this Layer." 91 return SpatialReference(lgdal.OSRClone(lgdal.OGR_L_GetSpatialRef(self._layer)), 'ogr') 92 ptr = lgdal.OGR_L_GetSpatialRef(self._layer) 93 if ptr: 94 srs = SpatialReference(lgdal.OSRClone(ptr), 'ogr') 95 else: 96 return None 92 97 93 98 @property django/branches/gis/django/contrib/gis/gdal/OGRGeometry.py
r5527 r5587 132 132 133 133 #### OGRGeometry Class #### 134 class OGRGeometryIndexError(OGRException, KeyError): 135 """This exception is raised when an invalid index is encountered, and has 136 the 'silent_variable_feature' attribute set to true. This ensures that 137 django's templates proceed to use the next lookup type gracefully when 138 an Exception is raised. Fixes ticket #4740. 139 """ 140 silent_variable_failure = True 141 134 142 class OGRGeometry(object): 135 143 "Generally encapsulates an OGR geometry." … … 413 421 return (x.value, y.value, z.value) 414 422 else: 415 raise IndexError, 'index out of range'423 raise OGRGeometryIndexError, 'index out of range: %s' % str(index) 416 424 417 425 def __iter__(self): … … 446 454 "Gets the ring at the specified index." 447 455 if index < 0 or index >= self.geom_count: 448 raise IndexError, 'index out of range'456 raise OGRGeometryIndexError, 'index out of range: %s' % str(index) 449 457 else: 450 458 return OGRGeometry(lgdal.OGR_G_Clone(lgdal.OGR_G_GetGeometryRef(self._g, c_int(index)))) … … 482 490 "Gets the Geometry at the specified index." 483 491 if index < 0 or index >= self.geom_count: 484 raise IndexError, 'index out of range'492 raise OGRGeometryIndexError, 'index out of range: %s' % str(index) 485 493 else: 486 494 return OGRGeometry(lgdal.OGR_G_Clone(lgdal.OGR_G_GetGeometryRef(self._g, c_int(index)))) django/branches/gis/django/contrib/gis/geos/GEOSGeometry.py
r5510 r5587 86 86 # The GEOSException class 87 87 class GEOSException(Exception): pass 88 class GEOSGeometryIndexError(GEOSException, KeyError): 89 """This exception is raised when an invalid index is encountered, and has 90 the 'silent_variable_feature' attribute set to true. This ensures that 91 django's templates proceed to use the next lookup type gracefully when 92 an Exception is raised. Fixes ticket #4740. 93 """ 94 silent_variable_failure = True 88 95 89 96 # Getting the GEOS C library. The C interface (CDLL) is used for … … 346 353 @property 347 354 def envelope(self): 348 "Return the geometries bounding box."355 "Return the envelope for this geometry (a polygon)." 349 356 return GEOSGeometry(lgeos.GEOSEnvelope(self._g)) 350 357 … … 433 440 sz = self.size 434 441 if (sz < 1) or (index < 0) or (index >= sz): 435 raise IndexError, 'index out of range'442 raise GEOSGeometryIndexError, 'invalid GEOS Geometry index: %s' % str(index) 436 443 437 444 def _checkdim(self, dim): … … 595 602 self._cache_cs() 596 603 if index < 0 or index >= self._cs.size: 597 raise IndexError, 'index out of range'604 raise GEOSGeometryIndexError, 'invalid GEOS Geometry index: %s' % str(index) 598 605 else: 599 606 return self._cs[index] … … 625 632 return the exterior ring. Indices > 0 will return the interior ring.""" 626 633 if index < 0 or index > self.num_interior_rings: 627 raise IndexError, 'index out of range'634 raise GEOSGeometryIndexError, 'invalid GEOS Geometry index: %s' % str(index) 628 635 else: 629 636 if index == 0: … … 688 695 "Checks the given geometry index." 689 696 if index < 0 or index >= self.num_geom: 690 raise IndexError, 'index out of range'697 raise GEOSGeometryIndexError, 'invalid GEOS Geometry index: %s' % str(index) 691 698 692 699 def __iter__(self): django/branches/gis/django/contrib/gis/models.py
r5397 r5587 49 49 50 50 def _cache_osr(self): 51 "Caches a GDAL OSR object for this Spatial Reference."51 "Caches a GDAL OSR SpatialReference object for this SpatialRefSys model." 52 52 if HAS_OSR: 53 53 if not hasattr(self, '_srs'): … … 72 72 @property 73 73 def srs(self): 74 "Returns the SpatialReference equivalent of this model." 74 75 self._cache_osr() 75 76 return self._srs.clone() … … 80 81 (semimajor axis, semiminor axis, and inverse flattening).""" 81 82 if HAS_OSR: 82 # Setting values initially to False83 83 self._cache_osr() 84 major = self._srs.semi_major 85 minor = self._srs.semi_minor 86 invflat = self._srs.inverse_flattening 87 return (major, minor, invflat) 84 return self._srs.ellipsoid 88 85 else: 89 86 m = spheroid_regex.match(self.srtext) django/branches/gis/django/contrib/gis/tests/test_gdal_ds.py
r5527 r5587 102 102 fld = feat[k] # Indexing with string value 103 103 104 # Asserting the string representation (which asserts the type) 105 self.assertEqual('%s (%s)' % (k, v.__name__), str(fld)) 104 # Asserting the string representation, and making sure we get 105 # the proper OGR Field instance. 106 self.assertEqual('%s (%s)' % (k, fld.value), str(fld)) 107 self.assertEqual(True, isinstance(fld, v)) 106 108 107 109 # Testing __iter__ on the Feature
