Skip to content

Commit

Permalink
ENH: support shapely polygon as enclosures limit (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis authored Sep 12, 2021
1 parent 8280c3d commit 2c34ea4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions momepy/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ def _enclosed_tessellation(
)
tessellation = pd.concat(new)

return tessellation.append(clean_blocks).reset_index(drop=True)
return tessellation.append(clean_blocks.drop(columns="position")).reset_index(
drop=True
)

def _tess(
self,
Expand Down Expand Up @@ -966,8 +968,9 @@ def enclosures(
primary_barriers : GeoDataFrame, GeoSeries
GeoDataFrame or GeoSeries containing primary barriers.
(Multi)LineString geometry is expected.
limit : GeoDataFrame, GeoSeries (default None)
GeoDataFrame or GeoSeries containing external limit of enclosures,
limit : GeoDataFrame, GeoSeries, shapely geometry (default None)
GeoDataFrame, GeoSeries or shapely geometry containing external limit
of enclosures,
i.e. the area which gets partitioned. If None is passed,
the internal area of ``primary_barriers`` will be used.
additional_barriers : GeoDataFrame
Expand All @@ -990,6 +993,8 @@ def enclosures(
"""
if limit is not None:
if isinstance(limit, BaseGeometry):
limit = gpd.GeoSeries([limit])
if limit.geom_type.isin(["Polygon", "MultiPolygon"]).any():
limit_b = limit.boundary
else:
Expand Down
6 changes: 5 additions & 1 deletion tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ def test_enclosures(self):
assert len(basic) == 7
assert isinstance(basic, gpd.GeoDataFrame)

limited = mm.enclosures(self.df_streets, gpd.GeoSeries([self.limit]))
limited = mm.enclosures(self.df_streets, self.limit)
assert len(limited) == 20
assert isinstance(limited, gpd.GeoDataFrame)

limited2 = mm.enclosures(self.df_streets, gpd.GeoSeries([self.limit]))
assert len(limited2) == 20
assert isinstance(limited2, gpd.GeoDataFrame)

b = self.limit.bounds
additional_barrier = gpd.GeoSeries([LineString([(b[0], b[1]), (b[2], b[3])])])

Expand Down

0 comments on commit 2c34ea4

Please sign in to comment.