Changeset 6465
- Timestamp:
- 10/07/07 17:42:26 (1 year ago)
- Files:
-
- django/branches/gis/django/contrib/gis/geos/base.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/geos/geometries.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/geos/pointer.py (modified) (1 diff)
- django/branches/gis/django/contrib/gis/tests/test_geos.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/geos/base.py
r6315 r6465 15 15 from django.contrib.gis.geos.libgeos import lgeos, HAS_NUMPY, ISQLQuote 16 16 from django.contrib.gis.geos.pointer import GEOSPointer, NULL_GEOM 17 18 # Trying to import GDAL libraries, if available. Have to place in 19 # try/except since this package may be used outside GeoDjango. 20 try: 21 from django.contrib.gis.gdal import OGRGeometry, SpatialReference 22 HAS_GDAL=True 23 except: 24 HAS_GDAL=False 17 25 18 26 # Regular expression for recognizing HEXEWKB and WKT. A prophylactic measure … … 436 444 return '<%s>%s</%s>' % (gtype, self.coord_seq.kml, gtype) 437 445 446 #### GDAL-specific output routines #### 447 @property 448 def ogr(self): 449 "Returns the OGR Geometry for this Geometry." 450 if HAS_GDAL: 451 if self.srid: 452 return OGRGeometry(self.wkb, self.srid) 453 else: 454 return OGRGeometry(self.wkb) 455 else: 456 return None 457 458 @property 459 def srs(self): 460 "Returns the OSR SpatialReference for SRID of this Geometry." 461 if HAS_GDAL and self.srid: 462 return SpatialReference(self.srid) 463 else: 464 return None 465 438 466 #### Topology Routines #### 439 467 def _unary_topology(self, func, *args): django/branches/gis/django/contrib/gis/geos/geometries.py
r6024 r6465 54 54 55 55 def __len__(self): 56 "Returns the number of dimensions for this Point (either 2 or 3)." 56 "Returns the number of dimensions for this Point (either 0, 2 or 3)." 57 if self.empty: return 0 57 58 if self.hasz: return 3 58 59 else: return 2 django/branches/gis/django/contrib/gis/geos/pointer.py
r6024 r6465 187 187 188 188 # Determining whether coordinate sequences pointers were passed in. 189 if isinstance(ptr_list[0], (tuple, list)):189 if n_child and isinstance(ptr_list[0], (tuple, list)): 190 190 self._child_cs = True 191 191 else: django/branches/gis/django/contrib/gis/tests/test_geos.py
r6314 r6465 5 5 MultiPoint, MultiLineString, MultiPolygon, GeometryCollection, \ 6 6 fromstr, HAS_NUMPY 7 from django.contrib.gis.geos.base import HAS_GDAL 7 8 from geometries import * 8 9 9 10 if HAS_NUMPY: from numpy import array 11 if HAS_GDAL: from django.contrib.gis.gdal import OGRGeometry, SpatialReference 10 12 11 13 class GEOSTest(unittest.TestCase): … … 723 725 self.assertEqual(8.0, mpoly.length) 724 726 727 def test20_emptyCollections(self): 728 "Testing empty geometries and collections." 729 gc1 = GeometryCollection([]) 730 gc2 = fromstr('GEOMETRYCOLLECTION EMPTY') 731 pnt = fromstr('POINT EMPTY') 732 ls = fromstr('LINESTRING EMPTY') 733 poly = fromstr('POLYGON EMPTY') 734 mls = fromstr('MULTILINESTRING EMPTY') 735 mpoly1 = fromstr('MULTIPOLYGON EMPTY') 736 mpoly2 = MultiPolygon(()) 737 738 for g in [gc1, gc2, pnt, ls, poly, mls, mpoly1, mpoly2]: 739 self.assertEqual(True, g.empty) 740 741 # Testing len() and num_geom. 742 if isinstance(g, Polygon): 743 self.assertEqual(1, len(g)) # Has one empty linear ring 744 self.assertEqual(1, g.num_geom) 745 self.assertEqual(0, len(g[0])) 746 elif isinstance(g, (Point, LineString)): 747 self.assertEqual(1, g.num_geom) 748 self.assertEqual(0, len(g)) 749 else: 750 self.assertEqual(0, g.num_geom) 751 self.assertEqual(0, len(g)) 752 753 # Testing __getitem__ (doesn't work on Point or Polygon) 754 if isinstance(g, Point): 755 self.assertRaises(GEOSGeometryIndexError, g.get_x) 756 elif isinstance(g, Polygon): 757 lr = g.shell 758 self.assertEqual('LINEARRING EMPTY', lr.wkt) 759 self.assertEqual(0, len(lr)) 760 self.assertEqual(True, lr.empty) 761 self.assertRaises(GEOSGeometryIndexError, lr.__getitem__, 0) 762 else: 763 self.assertRaises(GEOSGeometryIndexError, g.__getitem__, 0) 764 765 def test21_test_gdal(self): 766 "Testing `ogr` and `srs` properties." 767 if not HAS_GDAL: return 768 g1 = fromstr('POINT(5 23)') 769 self.assertEqual(True, isinstance(g1.ogr, OGRGeometry)) 770 self.assertEqual(g1.srs, None) 771 772 g2 = fromstr('LINESTRING(0 0, 5 5, 23 23)', srid=4326) 773 self.assertEqual(True, isinstance(g2.ogr, OGRGeometry)) 774 self.assertEqual(True, isinstance(g2.srs, SpatialReference)) 775 self.assertEqual(g2.hex, g2.ogr.hex) 776 self.assertEqual('WGS 84', g2.srs.name) 777 725 778 def suite(): 726 779 s = unittest.TestSuite()
