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
1aec7901
Commit
1aec7901
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: colored plotting for testing
parent
84468543
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
+23
-14
23 additions, 14 deletions
server/map/get_relation.py
with
23 additions
and
14 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
1aec7901
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
23
−
14
View file @
1aec7901
import
geopandas
as
gpd
from
shapely.geometry
import
Polygon
,
Point
,
LineString
,
MultiPolygon
import
matplotlib.pyplot
as
plt
from
shapely.ops
import
linemerge
,
unary_union
,
polygonize
import
matplotlib.ticker
as
ticker
import
random
import
numpy
as
np
...
...
@@ -30,23 +30,29 @@ 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
=
grid_lines
[
1
]
# Horizontal coordinates
for
line
in
hrz_lines
:
print
(
"
line:
"
,
line
)
vrt_lines
=
[
11.0413
]
# Vertical coordinates
vrt_lines
=
grid_lines
[
0
]
# Vertical coordinates
for
line
in
vrt_lines
:
print
(
"
Line:
"
,
line
)
# Cut polygon into horizontal sections
# 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
cut_poly_1
=
cut_polygon_in_two
(
polygon
,
hrz_line
,
True
)
polygon_part
=
cut_poly_1
[
0
]
# Save upper horizontal section
divided_map
.
append
(
polygon_part
)
if
not
polygon_part
or
not
cut_poly_1
[
0
]:
continue
# Cut each horizontal section into vertical sections, right to left
for
vrt_line
in
vrt_lines
:
cut_poly_2
=
cut_polygon_in_two
(
polygon_part
,
vrt_line
,
False
)
divided_map
.
append
(
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
]
polygon
=
cut_poly_1
[
1
]
# Set polygon to the remaining, un-split shape for next iteration
...
...
@@ -61,9 +67,12 @@ def get_relation(self, body_of_water: str):
ax
.
set_aspect
(
1.5
)
ax
.
xaxis
.
set_major_locator
(
ticker
.
MultipleLocator
(
0.2
))
for
polygon
in
tiles
[
'
geometry
'
]:
for
i
,
polygon
in
enumerate
(
tiles
[
'
geometry
'
]):
random_color
=
"
#{:06x}
"
.
format
(
random
.
randint
(
0
,
0xFFFFFF
))
x
,
y
=
polygon
.
exterior
.
xy
ax
.
plot
(
x
,
y
,
color
=
'
blue
'
,
alpha
=
0.5
)
# Plot the exterior of the polygon
ax
.
plot
(
x
,
y
,
color
=
'
blue
'
,
alpha
=
0.5
)
ax
.
fill
(
x
,
y
,
color
=
random_color
,
alpha
=
0.5
)
plt
.
show
()
...
...
@@ -105,14 +114,14 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
# Check if the split_shape has enough coordinates to create a polygon
if
len
(
split_shape
)
<
3
:
print
(
"
Not enough coordinates to create valid polygon: Split shape:
"
,
len
(
split_shape
))
#
print("Not enough coordinates to create valid polygon: Split shape: ", len(split_shape))
split_shape
=
None
else
:
split_shape
.
append
(
split_shape
[
0
])
# Append first coord to create closed loop
# Check if the remaining_shape has enough coordinates to create a polygon
if
len
(
remaining_shape
)
<
3
:
print
(
"
Not enough coordinates to create valid polygon: Remaining shape:
"
,
len
(
remaining_shape
))
#
print("Not enough coordinates to create valid polygon: Remaining shape: ", len(remaining_shape))
remaining_shape
=
None
else
:
remaining_shape
.
append
(
remaining_shape
[
0
])
# Append first coord to create closed loop
...
...
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