Skip to content

Commit

Permalink
granular test for nodes.fix_topology() (#91)
Browse files Browse the repository at this point in the history
* running commit

* granular test for nodes.fix_topology -- + #90

* add reset index to remove_false_nodes()
  • Loading branch information
jGaboardi authored Nov 18, 2024
1 parent 82cd59e commit 41f7d97
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sgeop/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def merge_geometries(block: gpd.GeoSeries) -> shapely.LineString:
fixed_index.append(ix)

aggregated.loc[loops.index[fixed_index], aggregated.geometry.name] = fixed_loops
return aggregated
return aggregated.reset_index(drop=True)


def _rotate_loop_coords(
Expand Down
50 changes: 50 additions & 0 deletions sgeop/tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,53 @@ def test_no_rotate_intersects_2(self):
edges[~edges.is_ring],
)
numpy.testing.assert_array_equal(observed, self.known)


def test_fix_topology():
p20 = shapely.Point(2, 0)
p30 = shapely.Point(3, 0)
p40 = shapely.Point(4, 0)
p21 = shapely.Point(2, 1)
p41 = shapely.Point(4, 1)

p251 = shapely.Point(2.5, 1)
p215 = shapely.Point(2, 1.5)
p315 = shapely.Point(3, 1.5)

p27508 = shapely.Point(2.75, 0.8)
p32508 = shapely.Point(3.25, 0.8)
p31 = shapely.Point(3, 1)

line2040 = shapely.LineString((p20, p40))
line41313041 = shapely.LineString((p41, p21, p30, p41))
line251215315251 = shapely.LineString((p215, p315, p251, p215))
line275083250831 = shapely.LineString((p27508, p32508, p31, p27508))

known = geopandas.GeoDataFrame(
{
"geometry": [
shapely.LineString((p251, p215, p315, p251)),
shapely.LineString((p31, p27508, p32508, p31)),
shapely.LineString((p30, p41, p31)),
shapely.LineString((p20, p30)),
shapely.LineString((p30, p40)),
shapely.LineString((p251, p21, p30)),
shapely.LineString((p31, p251)),
],
"_status": ["changed"] * 7,
}
)

observed = sgeop.nodes.fix_topology(
geopandas.GeoDataFrame(
geometry=[
line2040,
line2040,
line41313041,
line251215315251,
line275083250831,
]
)
)

geopandas.testing.assert_geodataframe_equal(observed, known)

0 comments on commit 41f7d97

Please sign in to comment.