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
zcmZuyO-vg{6rR}~8yg$k25hT!l~URsOa-J=3D6=W1X9(OA~i`PLEKu4XKYODU2A6@
zinEq{$N?ftMZM6YPqY=69D6J`j%&0MXr)S#s#eX-6|IDF>YFwG3wgWycE0z%dHZJe
zz1^P%2Ko`mT{)coTSn*)0a_wm4$j|%!9Jph;v8B-RC<ioFqJ_|6yHH{@>~#CQZ2qf
zU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ty~3=UY3uDwJ-A^9H!Syrx)syCC>VvJKZk5kT-L>3!R;nD
z(O-~0Dhy&dFMM-(jTUokUVjguC?kFg6vV;!3<WCg(eU--4;rYg-U{Go16@^a-2VZO
C{)$%s

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