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
4546ff39
Commit
4546ff39
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: minor improvement, new edge points
parent
592f0b73
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
+30
-17
30 additions, 17 deletions
server/map/get_relation.py
with
30 additions
and
17 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
4546ff39
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
30
−
17
View file @
4546ff39
...
...
@@ -5,6 +5,8 @@ import matplotlib.ticker as ticker
import
random
import
numpy
as
np
polygon_min_x
=
None
# The left most point of the entire polygon
def
get_relation
(
self
,
body_of_water
:
str
):
# Load GeoJSON data using geopandas
...
...
@@ -38,7 +40,7 @@ def get_relation(self, body_of_water: str):
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
,
cell_size
)
divided_poly
=
cut_polygon_
by_points
(
polygon
,
hrz_line
,
cell_size
)
horizontal_section
=
divided_poly
[
0
]
# Save upper horizontal section
polygon
=
divided_poly
[
1
]
# Set polygon to the remaining, un-split shape for next iteration
...
...
@@ -49,10 +51,10 @@ def get_relation(self, body_of_water: str):
# 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
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
,
-
0.1
)
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
...
...
@@ -92,8 +94,8 @@ 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
,
cell_size
:
float
):
# coordinate that defines the point of division
.
def
cut_polygon_
by_points
(
polygon
:
Polygon
,
divisor
:
float
,
cell_size
:
float
):
# Extract polygon exterior coordinates
exterior_coords
=
list
(
polygon
.
exterior
.
coords
)
...
...
@@ -110,21 +112,29 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, cell_size: float):
else
:
remaining_shape
.
append
(
point
)
if
len
(
split_shape
)
>
2
:
# Get last point added to
last_point
=
split_shape
[
-
1
]
# Get length of the newly created edge
new_edge_len
=
abs
(
last_point
.
x
-
split_shape
[
0
].
x
)
print
(
"
new_edge_len:
"
,
new_edge_len
,
"
cell_size:
"
,
cell_size
,
"
last_point.x:
"
,
last_point
.
x
,
"
split_shape[0].x:
"
,
split_shape
[
0
].
x
)
#################################################################
# Prepend new points onto the newly created edge to facilitate vertical splitting
if
len
(
split_shape
)
>
2
and
polygon_min_x
is
not
None
:
# Define starting point with an x-value that will be common for all polygons
starting_point
=
polygon_min_x
# Get corners of the newly created shape which make up the new edge
right_corner
=
split_shape
[
-
1
]
left_corner
=
split_shape
[
0
]
print
(
"
right_corner:
"
,
right_corner
,
"
left_corner:
"
,
left_corner
,
"
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
:
x_val
=
new_edge_len
-
cell_size
while
starting_point
<
left_corner
.
x
:
# Increment starting point until it is withing the polygons bounds
starting_point
+=
cell_size
split_shape
.
insert
(
0
,
(
x_val
,
last_point
.
y
))
# NB may have to add/subtract small offset of 0.00001
remaining_shape
.
insert
(
0
,
(
x_val
,
last_point
.
y
))
# Prepend
# Insert new points with cell_size spacing while starting_point is within bounds
while
starting_point
<
right_corner
.
x
:
new_edge_len
-=
cell_size
split_shape
.
insert
(
0
,
(
starting_point
,
divisor
))
# NB may have to add/subtract small offset of 0.00001
remaining_shape
.
insert
(
0
,
(
starting_point
,
divisor
))
# Prepend new point to shape
starting_point
+=
cell_size
#################################################################
else
:
# Vertical split
for
point
in
exterior_coords
:
...
...
@@ -157,6 +167,9 @@ 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
)
...
...
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