avoid calling to_polygons on Polygons (for speed)

This commit is contained in:
Jan Petykiewicz 2020-09-29 01:01:10 -07:00
parent de4726955b
commit 08cf7ca4b1

View File

@ -454,6 +454,14 @@ def _shapes_to_elements(shapes: List[Shape],
extension=extension, extension=extension,
properties=properties) properties=properties)
elements.append(path) elements.append(path)
elif isinstance(shape, Polygon):
polygon = shape
xy_open = numpy.round(polygon.vertices + polygon.offset).astype(int)
xy_closed = numpy.vstack((xy_open, xy_open[0, :]))
boundary = klamath.elements.Boundary(layer=(layer, data_type),
xy=xy_closed,
properties=properties)
elements.append(boundary)
else: else:
for polygon in shape.to_polygons(): for polygon in shape.to_polygons():
xy_open = numpy.round(polygon.vertices + polygon.offset).astype(int) xy_open = numpy.round(polygon.vertices + polygon.offset).astype(int)