From 3c81892241c78097dcd829e20fa0dac7c81d87f1 Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Tue, 9 Apr 2024 11:22:25 +0200 Subject: [PATCH] update: move map plotting to function + tidy server imports --- server/main.py | 4 +- .../__pycache__/process_lake.cpython-311.pyc | Bin 1705 -> 0 bytes server/map_handler/add_lake.py | 44 +++++++++--------- .../{process_lake.py => get_lake.py} | 0 server/map_handler/get_measurements.py | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 server/map_handler/__pycache__/process_lake.cpython-311.pyc rename server/map_handler/{process_lake.py => get_lake.py} (100%) diff --git a/server/main.py b/server/main.py index 33097ee3..8a1d2a3e 100644 --- a/server/main.py +++ b/server/main.py @@ -3,12 +3,12 @@ import json import sqlite3 from flask import Flask from urllib.parse import urlparse, parse_qs -from http.server import HTTPServer, BaseHTTPRequestHandler from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT +from http.server import HTTPServer, BaseHTTPRequestHandler 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_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 diff --git a/server/map_handler/__pycache__/process_lake.cpython-311.pyc b/server/map_handler/__pycache__/process_lake.cpython-311.pyc deleted file mode 100644 index c3ce2485ffb747f63820d5518630ccdbbaac4910..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1705 zcmZ3^%ge>Uz`zi~ESmO$nStRkhy%k+P{wB|1_p-d3@HpLj5!QZ3@J=43{i|J%q<L2 zOeu`P44N!2K??nnVd_CVHU<U;W(Ed^&q<6Ry)_IAK%y8pg>e}p1H)=Ym;@t34Z{LB z4<-ttQ<zeimoYIgtcKeHRtx8W)WGmE1_p-JFb)GFLkT;a!;r#K!&t?@z>vZUCfQKU zG-aq|s$p8df>4iOp_*FDoB|3F22}lw40+tj42BHFEaglU%#jS`jE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cuKyDQ>G9~c-pL82hC!~F)2_;nt+OFVK5*jI2} zQ83<+z9aXFna_#z3t=f&{8BHNrd^OvzsQqug(u?z7=2&{Y5c&(z$1QvMeH*uZZw&T zK(zumH-R0xlA%Zm<WG=yesS33=BJeAq}mm!FfcHHl2Nf40|UbcW=2NF8w}hHVEBQ9 Vi&6Un1DufIW)%OxfJuPO1ptr!idO&t diff --git a/server/map_handler/add_lake.py b/server/map_handler/add_lake.py index 2a1ab71b..d48efa91 100644 --- a/server/map_handler/add_lake.py +++ b/server/map_handler/add_lake.py @@ -1,8 +1,11 @@ +import os +import json +import random import geopandas as gpd -from shapely.geometry import Polygon, LineString, MultiLineString +from matplotlib import pyplot as plt from shapely.ops import linemerge, unary_union, polygonize -import json -import os +from shapely.geometry import Polygon, LineString, MultiLineString + from server.consts import LAKE_RELATIONS_PATH @@ -34,25 +37,6 @@ def cut_map(self, body_of_water: str): # NB: implement body_of_water divided_map.extend(combine_grid_with_poly(polygon, lines)) - ''' - ####################### PLOTTING ############################ - tiles = [gpd.GeoDataFrame(geometry=[tile]) for tile in divided_map] - - print("Plotting... This may take some time...") - # NB test plot - fig, ax = plt.subplots() - ax.set_aspect(1.5) - - # Plot each tile - for tile in tiles: # NB temporarily limited to 5 tiles - random_color = "#{:06x}".format(random.randint(0, 0xFFFFFF)) - gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none') - - - plt.show() - ##################### PLOTTIND END ########################### - ''' - features = [] sub_div_id = 0 @@ -151,3 +135,19 @@ def write_json_to_file(path: str, file_name: str, json_data: dict): with open(path + '/' + file_name + '_div.json', 'w') as f: json.dump(json_data, f) + + +def plot_map(divided_map): + tiles = [gpd.GeoDataFrame(geometry=[tile]) for tile in divided_map] + + print("Plotting... This may take some time...") + # NB test plot + fig, ax = plt.subplots() + ax.set_aspect(1.5) + + # Plot each tile + for tile in tiles: # NB temporarily limited to 5 tiles + random_color = "#{:06x}".format(random.randint(0, 0xFFFFFF)) + gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none') + + plt.show() diff --git a/server/map_handler/process_lake.py b/server/map_handler/get_lake.py similarity index 100% rename from server/map_handler/process_lake.py rename to server/map_handler/get_lake.py diff --git a/server/map_handler/get_measurements.py b/server/map_handler/get_measurements.py index a066d307..25b2b635 100644 --- a/server/map_handler/get_measurements.py +++ b/server/map_handler/get_measurements.py @@ -1,6 +1,6 @@ import json -from datetime import datetime import random +from datetime import datetime # get_markers requests all marker data or valid markers, converts the data to json, and writes -- GitLab