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
e2120518
Commit
e2120518
authored
May 06, 2024
by
Eric Duminil
Browse files
More types
parent
48cb32af
Changes
1
Hide whitespace changes
Inline
Side-by-side
python_scripts/add_trees_to_open_street_map/add_trees.py
View file @
e2120518
...
...
@@ -51,7 +51,7 @@ OUTPUT_DIR = SCRIPT_DIR / 'output'
Bounds
=
namedtuple
(
"Bounds"
,
"W S E N"
)
def
load_region
(
wkt_polygon
):
def
load_region
(
wkt_polygon
:
str
):
region
=
wkt
.
loads
(
wkt_polygon
)
bounds
=
Bounds
(
*
region
.
bounds
)
return
region
,
bounds
...
...
@@ -61,7 +61,7 @@ def get_basename(bounds):
return
f
'
{
bounds
.
S
}
__
{
bounds
.
N
}
__
{
bounds
.
W
}
__
{
bounds
.
E
}
_
{
TREE_DISTANCE
}
m'
.
replace
(
'.'
,
'_'
)
def
get_osm_roads
(
bounds
):
def
get_osm_roads
(
bounds
:
Bounds
):
cache_dir
=
SCRIPT_DIR
/
'cache'
cache_dir
.
mkdir
(
exist_ok
=
True
)
...
...
@@ -103,7 +103,7 @@ def set_plot(bounds, to_local_coordinates):
return
ax
def
place_trees
(
forest
,
ways
,
region
,
to_local
,
tree_distance
,
min_distance_2
)
->
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
)
for
way
in
ways
:
...
...
@@ -164,7 +164,7 @@ def plot_trees(bounds: Bounds, forest: Forest, tree_distance: float) -> None:
print
(
" DONE!"
)
def
export_map
(
bounds
,
f
orest
,
epsg_id
)
->
None
:
def
export_map
(
bounds
:
Bounds
,
forest
:
F
orest
,
epsg_id
:
str
)
->
None
:
print
(
"Exporting Map..."
)
to_wgs84
=
Transformer
.
from_crs
(
f
"EPSG:
{
epsg_id
}
"
,
"EPSG:4326"
,
always_xy
=
True
)
interactive_map
=
folium
.
Map
()
...
...
@@ -197,7 +197,7 @@ def export_map(bounds, forest, epsg_id) -> None:
print
(
" DONE!"
)
def
export_csv
(
bounds
,
f
orest
,
wkt_polygon
,
tree_distance
,
min_distance
,
epsg_id
)
->
None
:
def
export_csv
(
bounds
:
Bounds
,
forest
:
F
orest
,
wkt_polygon
:
str
,
tree_distance
:
float
,
min_distance
:
float
,
epsg_id
:
str
)
->
None
:
print
(
"Exporting CSV..."
)
with
open
(
OUTPUT_DIR
/
f
"
{
get_basename
(
bounds
)
}
_trees.csv"
,
"w"
)
as
csv
:
csv
.
write
(
f
"# Fake trees for;
{
wkt_polygon
}
\n
"
)
...
...
@@ -239,7 +239,7 @@ def export_shapefile(bounds: Bounds, forest: Forest, epsg_id: str) -> None:
print
(
" DONE!"
)
def
main
(
wkt_polygon
,
epsg_id
,
tree_distance
,
min_distance
,
import_tree_shp
)
->
None
:
def
main
(
wkt_polygon
:
str
,
epsg_id
:
str
,
tree_distance
:
float
,
min_distance
:
float
,
import_tree_shp
)
->
None
:
region
,
bounds
=
load_region
(
wkt_polygon
)
ways
=
get_osm_roads
(
bounds
)
...
...
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