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

add: lake relations directory path to consts

parent 46002dd4
No related branches found
No related tags found
1 merge request!12Clhp map
......@@ -9,5 +9,7 @@ CERT_DIR = "server/certificates/"
SSL_KEY_PATH = CERT_DIR + "testKey.key"
SSL_CERT_PATH = CERT_DIR + "testCert.crt"
# Measurement specs
AREA_SIZE = 20
# File paths
MAP_HANDLER_PATH = "server/map_handler/"
LAKE_RELATIONS_PATH = MAP_HANDLER_PATH + "lake_relations/"
......@@ -7,9 +7,10 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT
from map_handler.add_lake import cut_map
from server.consts import LAKE_RELATIONS_PATH
from map_handler.process_lake import get_divided_map
from map_handler.get_measurements import get_all_markers
from map_handler.input_new_data import input_new_Lidar_data
from map_handler.process_lake import get_divided_map, get_ids_and_centers
app = Flask(__name__)
terminate_server = 0
......@@ -42,7 +43,7 @@ class IceHTTP(BaseHTTPRequestHandler):
self.wfile.write(b"Root path hit!")
elif self.path == '/get_lake_names':
with open('server/map_handler/lake_relations/all_lake_names.json', 'r') as file:
with open(LAKE_RELATIONS_PATH + 'all_lake_names.json', 'r') as file:
lake_names = json.load(file)
# Disable ensure_ascii to keep 'ø'
......@@ -64,9 +65,6 @@ class IceHTTP(BaseHTTPRequestHandler):
get_divided_map(self, 'Mjosa') # NB temp hardcoded value
elif self.path == '/divide_new_relation':
cut_map(self, 'Mjosa')
elif self.path == '/test':
get_ids_and_centers('server/map_handler/lake_relations/mjosa_div.json')
def do_POST(self):
if self.path == '/new_lidar_data':
input_new_Lidar_data(self, self.cursor, 1, 'Mjosa') # hardcoded body of water must change later
......
......@@ -3,12 +3,13 @@ from shapely.geometry import Polygon, LineString, MultiLineString
from shapely.ops import linemerge, unary_union, polygonize
import json
import os
from server.consts import LAKE_RELATIONS_PATH
# Read a json file with relation data and send to response object
def cut_map(self, body_of_water: str): # NB: implement body_of_water
# Read relation from GeoJson file and extract all polygons
geo_data = gpd.read_file("server/map_handler/lake_relations/mjosa.geojson")
geo_data = gpd.read_file(LAKE_RELATIONS_PATH + "mjosa.geojson")
polygon_data = geo_data[geo_data['geometry'].geom_type == 'Polygon']
polygons = [Polygon(polygon.exterior) for polygon in polygon_data['geometry']]
......@@ -90,7 +91,7 @@ def cut_map(self, body_of_water: str): # NB: implement body_of_water
# NB currently hardcoded file path
# Create the txt file specified by the path
with open("server/map_handler/lake_relations/mjosa_centers.txt", 'w') as file:
with open(LAKE_RELATIONS_PATH + "mjosa_centers.txt", 'w') as file:
# Iterate over the list and write each element to the file
for sub_div_id, x, y in sub_div_center_list:
file.write(f"{sub_div_id}, {x}, {y}\n") # Write each list entry on a new line
......
import json
from server.consts import LAKE_RELATIONS_PATH
# Writes contents of a lake json file to the response
......@@ -8,23 +8,8 @@ def get_divided_map(self, file_name):
self.end_headers()
# Extract contents from JSON file
with open("server/map_handler/lake_relations/" + file_name + "_div.json", "r") as file:
with open(LAKE_RELATIONS_PATH + 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 all sub_division ids and their center coordinates for a given lake
def get_ids_and_centers(file_path): # NB buggy
# Expected format: [(sub_div_id, [x,y]), (sub_div_id, [x,y]), ...]
return_list = []
f = open(file_path)
data = json.load(f)
for measurement in data['measurement']:
for sub_div in measurement['Subdivisions']:
return_list.append((sub_div['SubdivID'], (sub_div['CenLatitude'], sub_div['CenLongitude'])))
return return_list
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