From 6c21504fe03235a5fb25a9aa65b83eb9c69485f1 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Sun, 26 Jun 2022 19:22:47 +0200 Subject: [PATCH] BUG: return itself when no change possible (#365) --- momepy/preprocessing.py | 5 +++++ tests/test_preprocess.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/momepy/preprocessing.py b/momepy/preprocessing.py index 33661cf9..23758c75 100644 --- a/momepy/preprocessing.py +++ b/momepy/preprocessing.py @@ -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 @@ -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: """ diff --git a/tests/test_preprocess.py b/tests/test_preprocess.py index 2c6d63f3..dc4ede4f 100644 --- a/tests/test_preprocess.py +++ b/tests/test_preprocess.py @@ -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 @@ -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)])