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
a5b79d6b
Commit
a5b79d6b
authored
Mar 26, 2024
by
Eric Duminil
Browse files
Preparing for Shapefile
parent
19615aa6
Changes
3
Hide whitespace changes
Inline
Side-by-side
python_scripts/add_trees_to_open_street_map/add_trees.py
View file @
a5b79d6b
...
@@ -31,6 +31,7 @@ from import_existing_trees import get_existing_forest
...
@@ -31,6 +31,7 @@ from import_existing_trees import get_existing_forest
WKT
=
"POLYGON((9.947021 49.803063, 9.947011 49.800917, 9.955025 49.800810, 9.955110 49.803019, 9.947021 49.803063))"
WKT
=
"POLYGON((9.947021 49.803063, 9.947011 49.800917, 9.955025 49.800810, 9.955110 49.803019, 9.947021 49.803063))"
# Replace with None if no existing tree should be imported
# Replace with None if no existing tree should be imported
EXISTING_TREES
=
'existing_trees/Trees_ideal_2_20240227.shp'
EXISTING_TREES
=
'existing_trees/Trees_ideal_2_20240227.shp'
# EXISTING_TREES = 'existing_trees/baumkataster/Baum.shp'
# Fellbach
# Fellbach
# WKT = "POLYGON((9.271353 48.811327, 9.271911 48.809010, 9.272147 48.807187, 9.275838 48.807173, 9.275602 48.806749, 9.276138 48.806325, 9.277683 48.806424, 9.277319 48.812514, 9.275581 48.811991, 9.271353 48.811327))"
# WKT = "POLYGON((9.271353 48.811327, 9.271911 48.809010, 9.272147 48.807187, 9.275838 48.807173, 9.275602 48.806749, 9.276138 48.806325, 9.277683 48.806424, 9.277319 48.812514, 9.275581 48.811991, 9.271353 48.811327))"
EPSG_ID
=
25832
EPSG_ID
=
25832
...
@@ -139,7 +140,7 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2) -
...
@@ -139,7 +140,7 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2) -
color
=
'#DFFF00'
,
color
=
'#DFFF00'
,
type
=
'Fake Tree'
,
type
=
'Fake Tree'
,
description
=
'Tilia tomentosa'
,
description
=
'Tilia tomentosa'
,
radius
=
3
diameter
=
6
)
)
return
forest
return
forest
...
@@ -147,7 +148,7 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2) -
...
@@ -147,7 +148,7 @@ def place_trees(forest, ways, region, to_local, tree_distance, min_distance_2) -
def
plot_trees
(
bounds
,
forest
,
tree_distance
)
->
None
:
def
plot_trees
(
bounds
,
forest
,
tree_distance
)
->
None
:
print
(
"Exporting diagram..."
)
print
(
"Exporting diagram..."
)
tree_xs
,
tree_ys
,
colors
=
forest
.
xs_ys_c
s
tree_xs
,
tree_ys
,
colors
=
forest
.
xs_ys_c
6
plt
.
scatter
(
tree_xs
,
tree_ys
,
s
=
2
,
c
=
colors
)
plt
.
scatter
(
tree_xs
,
tree_ys
,
s
=
2
,
c
=
colors
)
plt
.
grid
(
True
)
plt
.
grid
(
True
)
...
@@ -155,6 +156,7 @@ def plot_trees(bounds, forest, tree_distance) -> None:
...
@@ -155,6 +156,7 @@ def plot_trees(bounds, forest, tree_distance) -> None:
plt
.
gcf
().
set_size_inches
(
15
,
10
)
plt
.
gcf
().
set_size_inches
(
15
,
10
)
plt
.
savefig
(
plt
.
savefig
(
SCRIPT_DIR
/
f
"
{
get_basename
(
bounds
)
}
.png"
,
bbox_inches
=
'tight'
,
dpi
=
300
)
SCRIPT_DIR
/
f
"
{
get_basename
(
bounds
)
}
.png"
,
bbox_inches
=
'tight'
,
dpi
=
300
)
print
(
" DONE!"
)
def
export_map
(
bounds
,
forest
,
epsg_id
)
->
None
:
def
export_map
(
bounds
,
forest
,
epsg_id
)
->
None
:
...
@@ -167,7 +169,7 @@ def export_map(bounds, forest, epsg_id) -> None:
...
@@ -167,7 +169,7 @@ def export_map(bounds, forest, epsg_id) -> None:
lon
,
lat
=
to_wgs84
.
transform
(
tree
.
x
,
tree
.
y
)
lon
,
lat
=
to_wgs84
.
transform
(
tree
.
x
,
tree
.
y
)
folium
.
Circle
(
folium
.
Circle
(
location
=
[
lat
,
lon
],
location
=
[
lat
,
lon
],
radius
=
tree
.
radius
or
2
,
# [m]
, when defined
radius
=
tree
.
radius
,
# [m]
color
=
"black"
,
color
=
"black"
,
weight
=
1
,
weight
=
1
,
fill_opacity
=
0.9
,
fill_opacity
=
0.9
,
...
@@ -205,6 +207,11 @@ def export_csv(bounds, forest, wkt_polygon, tree_distance, min_distance, epsg_id
...
@@ -205,6 +207,11 @@ def export_csv(bounds, forest, wkt_polygon, tree_distance, min_distance, epsg_id
print
(
" DONE!"
)
print
(
" DONE!"
)
def
export_shapefile
(
bounds
,
forest
,
tree_distance
,
epsg_id
):
print
(
"Exporting shapefile"
)
print
(
" DONE!"
)
def
main
(
wkt_polygon
,
epsg_id
,
tree_distance
,
min_distance
,
import_tree_shp
)
->
None
:
def
main
(
wkt_polygon
,
epsg_id
,
tree_distance
,
min_distance
,
import_tree_shp
)
->
None
:
region
,
bounds
=
load_region
(
wkt_polygon
)
region
,
bounds
=
load_region
(
wkt_polygon
)
ways
=
get_osm_roads
(
bounds
)
ways
=
get_osm_roads
(
bounds
)
...
@@ -224,8 +231,8 @@ def main(wkt_polygon, epsg_id, tree_distance, min_distance, import_tree_shp) ->
...
@@ -224,8 +231,8 @@ def main(wkt_polygon, epsg_id, tree_distance, min_distance, import_tree_shp) ->
plot_trees
(
bounds
,
forest
,
tree_distance
)
plot_trees
(
bounds
,
forest
,
tree_distance
)
export_map
(
bounds
,
forest
,
epsg_id
)
export_map
(
bounds
,
forest
,
epsg_id
)
export_csv
(
bounds
,
forest
,
wkt_polygon
,
export_csv
(
bounds
,
forest
,
wkt_polygon
,
tree_distance
,
min_distance
,
epsg_id
)
tree_distance
,
min
_distance
,
epsg_id
)
export_shapefile
(
bounds
,
forest
,
tree
_distance
,
epsg_id
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
python_scripts/add_trees_to_open_street_map/import_existing_trees.py
View file @
a5b79d6b
...
@@ -9,8 +9,9 @@ def get_existing_forest(shp_input):
...
@@ -9,8 +9,9 @@ def get_existing_forest(shp_input):
point
=
tree_row
.
geometry
point
=
tree_row
.
geometry
trees
.
append
(
Tree
(
point
.
x
,
point
.
y
,
trees
.
append
(
Tree
(
point
.
x
,
point
.
y
,
description
=
tree_row
.
Bezeichnun
,
description
=
tree_row
.
Bezeichnun
,
radius
=
tree_row
.
Kroneradi
,
diameter
=
tree_row
.
Kronenbrei
,
type
=
tree_row
.
Baumart
type
=
tree_row
.
Baumart
,
trunk_diameter
=
tree_row
.
Stammumfan
))
))
return
Forest
(
trees
)
return
Forest
(
trees
)
...
...
python_scripts/add_trees_to_open_street_map/tree.py
View file @
a5b79d6b
...
@@ -7,9 +7,10 @@ import kdtree
...
@@ -7,9 +7,10 @@ import kdtree
class
Tree
:
class
Tree
:
x
:
float
x
:
float
y
:
float
y
:
float
diameter
:
float
z
:
float
=
0
z
:
float
=
0
height
:
float
=
None
height
:
float
=
None
radius
:
float
=
None
trunk_diameter
:
float
=
None
type
:
str
=
None
type
:
str
=
None
description
:
str
=
'?'
description
:
str
=
'?'
color
:
str
=
'green'
color
:
str
=
'green'
...
@@ -20,6 +21,10 @@ class Tree:
...
@@ -20,6 +21,10 @@ class Tree:
def
__getitem__
(
self
,
i
):
def
__getitem__
(
self
,
i
):
return
[
self
.
x
,
self
.
y
][
i
]
return
[
self
.
x
,
self
.
y
][
i
]
@
property
def
radius
(
self
):
return
self
.
diameter
/
2
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"
{
self
.
type
}
(
{
self
.
description
}
),
{
self
.
radius
or
'?'
}
m (X=
{
self
.
x
:
.
1
f
}
, Y=
{
self
.
y
:
.
1
f
}
)"
return
f
"
{
self
.
type
}
(
{
self
.
description
}
),
{
self
.
radius
or
'?'
}
m (X=
{
self
.
x
:
.
1
f
}
, Y=
{
self
.
y
:
.
1
f
}
)"
...
...
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