From cbc5ca62f79270c0032fb080cc6b4577f8ef0695 Mon Sep 17 00:00:00 2001 From: Michael Szell Date: Wed, 11 Nov 2026 17:01:30 +0100 Subject: [PATCH] Fix critical bug with bnl and simplify --- fixbikenet/fixbikenet.py | 7 ++++--- fixbikenet/utils.py | 16 +++++++++++----- tests/test_fixbikenet.py | 37 +++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/fixbikenet/fixbikenet.py b/fixbikenet/fixbikenet.py index ff5ab5e..29db124 100644 --- a/fixbikenet/fixbikenet.py +++ b/fixbikenet/fixbikenet.py @@ -1,5 +1,6 @@ """Main procedure for running `fixbikenet`.""" +import bikenetlib as bnl from . import constants, settings, osm, _overpass import os import geopandas as gpd @@ -87,9 +88,9 @@ def fixbikenet( - 'city_boundary' : None or str, default None If not set to None, the study area is selected from the - (Multi)Polygon provided in the city_boundary shape or gpkg file, - ideally in unprojected latitude-longitude degrees (EPSG:4326), but - EPSG:3857 also works. + (Multi)Polygon provided in the city_boundary shape, gpkg, or + geojson file, ideally in unprojected latitude-longitude degrees + (EPSG:4326), but EPSG:3857 also works. - 'street_network' : str | None, default None If not set to None, the street network is loaded from this file. For best results, this network should encompass both car and diff --git a/fixbikenet/utils.py b/fixbikenet/utils.py index 4c555d0..83a594a 100644 --- a/fixbikenet/utils.py +++ b/fixbikenet/utils.py @@ -171,16 +171,22 @@ def download_network(city_query, network_type='drive', custom_filter=None, retai # Fetch street network data from osmnx if city_boundary_geometry is None: g = ox.graph_from_place( - city_query, network_type=network_type, custom_filter=custom_filter, retain_all=retain_all + city_query, + network_type=network_type, + custom_filter=custom_filter, + retain_all=retain_all, + simplify=False ) else: g = ox.graph_from_polygon( - city_boundary_geometry, network_type=network_type, custom_filter=custom_filter, retain_all=retain_all + city_boundary_geometry, + network_type=network_type, + custom_filter=custom_filter, + retain_all=retain_all, + simplify=False ) - g_undir = g.to_undirected().copy() # convert to undirected (dropping OSMnx keys!) - - return g_undir + return g def import_network(street_network): diff --git a/tests/test_fixbikenet.py b/tests/test_fixbikenet.py index 286587d..98372d8 100644 --- a/tests/test_fixbikenet.py +++ b/tests/test_fixbikenet.py @@ -7,28 +7,41 @@ fbn.constants._CRS_CALCULATIONS = 'auto' valcols = ['source', 'target'] + +def test_fixbikenet_success_online(): + """Verify that the online version of fixbikenet does not throw an error. + """ + fbn.constants._ROUTING_PENALTY = {0: 1.5, 1: 1} + fbn.settings.radius = 1000 + gaps_ordered = fbn.fixbikenet( + city_query="Frederiksberg municipality", + min_gap_length = 0, + max_gap_length = 100, + num_gaps = 20, + ) + + @pytest.fixture def validation_gdf_frederiksberg(): gdf = gpd.read_file("./tests/test_data/frederiksberg-fixbikenet-gaps.gpkg", layer='Identified gaps') return gdf - -def test_fixbikenet_case_success_offline1(validation_gdf_frederiksberg): +def test_fixbikenet_success_offline(validation_gdf_frederiksberg): """Verify that the offline version of fixbikenet works as intended. """ fbn.constants._ROUTING_PENALTY = {0: 1.5, 1: 1} fbn.settings.radius = 1000 gaps_ordered = fbn.fixbikenet( - city_query="Frederiksberg", - min_gap_length = 0, - max_gap_length = 100, - num_gaps = 20, - import_files={ - 'city_boundary': "./tests/test_data/frederiksberg_boundary.geojson", - 'street_network': "./tests/test_data/frederiksberg_streetbike_network.gpkg", - }, - ) + city_query="Frederiksberg municipality", + min_gap_length = 0, + max_gap_length = 100, + num_gaps = 20, + import_files={ + 'city_boundary': "./tests/test_data/frederiksberg_boundary.geojson", + 'street_network': "./tests/test_data/frederiksberg_streetbike_network.gpkg", + }, + ) assert_frame_equal( validation_gdf_frederiksberg[valcols], gaps_ordered[valcols] - ) + ) \ No newline at end of file