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
c7cce876
Commit
c7cce876
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
upate: approach 2 to group shapes
parent
bf55e2ec
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/main.py
+1
-1
1 addition, 1 deletion
server/main.py
server/map/get_lake.py
+16
-17
16 additions, 17 deletions
server/map/get_lake.py
with
17 additions
and
18 deletions
server/main.py
+
1
−
1
View file @
c7cce876
...
...
@@ -41,7 +41,7 @@ class IceHTTP(BaseHTTPRequestHandler):
get_all_markers
(
self
,
self
.
cursor
,
'
mjosa
'
)
# Get all markers
# NB: temporary hardcoded waterBodyName
elif
self
.
path
==
'
/get_relation
'
:
cut
_map
(
self
,
'
mjosa
'
)
# NB temp hardcoded value
fetch_divided
_map
(
self
,
'
mjosa
'
)
# NB temp hardcoded value
def
do_POST
(
self
):
if
self
.
path
==
'
/get_weather_data
'
:
...
...
This diff is collapsed.
Click to expand it.
server/map/get_lake.py
+
16
−
17
View file @
c7cce876
...
...
@@ -26,7 +26,7 @@ def create_groups(relation_file: str, data: list):
relation_data
=
geo_data
[
geo_data
[
'
geometry
'
].
geom_type
==
'
Polygon
'
]
new_polygons
=
[]
# Add group IDs to lake relation
for
measurement
in
data
:
subdiv_list
=
[]
...
...
@@ -45,13 +45,14 @@ def create_groups(relation_file: str, data: list):
sorted_list
=
sorted
(
subdiv_list
,
key
=
lambda
x
:
x
[
0
])
current_group
=
-
1
# Current group_id
new_shape
=
[]
# While group_id is same -> merge all polygons and give each a group id
for
element
in
sorted_list
:
new_shape
=
[]
if
element
[
0
]
==
current_group
:
new_shape
.
append
(
element
[
1
])
elif
current_group
>
-
1
:
elif
len
(
new_shape
)
>
1
:
merged_polygon
=
MultiPolygon
(
new_shape
).
buffer
(
0
)
# Convert MultiPolygon to Polygon
...
...
@@ -59,33 +60,31 @@ def create_groups(relation_file: str, data: list):
merged_polygon
=
merged_polygon
.
convex_hull
# Add following structure to new polygon
'''
Expected structure:
{
merged_polygon_structure
=
{
"
type
"
:
"
Feature
"
,
"
properties
"
:
{
"
group_id
"
:
"
0
"
,
"
group_id
"
:
current_group
,
},
"
geometry
"
:
{
"
type
"
:
"
Polygon
"
,
"
coordinates
"
: [
[
[
10.4304,...
'''
"
coordinates
"
:
[
list
(
merged_polygon
.
exterior
.
coords
)]
}
}
# Append to new_polygons
# Append new polygon to new_polygons
new_polygons
.
append
(
merged_polygon_structure
)
current_group
=
element
[
0
]
# Update current group to new group_id
else
:
# Update current group to new group_id and reset new_shapes for next group
current_group
=
element
[
0
]
new_shape
=
[]
# Append all new shapes
relation_data
=
relation_data
.
append
(
new_polygons
,
ignore_index
=
True
)
# Convert GeoDataFrame to JSON
relation_data_json
=
json
.
loads
(
relation_data
.
to_json
())
# Append the new data to the end of features of mjosa_div.json
# Write relation with group shapes to file
write_json_to_file
(
"
server/lake_relations
"
,
"
mjosa
"
,
relation_data_json
)
...
...
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