Backport of r9392 from trunk; prevent GEOS_ERROR message from appearing where it shouldn't.
1.1 --- a/geometry.py Tue Nov 11 11:45:59 2008 -0600
1.2 +++ b/geometry.py Tue Nov 11 11:53:02 2008 -0600
1.3 @@ -23,7 +23,6 @@
1.4 # library. Not a substitute for good web security programming practices.
1.5 hex_regex = re.compile(r'^[0-9A-F]+$', re.I)
1.6 wkt_regex = re.compile(r'^(SRID=(?P<srid>\d+);)?(?P<wkt>(POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)[ACEGIMLONPSRUTY\d,\.\-\(\) ]+)$', re.I)
1.7 -json_regex = re.compile(r'^\{.+\}$')
1.8
1.9 class GEOSGeometry(GEOSBase):
1.10 "A class that, generally, encapsulates a GEOS geometry."
1.11 @@ -56,7 +55,7 @@
1.12 elif hex_regex.match(geo_input):
1.13 # Handling HEXEWKB input.
1.14 g = io.wkb_r.read(geo_input)
1.15 - elif gdal.GEOJSON and json_regex.match(geo_input):
1.16 + elif gdal.GEOJSON and gdal.geometries.json_regex.match(geo_input):
1.17 # Handling GeoJSON input.
1.18 g = io.wkb_r.read(gdal.OGRGeometry(geo_input).wkb)
1.19 else:
2.1 --- a/tests/geometries.py Tue Nov 11 11:45:59 2008 -0600
2.2 +++ b/tests/geometries.py Tue Nov 11 11:53:02 2008 -0600
2.3 @@ -154,4 +154,20 @@
2.4 json_geoms = (TestGeom('POINT(100 0)', json='{ "type": "Point", "coordinates": [ 100.000000, 0.000000 ] }'),
2.5 TestGeom('POLYGON((0 0, -10 0, -10 -10, 0 -10, 0 0))', json='{ "type": "Polygon", "coordinates": [ [ [ 0.000000, 0.000000 ], [ -10.000000, 0.000000 ], [ -10.000000, -10.000000 ], [ 0.000000, -10.000000 ], [ 0.000000, 0.000000 ] ] ] }'),
2.6 TestGeom('MULTIPOLYGON(((102 2, 103 2, 103 3, 102 3, 102 2)), ((100.0 0.0, 101.0 0.0, 101.0 1.0, 100.0 1.0, 100.0 0.0), (100.2 0.2, 100.8 0.2, 100.8 0.8, 100.2 0.8, 100.2 0.2)))', json='{ "type": "MultiPolygon", "coordinates": [ [ [ [ 102.000000, 2.000000 ], [ 103.000000, 2.000000 ], [ 103.000000, 3.000000 ], [ 102.000000, 3.000000 ], [ 102.000000, 2.000000 ] ] ], [ [ [ 100.000000, 0.000000 ], [ 101.000000, 0.000000 ], [ 101.000000, 1.000000 ], [ 100.000000, 1.000000 ], [ 100.000000, 0.000000 ] ], [ [ 100.200000, 0.200000 ], [ 100.800000, 0.200000 ], [ 100.800000, 0.800000 ], [ 100.200000, 0.800000 ], [ 100.200000, 0.200000 ] ] ] ] }'),
2.7 + TestGeom('GEOMETRYCOLLECTION(POINT(100 0),LINESTRING(101.0 0.0, 102.0 1.0))',
2.8 + json='{ "type": "GeometryCollection", "geometries": [ { "type": "Point", "coordinates": [ 100.000000, 0.000000 ] }, { "type": "LineString", "coordinates": [ [ 101.000000, 0.000000 ], [ 102.000000, 1.000000 ] ] } ] }',
2.9 + ),
2.10 + TestGeom('MULTILINESTRING((100.0 0.0, 101.0 1.0),(102.0 2.0, 103.0 3.0))',
2.11 + json="""
2.12 +
2.13 +{ "type": "MultiLineString",
2.14 + "coordinates": [
2.15 + [ [100.0, 0.0], [101.0, 1.0] ],
2.16 + [ [102.0, 2.0], [103.0, 3.0] ]
2.17 + ]
2.18 + }
2.19 +
2.20 +""",
2.21 + not_equal=True,
2.22 + ),
2.23 )
3.1 --- a/tests/test_geos.py Tue Nov 11 11:45:59 2008 -0600
3.2 +++ b/tests/test_geos.py Tue Nov 11 11:53:02 2008 -0600
3.3 @@ -46,6 +46,10 @@
3.4 g = fromstr(err.wkt)
3.5 except (GEOSException, ValueError):
3.6 pass
3.7 +
3.8 + # Bad WKB
3.9 + self.assertRaises(GEOSException, GEOSGeometry, buffer('0'))
3.10 +
3.11 print "\nEND - expecting GEOS_ERROR; safe to ignore.\n"
3.12
3.13 class NotAGeometry(object):
3.14 @@ -55,8 +59,6 @@
3.15 self.assertRaises(TypeError, GEOSGeometry, NotAGeometry())
3.16 # None
3.17 self.assertRaises(TypeError, GEOSGeometry, None)
3.18 - # Bad WKB
3.19 - self.assertRaises(GEOSException, GEOSGeometry, buffer('0'))
3.20
3.21 def test01e_wkb(self):
3.22 "Testing WKB output."
3.23 @@ -99,8 +101,9 @@
3.24 if not gdal or not gdal.GEOJSON: return
3.25 for g in json_geoms:
3.26 geom = GEOSGeometry(g.wkt)
3.27 - self.assertEqual(g.json, geom.json)
3.28 - self.assertEqual(g.json, geom.geojson)
3.29 + if not hasattr(g, 'not_equal'):
3.30 + self.assertEqual(g.json, geom.json)
3.31 + self.assertEqual(g.json, geom.geojson)
3.32 self.assertEqual(GEOSGeometry(g.wkt), GEOSGeometry(geom.json))
3.33
3.34 def test01j_eq(self):