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
932a6b89
Commit
932a6b89
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: perhaps some improvement
parent
adb005ac
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
+11
-19
11 additions, 19 deletions
server/map/get_relation.py
with
11 additions
and
19 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
932a6b89
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
11
−
19
View file @
932a6b89
...
...
@@ -19,7 +19,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
# Divide all polygons into sections
for
polygon
in
polygons
:
cell_size
=
0.4
cell_size
=
1.5
# Divide the length and with of polygon into a grid of equally sized parts
grid_lines
=
create_grid_coords
(
polygon
,
cell_size
)
...
...
@@ -28,7 +28,6 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
# 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_by_points
(
polygon
,
hrz_line
,
cell_size
)
horizontal_section
=
divided_poly
[
0
]
# Save upper horizontal section
...
...
@@ -122,10 +121,13 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float):
remaining_shape
.
append
((
point2
.
x
,
point2
.
y
))
# Populate newly created edges with points to facilitate vertical cutting
populated_shapes
=
populate_new_edge
(
split_shape
,
remaining_shape
,
cell_size
,
divisor
)
if
populated_shapes
is
not
None
:
split_shape
=
populated_shapes
[
0
]
remaining_shape
=
populated_shapes
[
1
]
populated_split
=
populate_new_edge
(
split_shape
,
cell_size
,
divisor
)
if
populated_split
is
not
None
:
split_shape
=
populated_split
populated_rem
=
populate_new_edge
(
remaining_shape
,
cell_size
,
divisor
)
if
populated_rem
is
not
None
:
remaining_shape
=
populated_rem
# Ensure that the shapes are closed loops
if
len
(
split_shape
)
>
0
and
split_shape
[
0
]
!=
split_shape
[
-
1
]:
...
...
@@ -137,7 +139,6 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float):
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
def
create_grid_coords
(
polygon
:
Polygon
,
cell_size
:
float
):
# Define boundaries of grid
...
...
@@ -174,7 +175,7 @@ def circle_polygon():
# Adds equally spaced points along an edge that is created after a polygon is cut.
def
populate_new_edge
(
split_shape
,
remaining_shape
,
cell_size
:
float
,
divisor
:
float
):
def
populate_new_edge
(
split_shape
,
cell_size
:
float
,
divisor
:
float
):
# Prepend new points onto the newly created edge to facilitate vertical splitting
if
split_shape
is
not
None
and
polygon_min_x
is
not
None
:
# Define starting point with an x-value that will be common for all polygons
...
...
@@ -183,11 +184,9 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f
# Create list of corners
corners
=
[]
divisor_range
=
((
divisor
-
0.1
),(
divisor
+
0.1
))
# Define tolerance NB: must find appropriate value
# Find all corners of split shape. Corner = point that intersects divisor
for
point
in
split_shape
:
if
divisor_range
[
0
]
<
point
[
1
]
<
divisor
_range
[
1
]
:
if
point
[
1
]
==
divisor
:
corners
.
append
(
point
)
if
not
corners
or
len
(
corners
)
<
2
:
...
...
@@ -199,16 +198,9 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f
while
starting_point
<
sorted_corners
[
0
][
0
]:
# 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)
# Insert new points with cell_size spacing while starting_point is within bounds
while
starting_point
<
sorted_corners
[
-
1
][
0
]:
split_shape
.
insert
(
0
,
(
starting_point
,
divisor
))
# NB may have to add/subtract small offset of 0.00001
remaining_shape
.
insert
(
-
1
,
(
starting_point
,
divisor
))
# Prepend new point to shape
starting_point
+=
cell_size
return
split_shape
,
remaining_shape
return
split_shape
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