Skip to content

Commit

Permalink
BUG: return itself when no change possible (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis committed Sep 20, 2022
1 parent b473069 commit 6c21504
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit 6c21504

Please sign in to comment.