Skip to content

Commit

Permalink
Raise explicit exception for geometry collections
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarianski committed May 9, 2016
1 parent 8ea6dd2 commit 8c2e4c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mapbox_vector_tile/encoder.py
Expand Up @@ -229,6 +229,11 @@ def _get_feature_type(self, shape):
return self.tile.LineString
elif shape.type == 'Polygon' or shape.type == 'MultiPolygon':
return self.tile.Polygon
elif shape.type == 'GeometryCollection':
raise ValueError('Encoding geometry collections not supported')
else:
raise ValueError('Cannot encode unknown geometry type: %s' %
shape.type)

def _encode_cmd_length(self, cmd, length):
return (length << cmd_bits) | (cmd & ((1 << cmd_bits) - 1))
Expand Down
7 changes: 7 additions & 0 deletions tests/test_encoder.py
Expand Up @@ -422,3 +422,10 @@ def test_validate_generates_rounding_error(self):
shape = shapely.geometry.Polygon(features[0]['geometry'][0])
self.assertTrue(shape.is_valid)
self.assertGreater(shape.area, 0)

def test_geometry_collection_raises(self):
from mapbox_vector_tile import encode
import shapely.wkt
collection = shapely.wkt.loads('GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (4095 3664), LINESTRING (2889 0, 2889 0)), POINT (4095 3664), LINESTRING (2889 0, 2912 158, 3757 1700, 3732 1999, 4095 3277))') # noqa
with self.assertRaises(ValueError):
encode({'name': 'streets', 'features': [{'geometry': collection}]})

0 comments on commit 8c2e4c0

Please sign in to comment.