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
3b1ae240
Commit
3b1ae240
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
add: some error handling, still no split
parent
d4dce05a
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
-10
23 additions, 10 deletions
server/map/get_relation.py
with
23 additions
and
10 deletions
server/map/__pycache__/get_relation.cpython-311.pyc
+
0
−
0
View file @
3b1ae240
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_relation.py
+
23
−
10
View file @
3b1ae240
...
...
@@ -7,21 +7,21 @@ import numpy as np
def
get_relation
(
self
,
body_of_water
:
str
):
print
(
"
In get_relation
"
)
# Load GeoJSON data using geopandas
geo_data
=
gpd
.
read_file
(
"
server/map/mjosa.geojson
"
)
# Filter only polygons, exclude points and other feature types to reduce response size
polygon_data
=
geo_data
[
geo_data
[
'
geometry
'
].
geom_type
==
'
Polygon
'
]
if
not
polygon_data
:
raise
ValueError
(
"
Failed to extract polygon data from file
"
)
# Extract coordinates from polygons and create polygon objects
polygons
=
[
Polygon
(
polygon
.
exterior
)
for
polygon
in
polygon_data
[
'
geometry
'
]]
if
len
(
polygons
)
<=
1
:
# Return if conversion to polygon fails
print
(
"
Failed to convert to polygons
"
)
return
if
not
polygons
:
raise
ValueError
(
"
Failed to convert to polygons
"
)
print
(
"
Creating grid and cutting polygons
"
)
divided_map
=
[]
# Divide all polygons into sections
...
...
@@ -71,21 +71,31 @@ def get_relation(self, body_of_water: str):
def
cut_polygon_in_two
(
polygon
,
line
):
points
=
list
(
polygon
.
exterior
.
coords
)
# Extract polygon coordinates
# Check for invalid parameters
if
not
isinstance
(
polygon
,
Polygon
)
or
not
isinstance
(
line
,
LineString
):
print
(
"
Inputs must be Shapely Polygon and LineString obects
"
)
# Extract polygon exterior coordinates
exterior_coords
=
list
(
polygon
.
exterior
.
coords
)
# Initialize lists to store points for the two shapes
shape_1
=
[]
shape_2
=
[]
# Split points into separate shapes based on their location relative to line
for
point
in
point
s
:
# Split points into separate shapes based on their location relative to
the
line
for
point
in
exterior_coord
s
:
point
=
Point
(
point
)
# Convert coordinates to Shapely Point object
if
line
.
distance
(
point
)
<
1e-10
:
# Floating point error tolerance
if
line
.
contains
(
point
):
# Determine if point
goes in
to shape 1 or shape 2
if
line
.
contains
(
point
):
# Determine if point
belongs
to shape 1 or shape 2
shape_1
.
append
(
point
)
else
:
shape_2
.
append
(
point
)
# Convert the lists of points to Polygon objects
# Check if shapes are empty
if
not
shape_1
or
not
shape_2
:
raise
ValueError
(
"
One or both shapes are empty after cutting
"
)
# Create Polygon objects from the lists of points
poly_1
=
Polygon
(
shape_1
)
poly_2
=
Polygon
(
shape_2
)
...
...
@@ -119,4 +129,7 @@ def create_grid(polygon, cell_size):
for
y
in
y_coords
:
horizontal_lines
.
append
(
LineString
([(
min_x
,
y
),
(
max_x
,
y
)]))
if
not
horizontal_lines
or
not
vertical_lines
:
raise
ValueError
(
"
List of horizontal or vertical lines is empty
"
)
return
horizontal_lines
,
vertical_lines
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