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
3aeee368
Commit
3aeee368
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: horizontal sections without spacing
parent
82434cba
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
+32
-40
32 additions, 40 deletions
server/map/get_relation.py
with
32 additions
and
40 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
3aeee368
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
32
−
40
View file @
3aeee368
...
...
@@ -96,46 +96,42 @@ def cut_polygon_by_points(polygon: Polygon, divisor: float, cell_size: float):
remaining_shape
=
[]
# Loop through points and check which side of the division line they are
if
cell_size
>
0
:
# Horizontal split
for
point
in
exterior_coords
:
point
=
Point
(
point
)
# Convert coordinates to Shapely Point object
if
point
.
y
<
divisor
:
# Check if point is over or below divisor
split_shape
.
append
(
point
)
# Append to appropriate shape
for
i
in
range
(
len
(
exterior_coords
)
-
1
):
point1
=
Point
(
exterior_coords
[
i
])
point2
=
Point
(
exterior_coords
[
i
+
1
])
# Check if both points are on the same side of the divisor
if
(
point1
.
y
<
divisor
and
point2
.
y
<
divisor
)
or
(
point1
.
y
>=
divisor
and
point2
.
y
>=
divisor
):
# Both points on same side, add to appropriate shape
if
point1
.
y
<
divisor
:
split_shape
.
append
(
exterior_coords
[
i
])
else
:
remaining_shape
.
append
(
point
)
# 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
]
else
:
# Vertical split
for
point
in
exterior_coords
:
point
=
Point
(
point
)
# Convert coordinates to Shapely Point object
if
point
.
x
<
divisor
:
split_shape
.
append
(
point
)
remaining_shape
.
append
(
exterior_coords
[
i
])
else
:
# Points on different sides, calculate intersection with divisor
x_intersect
=
point1
.
x
+
(
divisor
-
point1
.
y
)
*
(
point2
.
x
-
point1
.
x
)
/
(
point2
.
y
-
point1
.
y
)
# Add intersection point to both shapes
split_shape
.
append
((
x_intersect
,
divisor
))
remaining_shape
.
append
((
x_intersect
,
divisor
))
# Determine which side each original point belongs to
if
point1
.
y
<
divisor
:
split_shape
.
append
((
point2
.
x
,
point2
.
y
))
else
:
remaining_shape
.
append
(
point
)
# 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))
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))
remaining_shape
=
None
else
:
remaining_shape
.
append
(
remaining_shape
[
0
])
# Append first coord to create closed loop
# Return split polygons as Shapely Polygon objects
remaining_shape
.
append
((
point2
.
x
,
point2
.
y
))
# 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
])
if
len
(
remaining_shape
)
>
0
and
remaining_shape
[
0
]
!=
remaining_shape
[
-
1
]:
remaining_shape
.
append
(
remaining_shape
[
0
])
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
...
...
@@ -178,20 +174,17 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f
# Define starting point with an x-value that will be common for all polygons
starting_point
=
polygon_min_x
print
(
"
Hit main if
"
)
# Create list of corners
corners
=
[]
divisor_range
=
((
divisor
-
0.1
),(
divisor
+
0.1
))
# Define tolerance
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
.
y
<
divisor_range
[
1
]:
corners
.
append
(
point
)
print
(
"
Hit point in split_shape
"
)
if
not
corners
or
len
(
corners
)
<
2
:
print
(
"
no corners :(
"
)
return
None
# Sort corners in ascending order (left to right) based on x coordinate
...
...
@@ -207,7 +200,6 @@ def populate_new_edge(split_shape, remaining_shape, cell_size: float, divisor: f
while
starting_point
<
sorted_corners
[
-
1
].
x
:
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
print
(
"
Hit point insertion
"
)
starting_point
+=
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