Skip to content

Commit 8eb3255

Browse files
authored
Merge pull request jazzband#92 from udos/issue-79
fix for issue jazzband#79
2 parents 8d259b5 + 379bb38 commit 8eb3255

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ validation
287287
288288
>>> import geojson
289289
290-
>>> validation = geojson.is_valid(geojson.Point((-3.68,40.41,25.14)))
290+
>>> validation = geojson.is_valid(geojson.Point((-3.68,40.41,25.14,10.34)))
291291
>>> validation['valid']
292292
'no'
293293
>>> validation['message']

geojson/validation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def is_valid(obj):
2626
return output('this is not GeoJSON object')
2727

2828
if isinstance(obj, geojson.Point):
29-
if len(obj['coordinates']) != 2:
29+
if len(obj['coordinates']) not in (2, 3):
3030
return output('the "coordinates" member must be a single position')
3131

3232
if isinstance(obj, geojson.MultiPoint):
33-
if checkListOfObjects(obj['coordinates'], lambda x: len(x) == 2):
33+
if checkListOfObjects(obj['coordinates'], lambda x: len(x) in (2, 3)):
3434
return output(
3535
'the "coordinates" member must be an array of positions'
3636
)

tests/test_validation.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestValidationGeometry(unittest.TestCase):
1616

1717
def test_invalid_geometry_with_validate(self):
1818
self.assertRaises(
19-
ValueError, geojson.Point, (10, 20, 30), validate=True)
19+
ValueError, geojson.Point, (10, 20, 30, 40), validate=True)
2020

2121
def test_invalid_geometry_without_validate(self):
2222
try:
@@ -32,6 +32,13 @@ def test_valid_geometry(self):
3232
except ValueError:
3333
self.fail("Point raised ValueError unexpectedly")
3434

35+
def test_valid_geometry_with_elevation(self):
36+
try:
37+
geojson.Point((10, 20, 30), validate=True)
38+
geojson.Point((10, 20, 30), validate=False)
39+
except ValueError:
40+
self.fail("Point raised ValueError unexpectedly")
41+
3542

3643
class TestValidationGeoJSONObject(unittest.TestCase):
3744

@@ -47,25 +54,34 @@ def test_valid_jsonobject(self):
4754
class TestValidationPoint(unittest.TestCase):
4855

4956
def test_invalid_point(self):
50-
point = geojson.Point((10, 20, 30))
57+
point = geojson.Point((10, 20, 30, 40))
5158
self.assertEqual(is_valid(point)['valid'], NO)
5259

5360
def test_valid_point(self):
5461
point = geojson.Point((-3.68, 40.41))
5562
self.assertEqual(is_valid(point)['valid'], YES)
5663

64+
def test_valid_point_with_elevation(self):
65+
point = geojson.Point((-3.68, 40.41, 3.45))
66+
self.assertEqual(is_valid(point)['valid'], YES)
67+
5768

5869
class TestValidationMultipoint(unittest.TestCase):
5970

6071
def test_invalid_multipoint(self):
6172
mpoint = geojson.MultiPoint(
62-
[(3.5887, 10.44558), (2.5555, 3.887), (2.44, 3.44, 2.555)])
73+
[(3.5887,), (3.5887, 10.44558),
74+
(2.5555, 3.887, 4.56), (2.44, 3.44, 2.555, 4.56)])
6375
self.assertEqual(is_valid(mpoint)['valid'], NO)
6476

6577
def test_valid_multipoint(self):
6678
mpoint = geojson.MultiPoint([(10, 20), (30, 40)])
6779
self.assertEqual(is_valid(mpoint)['valid'], YES)
6880

81+
def test_valid_multipoint_with_elevation(self):
82+
mpoint = geojson.MultiPoint([(10, 20, 30), (30, 40, 50)])
83+
self.assertEqual(is_valid(mpoint)['valid'], YES)
84+
6985

7086
class TestValidationLineString(unittest.TestCase):
7187

0 commit comments

Comments
 (0)