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
f53a83e1
Commit
f53a83e1
authored
May 06, 2024
by
Eric Duminil
Browse files
Negative width to disable street type.
parent
0bcfd36d
Changes
1
Hide whitespace changes
Inline
Side-by-side
python_scripts/add_trees_to_open_street_map/add_trees.py
View file @
f53a83e1
...
...
@@ -41,8 +41,15 @@ TREE_DISTANCE = 10 # [m]
MIN_DISTANCE
=
TREE_DISTANCE
*
0.5
# [m]
# For display purposes only:
GRID
=
100
# [m]
DEFAULT_WIDTHS
=
{
'unclassified'
:
0
}
# If streets from OSM don't have known width, which one should be used?
# Leave empty to get default from similar streets, if available
# Set to -1 if you want to disable trees along the roads
DEFAULT_WIDTHS
=
{
'unclassified'
:
0
,
# 'residential': 8,
# 'motorway': -1,
# 'trunk': -1,
}
SCRIPT_DIR
=
Path
(
__file__
).
resolve
().
parent
...
...
@@ -125,14 +132,18 @@ def place_trees(forest: Forest, ways: list, region: str, to_local, tree_distance
for
way
in
ways
:
way_type
=
way
.
tags
.
get
(
"highway"
)
width
=
float
(
way
.
tags
.
get
(
"width"
,
0
))
default_width
=
default_widths
.
get
(
way_type
,
0
)
if
default_width
<
0
:
# Ignore this type of streets
continue
if
width
:
# Defined in OSM
color
=
'blue'
else
:
width
=
default_widths
.
get
(
way_type
,
0
)
if
width
:
if
default_width
:
# From OSM most common width
color
=
'orange'
width
=
default_width
else
:
# Unknown
color
=
'gray'
...
...
@@ -146,15 +157,13 @@ def place_trees(forest: Forest, ways: list, region: str, to_local, tree_distance
tree_path
=
road_as_polygon
.
exterior
displayed_width
=
width
else
:
# NOTE: Could try to guess width depending on highway type.
displayed_width
=
1
road_xs
,
road_ys
=
zip
(
*
road_xy_s
)
plt
.
plot
(
road_xs
,
road_ys
,
linewidth
=
displayed_width
,
c
=
color
,
alpha
=
0.8
,
zorder
=-
1
)
distances
=
np
.
arange
(
0
,
tree_path
.
length
,
tree_distance
)
potential_trees
=
[
tree_path
.
interpolate
(
distance
)
for
distance
in
distances
]
potential_trees
=
[
tree_path
.
interpolate
(
distance
)
for
distance
in
distances
]
if
tree_path
.
boundary
:
potential_trees
+=
[
tree_path
.
boundary
.
geoms
[
-
1
]]
...
...
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