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
1 change: 1 addition & 0 deletions examples/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
export_file_format="geojson",
maxgap = 800,
import_files = {
'city_boundary': 'boundaries/frederiksberg_dk.geojson',
'street_network': 'streetbike_networks/frederiksberg_dk.gpkg',
},
)
Expand Down
17 changes: 14 additions & 3 deletions fixbikenet/fixbikenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def fixbikenet(
import_files: dict, default {}
The following key:value entries can be set:

- '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.
- 'street_network' : str | None, default None
If not set to None, the street network is loaded from this file. Must be a gpkg file in unprojected crs EPSG:4326 with layers nodes and edges, with the structure that an undirected osmnx street network g has after saved via ox.io.save_graph_geopackage(). For example:
>>> ox.settings.useful_tags_way = ["highway", "cycleway", "cycleway:right", "cycleway:left", "cycleway:both", "cyclestreet"]
Expand All @@ -98,18 +103,25 @@ def fixbikenet(
import_files = _validate_parameters(city_query, radius, mingap, maxgap, export_data, export_file_format, import_files)
_print_header(city_query)


# Get city boundary
if import_files['city_boundary']:
city_boundary_shp = gpd.read_file(settings.import_path+import_files['city_boundary'])
city_boundary = city_boundary_shp.iloc[[0]]
else:
city_boundary = ox.geocoder.geocode_to_gdf(city_query)

if import_files['street_network'] is not None:
progress_bar = initialize_progress_bar("Importing network data", 1, "network")
g = import_network(import_files['street_network'])
else:
### downloading and preprocessing data from OSM. To do: Fix download with custom filters
progress_bar = initialize_progress_bar("Downloading OSM data", 1, "network")
ox.settings.useful_tags_way = ["highway", "cycleway", "cycleway:right", "cycleway:left", "cycleway:both", "cyclestreet"]
# fetch street network data from osmnx
# fetch street network data from osmnx. To do: Make it work with city_boundary import
g = ox.graph_from_place(
city_query, network_type='all', simplify=False
)

progress_bar.update(1)
progress_bar.close()

Expand Down Expand Up @@ -217,7 +229,6 @@ def fixbikenet(
if export_data:
edges_pbi_gdf.drop(["osmid"], axis=1, inplace=True)
edges_gdf.drop(["osmid"], axis=1, inplace=True)
city_boundary = ox.geocoder.geocode_to_gdf(city_query)
city_boundary.to_crs(epsg=4326, inplace=True)
if export_file_format == "geojson":
progress_bar = initialize_progress_bar("Exporting data", 4, "file")
Expand Down
6 changes: 6 additions & 0 deletions fixbikenet/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ def _validate_parameters(
raise TypeError("export_data must be a boolean")
if export_file_format != "geojson" and export_file_format != "gpkg":
raise ValueError("export_file_format must be 'geojson' or 'gpkg'")

if type(import_files) is not dict:
raise TypeError("import_files must be a dictionary")
# Prepare special case import_files. Turn it into a defaultdict where missing keys are None.
import_files = defaultdict(lambda: None, import_files)

# Import files
for filename in ['city_boundary','street_network']:
if type(import_files[filename]) is str and not os.path.isfile(settings.import_path+import_files[filename]):
raise FileNotFoundError(filename+" not found")

return import_files

def _validate_settings():
Expand Down
Loading