Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CircularGreenSimCity
CircularGreenSimCity
Commits
84ff6304
Commit
84ff6304
authored
Dec 16, 2024
by
Eric Duminil
Browse files
Show roads on map too.
parent
0bfefd43
Changes
1
Hide whitespace changes
Inline
Side-by-side
python_scripts/add_trees_to_open_street_map/add_trees.py
View file @
84ff6304
...
...
@@ -28,6 +28,7 @@ from tree import Forest
from
import_existing_trees
import
get_existing_forest
from
export_OSM_roads_to_csv
import
write_roads_to_csv
################################################################################
# USER PARAMETERS #
################################################################################
...
...
@@ -138,7 +139,7 @@ def get_basename(bounds: Bounds, with_tree_distance=True) -> str:
return
bounds_description
def
get_osm_roads
(
bounds
:
Bounds
):
def
get_osm_roads
(
bounds
:
Bounds
)
->
list
:
cache_dir
=
SCRIPT_DIR
/
'cache'
cache_dir
.
mkdir
(
exist_ok
=
True
)
...
...
@@ -235,6 +236,7 @@ def place_trees(forest: Forest, ways: list, region: str, to_local, tree_distance
tree_path
=
LineString
(
road_xy_s
)
if
width
:
road_as_polygon
=
tree_path
.
buffer
(
width
/
2
,
cap_style
=
'flat'
)
tree_path
=
road_as_polygon
.
exterior
...
...
@@ -284,12 +286,18 @@ def plot_trees(bounds: Bounds, forest: Forest, tree_distance: float) -> None:
print
(
" DONE!"
)
def
export_map
(
bounds
:
Bounds
,
forest
:
Forest
,
epsg_id
:
int
)
->
None
:
def
export_map
(
bounds
:
Bounds
,
forest
:
Forest
,
ways
:
list
,
epsg_id
:
int
)
->
None
:
print
(
"Exporting Map..."
)
to_wgs84
=
Transformer
.
from_crs
(
f
"EPSG:
{
epsg_id
}
"
,
"EPSG:4326"
,
always_xy
=
True
)
interactive_map
=
folium
.
Map
()
interactive_map
.
fit_bounds
([(
bounds
.
S
,
bounds
.
W
),
(
bounds
.
N
,
bounds
.
E
)])
for
way
in
ways
:
folium
.
PolyLine
([(
node
.
lat
,
node
.
lon
)
for
node
in
way
.
nodes
],
color
=
'blue'
,
weight
=
5
,
opacity
=
0.5
).
add_to
(
interactive_map
)
for
tree
in
forest
:
lon
,
lat
=
to_wgs84
.
transform
(
tree
.
x
,
tree
.
y
)
folium
.
Circle
(
...
...
@@ -313,6 +321,7 @@ def export_map(bounds: Bounds, forest: Forest, epsg_id: int) -> None:
control
=
True
).
add_to
(
interactive_map
)
interactive_map
.
save
(
OUTPUT_DIR
/
f
"
{
get_basename
(
bounds
)
}
_trees.html"
)
print
(
" DONE!"
)
...
...
@@ -379,7 +388,7 @@ def main(wkt_polygon: str, epsg_id: int, tree_distance: float, min_distance: flo
print
(
existing_forest
)
plot_trees
(
bounds
,
forest
,
tree_distance
)
export_map
(
bounds
,
forest
,
epsg_id
)
export_map
(
bounds
,
forest
,
ways
,
epsg_id
)
export_csv
(
bounds
,
forest
,
wkt_polygon
,
tree_distance
,
min_distance
,
epsg_id
)
export_shapefile
(
bounds
,
forest
,
epsg_id
)
...
...
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