Skip to content
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
7 changes: 4 additions & 3 deletions fixbikenet/fixbikenet.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions fixbikenet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
37 changes: 25 additions & 12 deletions tests/test_fixbikenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
)
Loading