From 792d6c3c23030dff9da985937cd555b25837d8d4 Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Thu, 21 Mar 2024 15:06:03 +0100
Subject: [PATCH] update: backtrack

---
 server/main.py                                |   5 ++-
 .../map/__pycache__/add_lake.cpython-311.pyc  | Bin 7007 -> 7007 bytes
 .../get_measurements.cpython-311.pyc          | Bin 4774 -> 4774 bytes
 .../__pycache__/process_lake.cpython-311.pyc  | Bin 0 -> 2163 bytes
 server/map/process_lake.py                    |  42 ++++++++++++++++++
 5 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 server/map/__pycache__/process_lake.cpython-311.pyc
 create mode 100644 server/map/process_lake.py

diff --git a/server/main.py b/server/main.py
index 66166825..cdc9cbd8 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
GIT binary patch
delta 20
bcmca_cHfM9IWI340|NuYKHEPVxkID@L`nuD

delta 20
bcmca_cHfM9IWI340|NuYVVmC@xkID@L}CUe

diff --git a/server/map/__pycache__/get_measurements.cpython-311.pyc b/server/map/__pycache__/get_measurements.cpython-311.pyc
index bbc96f8594f835ec1a5d086589f2e08eceb06fce..368701cd4bb230294da15f554647bff65ca17497 100644
GIT binary patch
delta 20
ccmZ3cx=fXOIWI340|NuYKHEPVxn~Oj06Fyq%>V!Z

delta 20
ccmZ3cx=fXOIWI340|NuYdWqi~xn~Oj063`ym;e9(

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
GIT binary patch
literal 2163
zcmZ3^%ge>Uz`)RK_a{|{m4V?ghy%k+P{!vx1_p-d3@HpLj5!QZj42E$OgT)s%u&p_
zEKw}EtWm6tAUWn7wp{io_FRrAj$F<tPOunb4p%OB6c3cm8^sGYgD;8?O!G(agK2>%
zffSY&hA6=l))s~+p%lho22Hk?Aj|zUnQyTN<mXhT=jYwx^2y9g4K69l%uBz;?^~Kv
zl8F$|WWL3jlbM&An_85fdW*X>FR`dHzBDfrq^$s=KeH+|8RjF9*=!6949pA+44;!2
zLB6YDSO5~mz$uK&7#SE=Gr}Yo8EP07z<DrH5S_x5!n}-$fnhb=7O+}452OZ$moYFf
ztcGzI7#T{~;T(n(mKw$?1_p){RxrtiYNjbeEmIBC0v3dN1Pj&FTILi`yfC2ZXJp9Z
zR%S3{C}t^Vs$h;}C}(73h-6@70J$}b6=v1~Q0TxoaJq(h0g^l6!VD?ws9}W41I2zY
zgC>XH%M%O?3{^bN`FSO&c_q3fl?AC)0*M6$Iho0cC7Jno`dP*KdB4PpQ;W({i}Z66
zvs2@XQggsk#rnTE<5M!r^gv2(F&0&^mX@UHT4-|I;w?_iONlQ^EiTB<D^9(|4d!N~
zCZ?no-QosGLD<E&Sn>-}^KP*er6#7_Vl7Y0%t^h)T3(b{l6s3RH7_|oB~_E<7E5tz
zPTDO_kYs#bVs7d!77+6mOG;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xSTDxWxi4+nDl;
z!9@Z%*j6$WX@TMv6nwupY;yBcN^?@}ip&@o7(khz7*vIPU}j`wyul!T0fufcI9|Yw
zZZKF~z>RJ&$X`H3HyC&u!0-kGcLNwAF*qB*@B;@IqxJ^|I3dH&DDi;-lK^`L0BdFx
A0RR91

literal 0
HcmV?d00001

diff --git a/server/map/process_lake.py b/server/map/process_lake.py
new file mode 100644
index 00000000..b2f7b85c
--- /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
+
-- 
GitLab