Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mayer
CircularGreenSimCity
Commits
c88c9734
Commit
c88c9734
authored
1 year ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Trying to recognize standard widths
parent
e95ceba1
eric_enrich_trees
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_scripts/add_trees_to_open_street_map/add_trees.py
+32
-8
python_scripts/add_trees_to_open_street_map/add_trees.py
with
32 additions
and
8 deletions
+32
-8
python_scripts/add_trees_to_open_street_map/add_trees.py
+
32
-
8
View file @
c88c9734
...
@@ -8,7 +8,7 @@ Trees are exported in a CSV table, a PNG diagram and an HTML interactive map.
...
@@ -8,7 +8,7 @@ Trees are exported in a CSV table, a PNG diagram and an HTML interactive map.
"""
"""
import
pickle
import
pickle
from
pathlib
import
Path
from
pathlib
import
Path
from
collections
import
namedtuple
from
collections
import
namedtuple
,
Counter
import
folium
import
folium
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
...
@@ -42,8 +42,7 @@ MIN_DISTANCE = TREE_DISTANCE * 0.5 # [m]
...
@@ -42,8 +42,7 @@ MIN_DISTANCE = TREE_DISTANCE * 0.5 # [m]
# For display purposes only:
# For display purposes only:
GRID
=
100
# [m]
GRID
=
100
# [m]
IGNORE_ROADS
=
set
([
'primary'
,
'unclassified'
,
'secondary'
,
DEFAULT_WIDTHS
=
{
'unclassified'
:
0
}
'secondary_link'
,
'trunk'
,
'trunk_link'
,
'primary_link'
])
SCRIPT_DIR
=
Path
(
__file__
).
resolve
().
parent
SCRIPT_DIR
=
Path
(
__file__
).
resolve
().
parent
...
@@ -88,7 +87,7 @@ def get_osm_roads(bounds: Bounds):
...
@@ -88,7 +87,7 @@ def get_osm_roads(bounds: Bounds):
return
ways
return
ways
def
set_plot
(
bounds
,
to_local_coordinates
):
def
set_plot
(
bounds
:
Bounds
,
to_local_coordinates
):
x_min
,
y_min
=
to_local_coordinates
.
transform
(
bounds
.
W
,
bounds
.
S
)
x_min
,
y_min
=
to_local_coordinates
.
transform
(
bounds
.
W
,
bounds
.
S
)
x_max
,
y_max
=
to_local_coordinates
.
transform
(
bounds
.
E
,
bounds
.
N
)
x_max
,
y_max
=
to_local_coordinates
.
transform
(
bounds
.
E
,
bounds
.
N
)
ax
=
plt
.
axes
()
ax
=
plt
.
axes
()
...
@@ -103,16 +102,41 @@ def set_plot(bounds, to_local_coordinates):
...
@@ -103,16 +102,41 @@ def set_plot(bounds, to_local_coordinates):
return
ax
return
ax
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
))
way_type
=
way
.
tags
.
get
(
"highway"
)
print
(
way_type
,
width
)
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
()}
def
place_trees
(
forest
:
Forest
,
ways
:
list
,
region
:
str
,
to_local
,
tree_distance
:
float
,
min_distance_2
:
float
)
->
Forest
:
def
place_trees
(
forest
:
Forest
,
ways
:
list
,
region
:
str
,
to_local
,
tree_distance
:
float
,
min_distance_2
:
float
)
->
Forest
:
local_region
=
transform
(
to_local
.
transform
,
region
)
local_region
=
transform
(
to_local
.
transform
,
region
)
default_widths
=
{
**
get_default_widths
(
ways
),
**
DEFAULT_WIDTHS
}
print
(
f
"Default widths:
{
default_widths
}
"
)
for
way
in
ways
:
for
way
in
ways
:
way_type
=
way
.
tags
.
get
(
"highway"
)
width
=
float
(
way
.
tags
.
get
(
"width"
,
0
))
width
=
float
(
way
.
tags
.
get
(
"width"
,
0
))
highway
=
way
.
tags
.
get
(
"highway"
)
if
width
:
if
highway
in
IGNORE_ROADS
:
# Defined in OSM
color
=
'
orang
e'
color
=
'
blu
e'
else
:
else
:
color
=
'gray'
width
=
default_widths
.
get
(
way_type
,
0
)
if
width
:
# From OSM most common width
color
=
'orange'
else
:
# Unknown
color
=
'gray'
road_xy_s
=
[
to_local
.
transform
(
node
.
lon
,
node
.
lat
)
for
node
in
way
.
nodes
]
road_xy_s
=
[
to_local
.
transform
(
node
.
lon
,
node
.
lat
)
for
node
in
way
.
nodes
]
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets