Skip to content

Commit

Permalink
Merge #102
Browse files Browse the repository at this point in the history
102: Errors method for validating geometry collections. r=frewsxcv a=hrfuller

Closes #101
  • Loading branch information
bors[bot] committed Aug 30, 2017
2 parents 14f85ee + 4c3dd19 commit 9b0d1d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions geojson/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def __init__(self, geometries=None, **extra):
super(GeometryCollection, self).__init__(**extra)
self["geometries"] = geometries or []

def errors(self):
errors = [geom.errors() for geom in self['geometries']]
return [err for err in errors if err]


# Marker classes.

Expand Down
23 changes: 23 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,26 @@ def test_valid_multipolygon(self):
(22, -18.11), (3.14, 23.17)]]
multipoly = geojson.MultiPolygon([poly1, poly2, poly3])
self.assertEqual(multipoly.is_valid, True)


class TestValidationGeometryCollection(unittest.TestCase):

def test_invalid_geometrycollection(self):
point = geojson.Point((10, 20))
bad_poly = geojson.Polygon([[(2.38, 57.322), (23.194, -20.28),
(-120.43, 19.15), (25.44, -17.91)]])

geom_collection = geojson.GeometryCollection(
geometries=[point, bad_poly]
)
self.assertFalse(geom_collection.is_valid)

def test_valid_geometrycollection(self):
point = geojson.Point((10, 20))
poly = geojson.Polygon([[(2.38, 57.322), (23.194, -20.28),
(-120.43, 19.15), (2.38, 57.322)]])

geom_collection = geojson.GeometryCollection(
geometries=[point, poly]
)
self.assertTrue(geom_collection.is_valid)

0 comments on commit 9b0d1d0

Please sign in to comment.