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

add: group_id and measurement_id to json resposne

parent f233ed60
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
No preview for this file type
No preview for this file type
import geopandas as gpd
from shapely.geometry import Polygon, LineString, MultiLineString
from shapely.ops import linemerge, unary_union, polygonize
import matplotlib.pyplot as plt
import random
import math
import json
import os
......@@ -72,7 +69,10 @@ def cut_map(self, body_of_water: str): # NB: implement body_of_water
'type': 'Feature',
'properties': {
'sub_div_id': str(sub_div_id),
'sub_div_center': center
'group_id': '', # Initialised empty, will be set upon requesting the relation
'measurement_id': '',
'sub_div_center': center,
},
'geometry': rounded_tile.__geo_interface__
}
......@@ -85,7 +85,7 @@ def cut_map(self, body_of_water: str): # NB: implement body_of_water
'tile_count': sub_div_id, # Add the last subdivision ID as number of tiles
}
#write_json_to_file("server/lake_relations", "mjosa", feature_collection)
# write_json_to_file("server/lake_relations", "mjosa", feature_collection)
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
......
......@@ -119,16 +119,21 @@ def get_all_markers(self, cursor, waterBodyName):
# Add group IDs to lake relation
for measurement in measurements_list:
measurement_id = measurement['MeasurementID'] # Extract measurement ID
measurement_id = str(measurement['MeasurementID']) # Extract measurement ID
for subdivision in measurement['Subdivisions']:
subDivID = str(subdivision['SubdivID']) # Convert to string to match format in feature
group_id = subdivision['GroupID'] # Extract group ID
new_group_id = str(measurement_id) + "-" + str(subdivision['GroupID']) # Create concatenated group ID
new_group_id = str(measurement_id) + "-" + str(group_id) # Create concatenated group ID
# Find the matching subdivision in relation_data
for idx, feature in relation_data.iterrows():
for index, feature in relation_data.iterrows():
# Add the new group ID to the correct subdivision
if feature['properties']['sub_div_id'] == subdivision['sub_div_id']:
relation_data.at[idx, 'GroupID'] = new_group_id
if feature['sub_div_id'] == subDivID:
# Update group_id and measurement_id within the properties
relation_data.at[index, 'group_id'] = new_group_id
relation_data.at[index, 'measurement_id'] = measurement_id
# relation_data.at[index, 'sub_div_center'] = feature['sub_div_center']
####################################################################################
......@@ -146,7 +151,7 @@ def get_all_markers(self, cursor, waterBodyName):
marker_data = json.dumps(data, indent=4)
except Exception as e:
print(f"Error in querying database: {e}")
print(f"Error get_measurements(): {e}")
marker_data = '[]'
# Set headers
......
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