diff --git a/server/main.py b/server/main.py index 66166825e62b09cb8fcda081acda65f92a918ff8..cdc9cbd873cc6535da044cfb283ce6d3f89e235b 100644 --- a/server/main.py +++ b/server/main.py @@ -3,6 +3,7 @@ from http.server import HTTPServer, BaseHTTPRequestHandler from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT from map.get_measurements import get_all_markers from map.add_lake import cut_map +from map.process_lake import fetch_divided_map from APIs.get_weather import get_weather from map.input_new_data import input_new_Lidar_data import ssl @@ -40,7 +41,9 @@ 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 + elif self.path == '/divide_new_relation': + cut_map(self, 'Mjosa') def do_POST(self): if self.path == '/get_weather_data': diff --git a/server/map/__pycache__/add_lake.cpython-311.pyc b/server/map/__pycache__/add_lake.cpython-311.pyc index 5791d4e3b431d3b5e9e3a8bfa6f60c3045aaf4dc..254a045f6358b78911bb45510bbcff0aec323d29 100644 Binary files a/server/map/__pycache__/add_lake.cpython-311.pyc and b/server/map/__pycache__/add_lake.cpython-311.pyc differ diff --git a/server/map/__pycache__/get_measurements.cpython-311.pyc b/server/map/__pycache__/get_measurements.cpython-311.pyc index bbc96f8594f835ec1a5d086589f2e08eceb06fce..368701cd4bb230294da15f554647bff65ca17497 100644 Binary files a/server/map/__pycache__/get_measurements.cpython-311.pyc and b/server/map/__pycache__/get_measurements.cpython-311.pyc differ diff --git a/server/map/__pycache__/process_lake.cpython-311.pyc b/server/map/__pycache__/process_lake.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7e90dfd53b3146fc294e1a9df3203d5e8fb93bce Binary files /dev/null and b/server/map/__pycache__/process_lake.cpython-311.pyc differ diff --git a/server/map/process_lake.py b/server/map/process_lake.py new file mode 100644 index 0000000000000000000000000000000000000000..b2f7b85c24eb94025c791d348457914282a4df3d --- /dev/null +++ b/server/map/process_lake.py @@ -0,0 +1,42 @@ +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 + + +# Writes contents of a map json file to the response +def fetch_divided_map(self, file_name): + self.send_response(200) + self.send_header("Content-type", "application/json") + self.end_headers() + + # Extract contents from JSON file + with open("server/lake_relations/" + file_name + "_div.json", "r") as file: + data = file.read() + + # Write contents of the JSON file to response + self.wfile.write(data.encode('utf-8')) + + +# Returns a list of [(sub_div_id, sub_div_center)] +def get_ids_and_centers(file_name): # NB buggy + # Expected format: [(id, [x,y]), (id, [x,y])] + geo_data = gpd.read_file("server/lake_relations/" + file_name + "_div.json") + subdivisions = [] + for index, row in geo_data.iterrows(): + sub_div_id = row['sub_div_id'] + sub_div_center = row['sub_div_center'] + + print("sub_div_id: ", sub_div_id) + + subdivision = { + 'sub_div_id': sub_div_id, + 'sub_div_center': sub_div_center + } + subdivisions.append(subdivision) + return subdivisions +