Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: return itself when no change possible in remove_false_nodes #365

Merged
merged 1 commit into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions momepy/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def remove_false_nodes(gdf):
"""
Clean topology of existing LineString geometry by removal of nodes of degree 2.

Returns the original gdf if there's no node of degree 2.

Parameters
----------
gdf : GeoDataFrame, GeoSeries, array of pygeos geometries
Expand Down Expand Up @@ -276,6 +278,9 @@ def remove_false_nodes(gdf):
)
return df.append(final, ignore_index=True)

# if there's nothing to fix, return the original dataframe
return gdf


class CheckTessellationInput:
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from packaging.version import Version
from shapely import affinity
from shapely.geometry import LineString, MultiPoint, Polygon
from geopandas.testing import assert_geodataframe_equal

import momepy as mm

Expand Down Expand Up @@ -47,6 +48,10 @@ def test_remove_false_nodes(self):
assert isinstance(fixed, gpd.GeoDataFrame)
assert sorted(self.false_network.columns) == sorted(fixed.columns)

# no node of a degree 2
df = self.df_streets.drop([4, 7, 17, 22])
assert_geodataframe_equal(df, mm.remove_false_nodes(df))

def test_CheckTessellationInput(self):
df = self.df_buildings
df.loc[144, "geometry"] = Polygon([(0, 0), (0, 1), (1, 0)])
Expand Down