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

Merge branch 'lidar_test' of gitlab.stud.idi.ntnu.no:sarasdj/prog2900

parents 52d3d018 84a3ce4f
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
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
File added
File added
......@@ -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')
......
File added
File added
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
......@@ -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);
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