|
1 | 1 | from collections import namedtuple, defaultdict |
2 | 2 | from shapely.geometry import box |
3 | 3 | from shapely.geometry import MultiLineString |
| 4 | +from shapely.geometry import MultiPolygon |
4 | 5 | from shapely.geometry.polygon import orient |
5 | 6 | from shapely.wkb import loads as wkb_loads |
6 | 7 | from tilequeue.query.common import layer_properties |
@@ -612,6 +613,25 @@ def _lines_only(shape): |
612 | 613 | return MultiLineString(lines) |
613 | 614 |
|
614 | 615 |
|
| 616 | +def _orient(shape): |
| 617 | + """ |
| 618 | + The Shapely version of the orient function appears to only work on |
| 619 | + Polygons, and fails on MultiPolygons. This is a quick wrapper to allow |
| 620 | + orienting of either. |
| 621 | + """ |
| 622 | + |
| 623 | + assert shape.geom_type in ('Polygon', 'MultiPolygon') |
| 624 | + |
| 625 | + if shape.geom_type == 'Polygon': |
| 626 | + return orient(shape) |
| 627 | + |
| 628 | + else: |
| 629 | + polys = [] |
| 630 | + for geom in shape.geoms: |
| 631 | + polys.append(orient(geom)) |
| 632 | + return MultiPolygon(polys) |
| 633 | + |
| 634 | + |
615 | 635 | class RawrTile(object): |
616 | 636 |
|
617 | 637 | def __init__(self, layers, tables, tile_pyramid, label_placement_layers, |
@@ -757,7 +777,7 @@ def _parse_row(self, zoom, unpadded_bounds, bbox, source, fid, shape, |
757 | 777 | # make sure boundary rings are oriented in the correct |
758 | 778 | # direction; anti-clockwise for outers and clockwise for |
759 | 779 | # inners, which means the interior should be on the left. |
760 | | - boundaries_shape = orient(shape).boundary |
| 780 | + boundaries_shape = _orient(shape).boundary |
761 | 781 |
|
762 | 782 | # make sure it's only lines, post-intersection. a polygon-line |
763 | 783 | # intersection can return points as well as lines. however, |
|
0 commit comments