Skip to content
Snippets Groups Projects
Commit ca800a07 authored by Hoa Ben The Nguyen's avatar Hoa Ben The Nguyen
Browse files

add: unfinished, add new data from lidar

parent e39107d9
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
File added
from flask import Flask from flask import Flask
from http.server import HTTPServer, BaseHTTPRequestHandler from http.server import HTTPServer, BaseHTTPRequestHandler
from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT
from map.get_markers import get_all_markers from map.get_markers import get_all_markers, input_new_Lidar_data
from APIs.get_weather import get_weather from APIs.get_weather import get_weather
import ssl import ssl
import keyboard import keyboard
...@@ -45,6 +45,9 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -45,6 +45,9 @@ class IceHTTP(BaseHTTPRequestHandler):
if self.path == '/get_weather_data': if self.path == '/get_weather_data':
get_weather(self) get_weather(self)
elif self.path == '/update_lidar':
input_new_Lidar_data(self,self.cursor, 1, 'Mjøsa')
# Terminate server on key press q # Terminate server on key press q
def on_key_press(server, event, cursor, conn): def on_key_press(server, event, cursor, conn):
if event.name == 'q': if event.name == 'q':
......
File added
import json import json
from datetime import datetime
# get_markers requests all marker data or valid markers, converts the data to json, and writes # get_markers requests all marker data or valid markers, converts the data to json, and writes
# the data to the response object # the data to the response object
...@@ -102,3 +102,38 @@ def get_all_markers(self, cursor, valid: bool): ...@@ -102,3 +102,38 @@ def get_all_markers(self, cursor, valid: bool):
# Write marker data to response object # Write marker data to response object
self.wfile.write(marker_data.encode('utf-8')) self.wfile.write(marker_data.encode('utf-8'))
def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
try:
cursor.execute('''
INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName) VALUES
(?,?,?);
''',( sensorId, datetime.utcnow(), bodyOfWater))
# auto generate new measurement id
measurement_id = cursor.lastrowid
cursor.execute('''
SELECT CornerLatitude, CornerLongitude
FROM Cursor
where MeasurementID = ?;
''')
cursor_data = cursor.fetchall()
if(cursor_data):
for row in cursor_data:
longitude, latitude = row
cursor.execute('''
INSERT INTO Data(MeasurementID, Latitude, Longitude, IceTop, IceBottom, CalculatedThickness) VALUES
(?,?,?,?);
''',(measurementId, ))
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
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))
# Limit the data to specific areas
# should be within this range (10.616913,60.742712) - (10.825653,60.940206)
# this is only temporary data for coordinates in arctic
areas = [
[(-3671212, 7898422), (-3200175, 4699978)],
[(-3671212, 7898422), (-3200175, 4699978)]
]
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 min(height_differences)
print(lazData_path[0])
# 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 = []
# areas
for area in areas:
ice_points = list(filter(lambda position: inArea(position, area), ice_points))
area_heights.append(find_height(ice_points))
print(area_heights)
\ No newline at end of file
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