Changeset 7113
- Timestamp:
- 02/14/08 10:05:44 (5 months ago)
- Files:
-
- django/branches/gis/django/contrib/gis/gdal/geometries.py (modified) (6 diffs)
- django/branches/gis/django/contrib/gis/gdal/__init__.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/gdal/prototypes/geom.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/gdal/geometries.py
r7107 r7113 217 217 def envelope(self): 218 218 "Returns the envelope for this Geometry." 219 # TODO: Fix Envelope() for Point geometries. 219 220 return Envelope(get_envelope(self._ptr, byref(OGREnvelope()))) 221 222 @property 223 def extent(self): 224 "Returns the envelope as a 4-tuple, instead of as an Envelope object." 225 return self.envelope.tuple 220 226 221 227 #### SpatialReference-related Properties #### … … 447 453 def z(self): 448 454 "Returns the Z coordinate for this Point." 449 return getz(self._ptr, 0) 455 if self.coord_dim == 3: 456 return getz(self._ptr, 0) 450 457 451 458 @property … … 456 463 elif self.coord_dim == 3: 457 464 return (self.x, self.y, self.z) 465 coords = tuple 458 466 459 467 class LineString(OGRGeometry): … … 486 494 def tuple(self): 487 495 "Returns the tuple representation of this LineString." 488 return tuple(self[i] for i in xrange(len(self))) 496 return tuple([self[i] for i in xrange(len(self))]) 497 coords = tuple 498 499 def _listarr(self, func): 500 """ 501 Internal routine that returns a sequence (list) corresponding with 502 the given function. 503 """ 504 return [func(self._ptr, i) for i in xrange(len(self))] 505 506 @property 507 def x(self): 508 "Returns the X coordinates in a list." 509 return self._listarr(getx) 510 511 @property 512 def y(self): 513 "Returns the Y coordinates in a list." 514 return self._listarr(gety) 515 516 @property 517 def z(self): 518 "Returns the Z coordinates in a list." 519 if self.coord_dim == 3: 520 return self._listarr(getz) 489 521 490 522 # LinearRings are used in Polygons. … … 514 546 "Returns the shell of this Polygon." 515 547 return self[0] # First ring is the shell 548 exterior_ring = shell 516 549 517 550 @property 518 551 def tuple(self): 519 552 "Returns a tuple of LinearRing coordinate tuples." 520 return tuple(self[i].tuple for i in xrange(self.geom_count)) 553 return tuple([self[i].tuple for i in xrange(self.geom_count)]) 554 coords = tuple 521 555 522 556 @property … … 576 610 def tuple(self): 577 611 "Returns a tuple representation of this Geometry Collection." 578 return tuple(self[i].tuple for i in xrange(self.geom_count)) 612 return tuple([self[i].tuple for i in xrange(self.geom_count)]) 613 coords = tuple 579 614 580 615 # Multiple Geometry types. django/branches/gis/django/contrib/gis/gdal/__init__.py
r6686 r7113 29 29 from django.contrib.gis.gdal.libgdal import gdal_version, gdal_full_version, gdal_release_date 30 30 from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform 31 from django.contrib.gis.gdal.geometries import OGRGeometry 31 from django.contrib.gis.gdal.geometries import OGRGeometry, GEOJSON 32 32 HAS_GDAL = True 33 33 except: 34 HAS_GDAL =False34 HAS_GDAL, GEOJSON = False, False 35 35 36 36 # The envelope, error, and geomtype modules do not actually require the django/branches/gis/django/contrib/gis/gdal/prototypes/geom.py
r7107 r7113 9 9 10 10 # Some prototypes need to be aware of what version GDAL we have. 11 major, minor 1, minor2 = map(int, gdal_version().split('.'))12 if major <= 1 and minor 1<= 4:11 major, minor = map(int, gdal_version().split('.')[:2]) 12 if major <= 1 and minor <= 4: 13 13 GEOJSON = False 14 14 else: django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py
r7107 r7113 117 117 self.assertRaises(OGRIndexError, linestr.__getitem__, len(linestr)) 118 118 prev = linestr 119 120 # Testing the x, y properties. 121 x = [tmpx for tmpx, tmpy in ls.tup] 122 y = [tmpy for tmpx, tmpy in ls.tup] 123 self.assertEqual(x, linestr.x) 124 self.assertEqual(y, linestr.y) 119 125 120 126 def test05_multilinestring(self): … … 355 361 for tmp in (mp1, mp2, mp3): self.assertEqual(mpoly, tmp) 356 362 363 def test15_extent(self): 364 "Testing `extent` property." 365 # The xmin, ymin, xmax, ymax of the MultiPoint should be returned. 366 mp = OGRGeometry('MULTIPOINT(5 23, 0 0, 10 50)') 367 self.assertEqual((0.0, 0.0, 10.0, 50.0), mp.extent) 368 # Testing on the 'real world' Polygon. 369 poly = OGRGeometry(polygons[3].wkt) 370 ring = poly.shell 371 x, y = ring.x, ring.y 372 xmin, ymin = min(x), min(y) 373 xmax, ymax = max(x), max(y) 374 self.assertEqual((xmin, ymin, xmax, ymax), poly.extent) 375 357 376 def suite(): 358 377 s = unittest.TestSuite()
