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
a4a9d703
Commit
a4a9d703
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: test with circle, update grid creation
parent
05b1ca38
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
+31
-29
31 additions, 29 deletions
server/map/get_relation.py
with
31 additions
and
29 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
a4a9d703
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
31
−
29
View file @
a4a9d703
...
...
@@ -26,12 +26,15 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
if
not
polygons
:
raise
ValueError
(
"
Failed to convert to polygons
"
)
divided_map
=
[]
divided_map
=
[]
# List to store map shapes while splitting
# NB: test polygon, remove after testing
polygons
=
[
circle_polygon
()]
# Divide all polygons into sections
for
polygon
in
polygons
:
cell_size
=
0.
1
cell_size
=
0.
4
# Divide the length and with of polygon into a grid of equally sized parts
grid_lines
=
create_grid_coords
(
polygon
,
cell_size
)
...
...
@@ -50,18 +53,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
if
not
horizontal_section
or
not
divided_poly
[
0
]:
continue
# Cut each horizontal section into vertical sections, right to left
for
vrt_line
in
vrt_lines
:
if
len
(
horizontal_section
.
exterior
.
coords
)
<
3
:
break
# Break from loop im remaining section has no coordinates
# Split the horizontal section into two vertical parts
vertical_parts
=
cut_polygon_by_points
(
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
]
divided_map
.
append
(
horizontal_section
)
divided_map
.
append
(
polygon
)
...
...
@@ -115,7 +107,9 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float):
remaining_shape
.
append
(
point
)
# Add points to the newly created edges of split_shape and remaining_shape
split_shape
,
remaining_shape
=
populate_new_edge
(
split_shape
,
remaining_shape
,
cell_size
,
divisor
)
populate_new_edge
(
split_shape
,
remaining_shape
,
cell_size
,
divisor
)
#split_shape = shape_w_edges[0]
#remaining_shape = shape_w_edges[1]
else
:
# Vertical split
for
point
in
exterior_coords
:
...
...
@@ -154,11 +148,10 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f
right_corner
=
split_shape
[
-
1
]
left_corner
=
split_shape
[
0
]
print
(
"
right_corner:
"
,
right_corner
,
"
left_corner:
"
,
left_corner
,
"
cell_size:
"
,
cell_size
)
print
(
"
right_corner:
"
,
right_corner
,
"
left_corner:
"
,
left_corner
,
"
left == right?:
"
,
left_corner
==
right_corner
)
while
starting_point
<
left_corner
.
x
:
# Increment starting point until it is withing the polygons bounds
starting_point
+=
cell_size
# if starting_point < left_corner.x: # NB: optimised substitute for previous while loop, requires testing
# starting_point += cell_size * math.floor(starting_point - left_corner.x)
...
...
@@ -177,19 +170,28 @@ def create_grid_coords(polygon: Polygon, cell_size: float):
# Define boundaries of grid
min_x
,
min_y
,
max_x
,
max_y
=
polygon
.
bounds
global
polygon_min_x
# Set value of global variable
polygon_min_x
=
min_x
# Divide grid into sections of size *cell_size
x_coords
=
np
.
arange
(
min_x
,
max_x
,
cell_size
)
y_coords
=
np
.
arange
(
min_y
,
max_y
,
cell_size
)
x_step
=
max
((
max_x
-
min_x
)
/
10
,
cell_size
)
y_step
=
max
((
max_y
-
min_y
)
/
10
,
cell_size
)
x_coords
=
np
.
arange
(
min_x
,
max_x
+
x_step
,
x_step
)
y_coords
=
np
.
arange
(
min_y
,
max_y
+
y_step
,
y_step
)
return
x_coords
,
y_coords
# Round coordinates to 4 decimals
x_coords_rounded
=
np
.
around
(
x_coords
,
decimals
=
4
)
y_coords_rounded
=
np
.
around
(
y_coords
,
decimals
=
4
)
# NB: only for testing
def
circle_polygon
():
circle_points
=
[]
num_points
=
80
center_x
,
center_y
=
0.0
,
0.0
radius
=
6
if
len
(
x_coords_rounded
)
==
0
or
len
(
y_coords_rounded
)
==
0
:
raise
ValueError
(
"
No grid points generated
"
)
for
i
in
range
(
num_points
):
angle
=
2
*
np
.
pi
*
i
/
num_points
x
=
center_x
+
radius
*
np
.
cos
(
angle
)
y
=
center_y
+
radius
*
np
.
sin
(
angle
)
circle_points
.
append
((
x
,
y
))
circle_points
.
append
(
circle_points
[
0
])
# Close the circle
# Return tuple of list of x coordinates and list of y coordinates
return
x_coords_rounded
,
y_coords_rounded
return
Polygon
(
circle_points
)
\ No newline at end of file
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