Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sara Savanovic Djordjevic
PROG2900
Commits
0c769f27
Commit
0c769f27
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: attempt to add points to cut dedges
parent
8e591cfd
No related branches found
Branches containing commit
No related tags found
1 merge request
!6
Clhp map
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/map/__pycache__/get_relation.cpython-311.pyc
+0
-0
0 additions, 0 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
server/map/get_relation.py
+28
-13
28 additions, 13 deletions
server/map/get_relation.py
with
28 additions
and
13 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
0c769f27
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
28
−
13
View file @
0c769f27
...
...
@@ -27,22 +27,22 @@ def get_relation(self, body_of_water: str):
# Divide all polygons into sections
for
polygon
in
polygons
:
cell_size
=
0.1
# Divide the length and with of polygon into a grid of equally sized parts
grid_lines
=
create_grid_coords
(
polygon
,
cell_size
=
0.1
)
grid_lines
=
create_grid_coords
(
polygon
,
cell_size
)
vrt_lines
=
grid_lines
[
0
]
# Vertical grid coordinates
hrz_lines
=
grid_lines
[
1
]
# Horizontal grid coordinates
for
line
in
vrt_lines
:
print
(
"
Line:
"
,
line
)
# Cut polygon into horizontal sections, bottom to top
for
hrz_line
in
hrz_lines
:
# Split shape into upper and lower section as hrz_line as divider
divided_poly
=
cut_polygon_in_two
(
polygon
,
hrz_line
,
Tru
e
)
divided_poly
=
cut_polygon_in_two
(
polygon
,
hrz_line
,
cell_siz
e
)
horizontal_section
=
divided_poly
[
0
]
# Save upper horizontal section
polygon
=
divided_poly
[
1
]
# Set polygon to the remaining, un-split shape for next iteration
if
not
horizontal_section
or
not
divided_poly
[
0
]:
continue
...
...
@@ -52,15 +52,13 @@ def get_relation(self, body_of_water: str):
break
# Break from loop im remaining section has no coordinates
# Split the horizontal section into two vertical parts
vertical_parts
=
cut_polygon_in_two
(
horizontal_section
,
vrt_line
,
False
)
vertical_parts
=
cut_polygon_in_two
(
horizontal_section
,
vrt_line
,
-
0.1
)
divided_map
.
append
(
vertical_parts
[
0
])
# Append split vertical sections to final list of shapes
# Set horizontal_section to the remaining, un-split, horizontal section for next iteration
horizontal_section
=
vertical_parts
[
1
]
polygon
=
divided_poly
[
1
]
# Set polygon to the remaining, un-split shape for next iteration
divided_map
.
append
(
polygon
)
break
...
...
@@ -95,7 +93,7 @@ def get_relation(self, body_of_water: str):
# Takes a polygon and divides its coordinates into two shapes, where divisor is a
# coordinate that defines the point of division
def
cut_polygon_in_two
(
polygon
:
Polygon
,
divisor
:
float
,
horizontal
:
bool
):
def
cut_polygon_in_two
(
polygon
:
Polygon
,
divisor
:
float
,
cell_size
:
float
):
# Extract polygon exterior coordinates
exterior_coords
=
list
(
polygon
.
exterior
.
coords
)
...
...
@@ -104,14 +102,31 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
remaining_shape
=
[]
# Loop through points and check which side of the division line they are
for
point
in
exterior_coords
:
point
=
Point
(
point
)
# Convert coordinates to Shapely Point object
if
horizontal
:
# Horizontal spli
t
if
cell_size
>
0
:
# Horizontal split
for
point
in
exterior_coords
:
point
=
Point
(
point
)
# Convert coordinates to Shapely Point objec
t
if
point
.
y
<
divisor
:
split_shape
.
append
(
point
)
else
:
remaining_shape
.
append
(
point
)
else
:
# Vertical split
if
len
(
split_shape
)
>
2
:
# Get last point added to
last_point
=
split_shape
[
len
(
split_shape
)
-
1
]
# Get length of the newly created edge
new_edge_len
=
last_point
.
x
-
split_shape
[
0
].
x
-
0.0001
print
(
"
new_edge_len:
"
,
new_edge_len
,
"
cell_size:
"
,
cell_size
)
# Add points along the new edge to allow horizontal sections to be split into vertical ones
while
new_edge_len
>
cell_size
:
print
(
"
Hit
"
)
split_shape
.
append
((
new_edge_len
-
cell_size
,
last_point
.
y
))
remaining_shape
.
append
((
new_edge_len
-
cell_size
,
last_point
.
y
))
new_edge_len
-=
cell_size
else
:
# Vertical split
for
point
in
exterior_coords
:
point
=
Point
(
point
)
# Convert coordinates to Shapely Point object
if
point
.
x
<
divisor
:
split_shape
.
append
(
point
)
else
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment