From 491505544a0c3850001c5769bf6ebd2d1ae0cb6b Mon Sep 17 00:00:00 2001 From: ajc Date: Wed, 29 Jul 2020 13:06:46 -0400 Subject: [PATCH 1/3] - adds support for ArcGIS API for Python's Polygon and Polyline Geometry objects. - Point Geometry already works :) --- libpysal/weights/_contW_lists.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libpysal/weights/_contW_lists.py b/libpysal/weights/_contW_lists.py index 8fe7cbfe8..b7e043d3f 100644 --- a/libpysal/weights/_contW_lists.py +++ b/libpysal/weights/_contW_lists.py @@ -17,14 +17,21 @@ def _get_boundary_points(shape): Recursively handle polygons vs. multipolygons to extract the boundary point set from each. """ - if shape.type.lower() == 'polygon': + if shape.type.lower() == "polygon" and 'rings' in shape: + return _get_boundary_points(shape.boundary()) # returns a polyline (path) + elif shape.type.lower() == 'polygon': shape = shape.boundary return _get_boundary_points(shape) + elif shape.type.lower() == 'linestring': return list(map(tuple, list(zip(*shape.coords.xy)))) elif shape.type.lower() == 'multilinestring': return list(it.chain(*(list(zip(*shape.coords.xy)) for shape in shape))) + elif shape.type.lower() == 'polyline': + coords = [] + r = [coords.extend([tuple(p) for p in path]) for path in shape['paths']] + return coords elif shape.type.lower() == 'multipolygon': return list(it.chain(*(_get_boundary_points(part.boundary) for part in shape))) From 18e2158d35b9d6c5eaa383d5a8daaa0ac803e1a8 Mon Sep 17 00:00:00 2001 From: ajc Date: Wed, 29 Jul 2020 13:22:15 -0400 Subject: [PATCH 2/3] - fix for failing test by adding check for `dict` type --- libpysal/weights/_contW_lists.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libpysal/weights/_contW_lists.py b/libpysal/weights/_contW_lists.py index b7e043d3f..24741ebc6 100644 --- a/libpysal/weights/_contW_lists.py +++ b/libpysal/weights/_contW_lists.py @@ -17,7 +17,9 @@ def _get_boundary_points(shape): Recursively handle polygons vs. multipolygons to extract the boundary point set from each. """ - if shape.type.lower() == "polygon" and 'rings' in shape: + if shape.type.lower() == "polygon" and \ + isinstance(shape, dict) and \ + 'rings' in shape: return _get_boundary_points(shape.boundary()) # returns a polyline (path) elif shape.type.lower() == 'polygon': shape = shape.boundary From a2a3318694e9aca5d400af10c15ff098da95ac8a Mon Sep 17 00:00:00 2001 From: ajc Date: Thu, 30 Jul 2020 05:47:45 -0400 Subject: [PATCH 3/3] removed `r = ` from the tuple enforcement statement as per the request. --- libpysal/weights/_contW_lists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpysal/weights/_contW_lists.py b/libpysal/weights/_contW_lists.py index 24741ebc6..ea456b258 100644 --- a/libpysal/weights/_contW_lists.py +++ b/libpysal/weights/_contW_lists.py @@ -32,7 +32,7 @@ def _get_boundary_points(shape): for shape in shape))) elif shape.type.lower() == 'polyline': coords = [] - r = [coords.extend([tuple(p) for p in path]) for path in shape['paths']] + [coords.extend([tuple(p) for p in path]) for path in shape['paths']] return coords elif shape.type.lower() == 'multipolygon': return list(it.chain(*(_get_boundary_points(part.boundary)