Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mayer
CircularGreenSimCity
Commits
06421a92
Commit
06421a92
authored
May 29, 2024
by
Eric Duminil
Browse files
OSM: some widths are given with units
parent
770caa5b
Changes
1
Show whitespace changes
Inline
Side-by-side
python_scripts/add_trees_to_open_street_map/add_trees.py
View file @
06421a92
...
...
@@ -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
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment