diff --git a/python_scripts/add_trees_to_open_street_map/add_trees.py b/python_scripts/add_trees_to_open_street_map/add_trees.py index e2479c924cc3464455c8c54cb9c44979d0409ff5..46f734854aa3dd7c5e977d9ac2baaee23750ec75 100644 --- a/python_scripts/add_trees_to_open_street_map/add_trees.py +++ b/python_scripts/add_trees_to_open_street_map/add_trees.py @@ -109,17 +109,19 @@ def set_plot(bounds: Bounds, to_local_coordinates): return ax -def get_default_widths(ways: list) -> dict[str, float] : +def get_default_widths(ways: list) -> dict[str, float]: """Check existing OSM highways, and extract the most common width for each type""" width_counters = {} for way in ways: - width = float(way.tags.get("width", 0)) + # NOTE: Some widths are written with units, so try to remove [m] first. + # TODO: use regex instead + width = float(way.tags.get("width", '0').replace('m', '')) way_type = way.tags.get("highway") if width: if way_type not in width_counters: width_counters[way_type] = Counter() width_counters[way_type][width] += 1 - return {w:c.most_common(1)[0][0] for w, c in width_counters.items()} + return {w: c.most_common(1)[0][0] for w, c in width_counters.items()} def place_trees(forest: Forest, ways: list, region: str, to_local, tree_distance: float, min_distance_2: float) -> Forest: