@@ -125,7 +125,7 @@ def test03_multipoints(self):
125
125
self .assertEqual (mgeom1 , mgeom3 )
126
126
self .assertEqual (mp .points , mgeom2 .tuple )
127
127
self .assertEqual (mp .n_p , mgeom2 .point_count )
128
-
128
+
129
129
def test04_linestring (self ):
130
130
"Testing LineString objects."
131
131
prev = OGRGeometry ('POINT(0 0)' )
@@ -161,7 +161,7 @@ def test05_multilinestring(self):
161
161
for ls in mlinestr :
162
162
self .assertEqual (2 , ls .geom_type )
163
163
self .assertEqual ('LINESTRING' , ls .geom_name )
164
- self .assertRaises (OGRIndexError , mlinestr .__getitem__ , len (mlinestr ))
164
+ self .assertRaises (OGRIndexError , mlinestr .__getitem__ , len (mlinestr ))
165
165
166
166
def test06_linearring (self ):
167
167
"Testing LinearRing objects."
@@ -179,7 +179,7 @@ def test07a_polygons(self):
179
179
"Testing Polygon objects."
180
180
181
181
# Testing `from_bbox` class method
182
- bbox = (- 180 ,- 90 ,180 ,90 )
182
+ bbox = (- 180 ,- 90 ,180 ,90 )
183
183
p = OGRGeometry .from_bbox ( bbox )
184
184
self .assertEqual (bbox , p .extent )
185
185
@@ -200,13 +200,13 @@ def test07a_polygons(self):
200
200
# Testing equivalence
201
201
self .assertEqual (True , poly == OGRGeometry (p .wkt ))
202
202
self .assertEqual (True , poly != prev )
203
-
203
+
204
204
if p .ext_ring_cs :
205
205
ring = poly [0 ]
206
206
self .assertEqual (p .ext_ring_cs , ring .tuple )
207
207
self .assertEqual (p .ext_ring_cs , poly [0 ].tuple )
208
208
self .assertEqual (len (p .ext_ring_cs ), ring .point_count )
209
-
209
+
210
210
for r in poly :
211
211
self .assertEqual ('LINEARRING' , r .geom_name )
212
212
@@ -258,11 +258,11 @@ def test09a_srs(self):
258
258
sr = SpatialReference ('WGS84' )
259
259
mpoly = OGRGeometry (mp .wkt , sr )
260
260
self .assertEqual (sr .wkt , mpoly .srs .wkt )
261
-
261
+
262
262
# Ensuring that SRS is propagated to clones.
263
263
klone = mpoly .clone ()
264
264
self .assertEqual (sr .wkt , klone .srs .wkt )
265
-
265
+
266
266
# Ensuring all children geometries (polygons and their rings) all
267
267
# return the assigned spatial reference as well.
268
268
for poly in mpoly :
@@ -284,7 +284,7 @@ def test09a_srs(self):
284
284
mpoly .srs = SpatialReference (4269 )
285
285
self .assertEqual (4269 , mpoly .srid )
286
286
self .assertEqual ('NAD83' , mpoly .srs .name )
287
-
287
+
288
288
# Incrementing through the multipolyogn after the spatial reference
289
289
# has been re-assigned.
290
290
for poly in mpoly :
@@ -330,7 +330,7 @@ def test09c_transform_dim(self):
330
330
"Testing coordinate dimension is the same on transformed geometries."
331
331
ls_orig = OGRGeometry ('LINESTRING(-104.609 38.255)' , 4326 )
332
332
ls_trans = OGRGeometry ('LINESTRING(992385.4472045 481455.4944650)' , 2774 )
333
-
333
+
334
334
prec = 3
335
335
ls_orig .transform (ls_trans .srs )
336
336
# Making sure the coordinate dimension is still 2D.
@@ -377,7 +377,7 @@ def test12_symdifference(self):
377
377
self .assertEqual (d1 , a ^ b ) # __xor__ is symmetric difference operator
378
378
a ^= b # testing __ixor__
379
379
self .assertEqual (d1 , a )
380
-
380
+
381
381
def test13_union (self ):
382
382
"Testing union()."
383
383
for i in xrange (len (topology_geoms )):
@@ -436,6 +436,31 @@ def test16_25D(self):
436
436
self .assertEqual ([1.0 , 2.0 , 3.0 ], ls_25d .z )
437
437
self .assertEqual (3 , ls_25d .coord_dim )
438
438
439
+ def test18_ogrgeometry_transform_workaround (self ):
440
+ "Testing coordinate dimensions on geometries after transformation."
441
+ # A bug in GDAL versions prior to 1.7 changes the coordinate
442
+ # dimension of a geometry after it has been transformed.
443
+ # This test ensures that the bug workarounds employed within
444
+ # `OGRGeometry.transform` indeed work.
445
+ wkt_2d = "MULTILINESTRING ((0 0,1 1,2 2))"
446
+ wkt_3d = "MULTILINESTRING ((0 0 0,1 1 1,2 2 2))"
447
+ srid = 4326
448
+
449
+ # For both the 2D and 3D MultiLineString, ensure _both_ the dimension
450
+ # of the collection and the component LineString have the expected
451
+ # coordinate dimension after transform.
452
+ geom = OGRGeometry (wkt_2d , srid )
453
+ geom .transform (srid )
454
+ self .assertEqual (2 , geom .coord_dim )
455
+ self .assertEqual (2 , geom [0 ].coord_dim )
456
+ self .assertEqual (wkt_2d , geom .wkt )
457
+
458
+ geom = OGRGeometry (wkt_3d , srid )
459
+ geom .transform (srid )
460
+ self .assertEqual (3 , geom .coord_dim )
461
+ self .assertEqual (3 , geom [0 ].coord_dim )
462
+ self .assertEqual (wkt_3d , geom .wkt )
463
+
439
464
def suite ():
440
465
s = unittest .TestSuite ()
441
466
s .addTest (unittest .makeSuite (OGRGeomTest ))
0 commit comments