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
bf55e2ec
Commit
bf55e2ec
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: progress in new group implementation
parent
3ad18fe6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/map/get_lake.py
+39
-23
39 additions, 23 deletions
server/map/get_lake.py
with
39 additions
and
23 deletions
server/map/get_lake.py
+
39
−
23
View file @
bf55e2ec
import
geopandas
as
gpd
import
geopandas
as
gpd
from
shapely.geometry
import
Polygon
,
LineString
,
MultiLineString
from
shapely.geometry
import
Polygon
,
MultiPolygon
from
shapely.ops
import
linemerge
,
unary_union
,
polygonize
from
shapely.ops
import
linemerge
,
unary_union
,
polygonize
import
json
import
json
from
server.map.add_new_lake
import
write_json_to_file
from
server.map.add_new_lake
import
write_json_to_file
...
@@ -19,6 +19,7 @@ def fetch_divided_map(self, file_name):
...
@@ -19,6 +19,7 @@ def fetch_divided_map(self, file_name):
self
.
wfile
.
write
(
data
.
encode
(
'
utf-8
'
))
self
.
wfile
.
write
(
data
.
encode
(
'
utf-8
'
))
# Create groups creates polygons which consist of groupings of related subdivisions
def
create_groups
(
relation_file
:
str
,
data
:
list
):
def
create_groups
(
relation_file
:
str
,
data
:
list
):
# Read lake relation from json file
# Read lake relation from json file
geo_data
=
gpd
.
read_file
(
"
server/lake_relations/
"
+
relation_file
+
"
_div.json
"
)
geo_data
=
gpd
.
read_file
(
"
server/lake_relations/
"
+
relation_file
+
"
_div.json
"
)
...
@@ -40,29 +41,44 @@ def create_groups(relation_file: str, data: list):
...
@@ -40,29 +41,44 @@ def create_groups(relation_file: str, data: list):
if
feature
[
'
sub_div_id
'
]
==
subDivID
:
if
feature
[
'
sub_div_id
'
]
==
subDivID
:
subdiv_list
.
append
((
group_id
,
Polygon
([
feature
[
'
coordinates
'
]])))
subdiv_list
.
append
((
group_id
,
Polygon
([
feature
[
'
coordinates
'
]])))
# Sort subdiv_list in ascending order of group_ids
# Sort subdiv_list based on group_ids
# While group_id is same -> merge all polygons and give each a group id
sorted_list
=
sorted
(
subdiv_list
,
key
=
lambda
x
:
x
[
0
])
# new_polygons.append((group_id, new_shape))
# Put the coordinates and group id of each new polygon in the expected structure
for
polygon
in
new_polygons
:
'''
Expected structure:
{
"
type
"
:
"
Feature
"
,
"
properties
"
: {
"
group_id
"
:
"
0
"
,
},
"
geometry
"
: {
"
type
"
:
"
Polygon
"
,
"
coordinates
"
: [
[
[
10.4304,...
'''
current_group
=
-
1
# Current group_id
# 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
:
merged_polygon
=
MultiPolygon
(
new_shape
).
buffer
(
0
)
# Convert MultiPolygon to Polygon
if
isinstance
(
merged_polygon
,
MultiPolygon
):
merged_polygon
=
merged_polygon
.
convex_hull
# Add following structure to new polygon
'''
Expected structure:
{
"
type
"
:
"
Feature
"
,
"
properties
"
: {
"
group_id
"
:
"
0
"
,
},
"
geometry
"
: {
"
type
"
:
"
Polygon
"
,
"
coordinates
"
: [
[
[
10.4304,...
'''
# Append to new_polygons
current_group
=
element
[
0
]
# Update current group to new group_id
else
:
current_group
=
element
[
0
]
# Convert GeoDataFrame to JSON
# Convert GeoDataFrame to 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