diff --git a/server/APIs/__pycache__/get_weather.cpython-39.pyc b/server/APIs/__pycache__/get_weather.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f8858872de717cd7d93b420283a1654752615aec Binary files /dev/null and b/server/APIs/__pycache__/get_weather.cpython-39.pyc differ diff --git a/server/__pycache__/consts.cpython-39.pyc b/server/__pycache__/consts.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ff162bfb6d8c2b2d4564d94fc8fb72b874a69df4 Binary files /dev/null and b/server/__pycache__/consts.cpython-39.pyc differ diff --git a/server/data_processing/__pycache__/process_lidar_data.cpython-39.pyc b/server/data_processing/__pycache__/process_lidar_data.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ed6b00f7f03e667fd4b21e59cb7f512854ed06c6 Binary files /dev/null and b/server/data_processing/__pycache__/process_lidar_data.cpython-39.pyc differ diff --git a/server/data_processing/process_lidar_data.py b/server/data_processing/process_lidar_data.py new file mode 100644 index 0000000000000000000000000000000000000000..55d31e2aaf7396d67e064a37484883a3a685a07d --- /dev/null +++ b/server/data_processing/process_lidar_data.py @@ -0,0 +1,80 @@ +import numpy as np +import laspy +from itertools import groupby + +lazData_path = ["server/example_lidar_data/ot_N_000005_1.laz", "server/example_lidar_data/ot_N_000033_1.laz"] + +# Info about data +with laspy.open(lazData_path[0]) as fh: + # Print metadata properties + print("File Version:", fh.header.version) + print("Point Count:", fh.header.point_count) + print("Scale Factors:", fh.header.scale) + print("Offset:", fh.header.offset) + + print('Points from Header:', fh.header.point_count) + las = fh.read() + print(las) + print('Points from data:', len(las.points)) + ground_pts = las.classification == 2 + bins, counts = np.unique(las.return_number[ground_pts], return_counts=True) + print('Ground Point Return Number distribution:') + for r, c in zip(bins, counts): + print(' {}:{}'.format(r, c)) + +def inArea(position, areaRange): + x, y, _ = position + if (areaRange[0][0] < x < areaRange[1][0]) and (areaRange[0][1] > y > areaRange[1][1]): + return True + else: + return False + +# Calculation of height gotten from las files +def find_height(points): + sorted_coords = sorted(points, key=lambda coord: (coord[0],coord[1])) + + groupCoords = [list(group) for key, group in groupby(sorted_coords, key=lambda coord: (coord[0], coord[1]))] + + height_differences = [] + groupss = [] + + for groups in groupCoords: + if len(groups) < 2 or groups[0] == groups[1]: + continue + + min_height = min(coords[2] for coords in groups) + max_height = max(coords[2] for coords in groups) + + difference = max_height - min_height + height_differences.append(difference) + groupss.append(groups) + + return height_differences + +# areas +def height_in_area(area): + # Limit the data to specific areas + + # this is only temporary data for coordinates in arctic + # areas = [ + # [(-3671212, 7898422), (-3200175, 4699978)], + # [(60.815356, 10.672022), (60.774878, 10.768867)], + # ] + + # NB: is only for the test data should be removed after + areazone = [(((area[0]) * ((-3671212/60.815356) - (-3200175/60.774878))) - 3200175, (area[1] * ((7898422/10.768867) - (4699978/10.672022))) + 4699978), + (((area[0] - 100) * ((-3671212/60.815356) - (-3200175/60.774878))) - 3200175, ((area[1] - 1) * ((7898422/10.768867) - (4699978/10.672022))) + 4699978)] + + # Refactor data format + iceOver = laspy.read(lazData_path[0]) + iceUnder = laspy.read(lazData_path[1]) + + ice_points = list(zip(iceOver.X,iceOver.Y,iceOver.Z)) + list(zip(iceUnder.X,iceUnder.Y,iceUnder.Z)) + + area_heights = [] + + ice_points = list(filter(lambda position: inArea(position, areazone), ice_points)) + + area_heights = find_height(ice_points) + + return area_heights diff --git a/server/example_lidar_data/ot_N_000005_1.laz b/server/example_lidar_data/ot_N_000005_1.laz new file mode 100644 index 0000000000000000000000000000000000000000..38130cafc8020da6c45bc39d931428b0443475f9 Binary files /dev/null and b/server/example_lidar_data/ot_N_000005_1.laz differ diff --git a/server/example_lidar_data/ot_N_000033_1.laz b/server/example_lidar_data/ot_N_000033_1.laz new file mode 100644 index 0000000000000000000000000000000000000000..b6c8ed693e0926851192979f7739e1591e0102c1 Binary files /dev/null and b/server/example_lidar_data/ot_N_000033_1.laz differ diff --git a/server/main.py b/server/main.py index e81df05111821fd5ba96e99bb6b99c5d7c4f052b..90c4048f8c59ea441269c4301db6572ff0f6d90d 100644 --- a/server/main.py +++ b/server/main.py @@ -2,13 +2,11 @@ from flask import Flask from http.server import HTTPServer, BaseHTTPRequestHandler from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT from map.get_markers import get_all_markers -from map.get_relation import get_relation from APIs.get_weather import get_weather import ssl import keyboard import sqlite3 - app = Flask(__name__) terminate_server = 0 @@ -50,6 +48,8 @@ class IceHTTP(BaseHTTPRequestHandler): if self.path == '/get_weather_data': get_weather(self) + elif self.path == '/new_lidar_data': + input_new_Lidar_data(self,self.cursor, 1, 'Mjosa') # hardcoded body of water must change later # Terminate server on key press q def on_key_press(server, event, cursor, conn): @@ -64,7 +64,6 @@ def on_key_press(server, event, cursor, conn): # Start a server on port 8443 using self defined HTTP class if __name__ == "__main__": - try: # Initialize database connection conn = sqlite3.connect('server/sql_db/icedb') diff --git a/server/map/__pycache__/get_markers.cpython-39.pyc b/server/map/__pycache__/get_markers.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cc7f240b40c18edd6be1771b577755de32cccab0 Binary files /dev/null and b/server/map/__pycache__/get_markers.cpython-39.pyc differ diff --git a/server/map/__pycache__/input_new_data.cpython-39.pyc b/server/map/__pycache__/input_new_data.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..673649fd0412e6fd0fa2c004c01e4a38123e7fda Binary files /dev/null and b/server/map/__pycache__/input_new_data.cpython-39.pyc differ diff --git a/server/map/input_new_data.py b/server/map/input_new_data.py new file mode 100644 index 0000000000000000000000000000000000000000..ae0965bb208d57055e4aa42e64f05877b12baf04 --- /dev/null +++ b/server/map/input_new_data.py @@ -0,0 +1,52 @@ +import json +from datetime import datetime +from server.data_processing.process_lidar_data import height_in_area + +def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): + try: + + cursor.execute(''' + INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName, WholeAverageThickness) VALUES + (?,?,?,?); + ''', ( sensorId, datetime.utcnow().replace(microsecond=0), bodyOfWater,0)) + + # auto generate new measurement id + measurement_id = cursor.lastrowid + + cursor.execute(''' + UPDATE Measurement + SET measurementID = ? + WHERE MeasurementID IS NULL; + ''', (int(measurement_id),)) + + cursor.execute(''' + SELECT CenterLatitude, CenterLongitude, SubDivisionID, GroupID + FROM SubDivision + GROUP BY CenterLatitude, CenterLongitude + ''') + position_data = cursor.fetchall() + + if(position_data): + for row in position_data: + latitude, longitude, subID, groupID = row + heights = height_in_area((latitude,longitude)) + if(len(heights) > 0): + print(heights) + else: + print("No height found") + average = sum(heights)/len(heights) + cursor.execute(''' + INSERT INTO SubDivision(MeasurementID, SubDivisionID, GroupID, MinimumThickness, AverageThickness, CenterLatitude, CenterLongitude, Accuracy) VALUES + (?,?,?,?,?,?,?,?); + ''',(measurement_id, subID, groupID, float(min(heights)), float(average), float(latitude), float(longitude), float(1))) + else: + print('No data') + + cursor.connection.commit() + + print("suc_ceed") + + except Exception as e: + print("An error occurred", e) + # rollback in case of error + cursor.connection.rollback() \ No newline at end of file diff --git a/server/sql_db/schema.sql b/server/sql_db/schema.sql index ebc8dbaef7caa70b15387c2c7ca0c1a200ac6a0f..39daec0a0002413b7d803c955940c220818d9220 100644 --- a/server/sql_db/schema.sql +++ b/server/sql_db/schema.sql @@ -63,6 +63,3 @@ INSERT INTO SubDivision (MeasurementID, SubDivisionID, GroupID, MinimumThickness (2, 2, 2, 3.5, 5.0, 60.749, 10.783, 1.4), (3, 1, 1, 4.1, 5.7, 60.768, 10.845, 1.3), (3, 2, 2, 3.5, 5.0, 60.749, 10.783, 1.4); - - -