From 06421a929815f8fb8401d35b714b04cbd1adda53 Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Wed, 29 May 2024 09:28:23 +0200 Subject: [PATCH] OSM: some widths are given with units --- python_scripts/add_trees_to_open_street_map/add_trees.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 e2479c9..46f7348 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: -- GitLab