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
4e580b52
Commit
4e580b52
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: minor progress, part of map
parent
59a0e44e
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
+18
-12
18 additions, 12 deletions
server/map/get_relation.py
with
18 additions
and
12 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
4e580b52
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
18
−
12
View file @
4e580b52
...
...
@@ -30,8 +30,8 @@ def get_relation(self, body_of_water: str):
# Divide the length and with of polygon into a grid
grid_lines
=
create_grid_coords
(
polygon
,
cell_size
=
0.1
)
hrz_lines
=
grid_lines
[
0
]
# Horizontal coordinates
vrt_lines
=
grid_lines
[
1
]
# Vertical coordinates
hrz_lines
=
[
60.7451
]
# Horizontal coordinates
vrt_lines
=
[
10.9600
]
# Vertical coordinates
# Cut polygon into horizontal sections
for
hrz_line
in
hrz_lines
:
...
...
@@ -50,7 +50,7 @@ def get_relation(self, body_of_water: str):
if
not
cut_poly_2
[
0
]:
continue
divided_map
.
ext
end
(
cut_poly_2
[
0
])
# Append part to final list of shapes
divided_map
.
app
end
(
cut_poly_2
[
0
])
# Append part to final list of shapes
# Set polygon_part to the remaining, un-split, horizontal section for next iteration
polygon_part
=
cut_poly_2
[
1
]
...
...
@@ -92,26 +92,31 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
for
point
in
exterior_coords
:
point
=
Point
(
point
)
# Convert coordinates to Shapely Point object
if
horizontal
:
# Horizontal split
if
point
.
y
<
divisor
:
if
point
.
y
>
divisor
:
split_shape
.
append
(
point
)
else
:
remaining_shape
.
append
(
point
)
else
:
# Vertical split
if
point
.
x
<
divisor
:
if
point
.
x
>
divisor
:
split_shape
.
append
(
point
)
else
:
remaining_shape
.
append
(
point
)
# Check if polygons have enough coordinates
if
len
(
split_shape
)
<
3
or
len
(
remaining_shape
)
<
3
:
print
(
"
Not enough coordinates to create valid polygons
"
)
return
None
,
None
if
len
(
split_shape
)
<
3
:
print
(
"
Not enough coordinates to create valid polygons: Split shape
"
)
split_shape
=
None
else
:
split_shape
.
append
(
split_shape
[
0
])
# NB: may not be necessary?
# Append the first coordinate of the shapes to create closed loop
split_shape
.
append
(
split_shape
[
0
])
# NB: may not be necessary?
remaining_shape
.
append
(
remaining_shape
[
0
])
if
len
(
remaining_shape
)
<
3
:
print
(
"
Not enough coordinates to create valid polygons: Remaining shape
"
)
remaining_shape
=
None
else
:
remaining_shape
.
append
(
remaining_shape
[
0
])
return
Polygon
(
split_shape
),
Polygon
(
remaining_shape
)
# Return split polygons as Shapely Polygon objects
# Return split polygons as Shapely Polygon objects
return
Polygon
(
split_shape
),
Polygon
(
remaining_shape
)
# Generate grid of equally spaced x and y coordinates where the grid size is determined by cell_size
...
...
@@ -123,5 +128,6 @@ def create_grid_coords(polygon: Polygon, cell_size: float):
if
len
(
x_coords
)
==
0
or
len
(
y_coords
)
==
0
:
raise
ValueError
(
"
No grid points generated
"
)
# Return tuple of list of x coordinates and list of y coordinates
return
x_coords
,
y_coords
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