--- a/web/lib/django/contrib/gis/gdal/tests/test_geom.py Wed May 19 17:43:59 2010 +0200
+++ b/web/lib/django/contrib/gis/gdal/tests/test_geom.py Tue May 25 02:43:45 2010 +0200
@@ -46,12 +46,30 @@
self.assertEqual(0, gt.num)
self.assertEqual('Unknown', gt.name)
+ def test00b_geomtype_25d(self):
+ "Testing OGRGeomType object with 25D types."
+ wkb25bit = OGRGeomType.wkb25bit
+ self.failUnless(OGRGeomType(wkb25bit + 1) == 'Point25D')
+ self.failUnless(OGRGeomType('MultiLineString25D') == (5 + wkb25bit))
+ self.assertEqual('GeometryCollectionField', OGRGeomType('GeometryCollection25D').django)
+
def test01a_wkt(self):
"Testing WKT output."
for g in wkt_out:
geom = OGRGeometry(g.wkt)
self.assertEqual(g.wkt, geom.wkt)
+ def test01a_ewkt(self):
+ "Testing EWKT input/output."
+ for ewkt_val in ('POINT (1 2 3)', 'LINEARRING (0 0,1 1,2 1,0 0)'):
+ # First with ewkt output when no SRID in EWKT
+ self.assertEqual(ewkt_val, OGRGeometry(ewkt_val).ewkt)
+ # No test consumption with an SRID specified.
+ ewkt_val = 'SRID=4326;%s' % ewkt_val
+ geom = OGRGeometry(ewkt_val)
+ self.assertEqual(ewkt_val, geom.ewkt)
+ self.assertEqual(4326, geom.srs.srid)
+
def test01b_gml(self):
"Testing GML output."
for g in wkt_out:
@@ -118,7 +136,7 @@
self.assertEqual(mgeom1, mgeom3)
self.assertEqual(mp.points, mgeom2.tuple)
self.assertEqual(mp.n_p, mgeom2.point_count)
-
+
def test04_linestring(self):
"Testing LineString objects."
prev = OGRGeometry('POINT(0 0)')
@@ -154,7 +172,7 @@
for ls in mlinestr:
self.assertEqual(2, ls.geom_type)
self.assertEqual('LINESTRING', ls.geom_name)
- self.assertRaises(OGRIndexError, mlinestr.__getitem__, len(mlinestr))
+ self.assertRaises(OGRIndexError, mlinestr.__getitem__, len(mlinestr))
def test06_linearring(self):
"Testing LinearRing objects."
@@ -172,7 +190,7 @@
"Testing Polygon objects."
# Testing `from_bbox` class method
- bbox = (-180,-90,180,90)
+ bbox = (-180,-90,180,90)
p = OGRGeometry.from_bbox( bbox )
self.assertEqual(bbox, p.extent)
@@ -193,13 +211,13 @@
# Testing equivalence
self.assertEqual(True, poly == OGRGeometry(p.wkt))
self.assertEqual(True, poly != prev)
-
+
if p.ext_ring_cs:
ring = poly[0]
self.assertEqual(p.ext_ring_cs, ring.tuple)
self.assertEqual(p.ext_ring_cs, poly[0].tuple)
self.assertEqual(len(p.ext_ring_cs), ring.point_count)
-
+
for r in poly:
self.assertEqual('LINEARRING', r.geom_name)
@@ -251,11 +269,11 @@
sr = SpatialReference('WGS84')
mpoly = OGRGeometry(mp.wkt, sr)
self.assertEqual(sr.wkt, mpoly.srs.wkt)
-
+
# Ensuring that SRS is propagated to clones.
klone = mpoly.clone()
self.assertEqual(sr.wkt, klone.srs.wkt)
-
+
# Ensuring all children geometries (polygons and their rings) all
# return the assigned spatial reference as well.
for poly in mpoly:
@@ -277,7 +295,7 @@
mpoly.srs = SpatialReference(4269)
self.assertEqual(4269, mpoly.srid)
self.assertEqual('NAD83', mpoly.srs.name)
-
+
# Incrementing through the multipolyogn after the spatial reference
# has been re-assigned.
for poly in mpoly:
@@ -319,6 +337,18 @@
self.assertAlmostEqual(trans.x, p.x, prec)
self.assertAlmostEqual(trans.y, p.y, prec)
+ def test09c_transform_dim(self):
+ "Testing coordinate dimension is the same on transformed geometries."
+ ls_orig = OGRGeometry('LINESTRING(-104.609 38.255)', 4326)
+ ls_trans = OGRGeometry('LINESTRING(992385.4472045 481455.4944650)', 2774)
+
+ prec = 3
+ ls_orig.transform(ls_trans.srs)
+ # Making sure the coordinate dimension is still 2D.
+ self.assertEqual(2, ls_orig.coord_dim)
+ self.assertAlmostEqual(ls_trans.x[0], ls_orig.x[0], prec)
+ self.assertAlmostEqual(ls_trans.y[0], ls_orig.y[0], prec)
+
def test10_difference(self):
"Testing difference()."
for i in xrange(len(topology_geoms)):
@@ -358,7 +388,7 @@
self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
a ^= b # testing __ixor__
self.assertEqual(d1, a)
-
+
def test13_union(self):
"Testing union()."
for i in xrange(len(topology_geoms)):
@@ -406,6 +436,56 @@
xmax, ymax = max(x), max(y)
self.assertEqual((xmin, ymin, xmax, ymax), poly.extent)
+ def test16_25D(self):
+ "Testing 2.5D geometries."
+ pnt_25d = OGRGeometry('POINT(1 2 3)')
+ self.assertEqual('Point25D', pnt_25d.geom_type.name)
+ self.assertEqual(3.0, pnt_25d.z)
+ self.assertEqual(3, pnt_25d.coord_dim)
+ ls_25d = OGRGeometry('LINESTRING(1 1 1,2 2 2,3 3 3)')
+ self.assertEqual('LineString25D', ls_25d.geom_type.name)
+ self.assertEqual([1.0, 2.0, 3.0], ls_25d.z)
+ self.assertEqual(3, ls_25d.coord_dim)
+
+ def test17_pickle(self):
+ "Testing pickle support."
+ import cPickle
+ g1 = OGRGeometry('LINESTRING(1 1 1,2 2 2,3 3 3)', 'WGS84')
+ g2 = cPickle.loads(cPickle.dumps(g1))
+ self.assertEqual(g1, g2)
+ self.assertEqual(4326, g2.srs.srid)
+ self.assertEqual(g1.srs.wkt, g2.srs.wkt)
+
+ def test18_ogrgeometry_transform_workaround(self):
+ "Testing coordinate dimensions on geometries after transformation."
+ # A bug in GDAL versions prior to 1.7 changes the coordinate
+ # dimension of a geometry after it has been transformed.
+ # This test ensures that the bug workarounds employed within
+ # `OGRGeometry.transform` indeed work.
+ wkt_2d = "MULTILINESTRING ((0 0,1 1,2 2))"
+ wkt_3d = "MULTILINESTRING ((0 0 0,1 1 1,2 2 2))"
+ srid = 4326
+
+ # For both the 2D and 3D MultiLineString, ensure _both_ the dimension
+ # of the collection and the component LineString have the expected
+ # coordinate dimension after transform.
+ geom = OGRGeometry(wkt_2d, srid)
+ geom.transform(srid)
+ self.assertEqual(2, geom.coord_dim)
+ self.assertEqual(2, geom[0].coord_dim)
+ self.assertEqual(wkt_2d, geom.wkt)
+
+ geom = OGRGeometry(wkt_3d, srid)
+ geom.transform(srid)
+ self.assertEqual(3, geom.coord_dim)
+ self.assertEqual(3, geom[0].coord_dim)
+ self.assertEqual(wkt_3d, geom.wkt)
+
+ def test19_equivalence_regression(self):
+ "Testing equivalence methods with non-OGRGeometry instances."
+ self.assertNotEqual(None, OGRGeometry('POINT(0 0)'))
+ self.assertEqual(False, OGRGeometry('LINESTRING(0 0, 1 1)') == 3)
+
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(OGRGeomTest))