Skip to content
Snippets Groups Projects
Commit c7cce876 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

upate: approach 2 to group shapes

parent bf55e2ec
No related branches found
No related tags found
No related merge requests found
......@@ -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':
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment