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
79bd3336
Commit
79bd3336
authored
May 06, 2024
by
Eric Duminil
Browse files
Check if trees are duplicate.
parent
e6ba2d4d
Changes
2
Show whitespace changes
Inline
Side-by-side
python_scripts/add_trees_to_open_street_map/import_existing_trees.py
View file @
79bd3336
...
@@ -5,18 +5,20 @@ from tree import Tree, Forest
...
@@ -5,18 +5,20 @@ from tree import Tree, Forest
def
get_existing_forest
(
shp_input
):
def
get_existing_forest
(
shp_input
):
print
(
f
"Importing
{
shp_input
}
"
)
print
(
f
"Importing
{
shp_input
}
"
)
df
=
gpd
.
read_file
(
shp_input
)
df
=
gpd
.
read_file
(
shp_input
)
tre
es
=
[]
for
es
t
=
Forest
()
for
tree_row
in
df
.
itertuples
():
for
tree_row
in
df
.
itertuples
():
point
=
tree_row
.
geometry
point
=
tree_row
.
geometry
tre
es
.
a
ppend
(
Tree
(
point
.
x
,
point
.
y
,
added
=
for
es
t
.
a
dd_tree_if_possible
(
0.1
,
point
.
x
,
point
.
y
,
description
=
tree_row
.
Bezeichnun
,
description
=
tree_row
.
Bezeichnun
,
diameter
=
tree_row
.
Kronenbrei
,
diameter
=
tree_row
.
Kronenbrei
,
type
=
tree_row
.
Baumart
,
type
=
tree_row
.
Baumart
,
trunk_diameter
=
tree_row
.
Stammumfan
,
trunk_diameter
=
tree_row
.
Stammumfan
,
height
=
tree_row
.
Baumhöhe
,
height
=
tree_row
.
Baumhöhe
,
source
=
Path
(
shp_input
).
name
source
=
Path
(
shp_input
).
name
))
)
return
Forest
(
trees
)
if
not
added
:
print
(
f
"Warning, tree seems to be too close to others! Is it a duplicate?
\n\t
{
tree_row
}
"
)
return
forest
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
print
(
repr
(
get_existing_forest
(
'existing_trees/Trees_ideal_2_20240227.shp'
)))
print
(
repr
(
get_existing_forest
(
'existing_trees/Trees_ideal_2_20240227.shp'
)))
...
...
python_scripts/add_trees_to_open_street_map/tree.py
View file @
79bd3336
...
@@ -39,11 +39,13 @@ class Forest(UserList):
...
@@ -39,11 +39,13 @@ class Forest(UserList):
self
.
data
=
existing_trees
self
.
data
=
existing_trees
def
add_tree_if_possible
(
self
,
min_distance_2
,
x
,
y
,
**
kparams
):
def
add_tree_if_possible
(
self
,
min_distance_2
,
x
,
y
,
**
kparams
)
->
bool
:
_nearest_tree
,
distance_2
=
self
.
kd_tree
.
search_nn
((
x
,
y
))
_nearest_tree
,
distance_2
=
self
.
kd_tree
.
search_nn
((
x
,
y
))
if
distance_2
>
min_distance_2
:
if
distance_2
>
min_distance_2
:
self
.
kd_tree
.
add
((
x
,
y
))
self
.
kd_tree
.
add
((
x
,
y
))
self
.
append
(
Tree
(
x
,
y
,
**
kparams
))
self
.
append
(
Tree
(
x
,
y
,
**
kparams
))
return
True
return
False
@
property
@
property
def
xs_ys_cs
(
self
):
def
xs_ys_cs
(
self
):
...
...
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