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
adb005ac
Commit
adb005ac
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: horizontal sections, no spacing, wrong verticals
parent
3aeee368
No related branches found
Branches containing commit
No related tags found
Loading
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
-5
11 additions, 5 deletions
server/map/get_relation.py
with
11 additions
and
5 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
adb005ac
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
11
−
5
View file @
adb005ac
...
...
@@ -44,7 +44,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
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
)
vertical_parts
=
cut_polygon_by_points
(
horizontal_section
,
vrt_line
,
cell_size
)
divided_map
.
append
(
vertical_parts
[
0
])
# Append split vertical sections to final list of shapes
...
...
@@ -121,6 +121,12 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float):
else
:
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
]
# Ensure that the shapes are closed loops
if
len
(
split_shape
)
>
0
and
split_shape
[
0
]
!=
split_shape
[
-
1
]:
split_shape
.
append
(
split_shape
[
0
])
...
...
@@ -181,23 +187,23 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f
# Find all corners of split shape. Corner = point that intersects divisor
for
point
in
split_shape
:
if
divisor_range
[
0
]
<
point
.
y
<
divisor_range
[
1
]:
if
divisor_range
[
0
]
<
point
[
1
]
<
divisor_range
[
1
]:
corners
.
append
(
point
)
if
not
corners
or
len
(
corners
)
<
2
:
return
None
# Sort corners in ascending order (left to right) based on x coordinate
sorted_corners
=
sorted
(
corners
,
key
=
lambda
p
:
p
.
x
)
sorted_corners
=
sorted
(
corners
,
key
=
lambda
p
:
p
[
0
]
)
while
starting_point
<
sorted_corners
[
0
]
.
x
:
# Increment starting point until it is withing the polygons bounds
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
]
.
x
:
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
...
...
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