Skip to content
Snippets Groups Projects
Commit 047d6be8 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

Merge branch 'main' of gitlab.stud.idi.ntnu.no:sarasdj/prog2900 into clhp_map

parents 177e2f25 b0f3cebd
No related branches found
No related tags found
1 merge request!16Clhp map into main
import json import json
import math import math
import os
import laspy import laspy
import numpy as np import numpy as np
...@@ -7,12 +8,10 @@ import numpy as np ...@@ -7,12 +8,10 @@ import numpy as np
from server.data_processing.area_processing import calculate_corners, define_gridareas, inArea, find_height, \ from server.data_processing.area_processing import calculate_corners, define_gridareas, inArea, find_height, \
closest_points, position_relative_to_pointcloud, define_grid_lidardata closest_points, position_relative_to_pointcloud, define_grid_lidardata
# hard coded files for test datas
lazData_path = ["server/example_lidar_data/ot_N_000005_1.laz", "server/example_lidar_data/ot_N_000033_1.laz"]
# Info about data # Info about data
def about_laz_file(): def about_laz_file(path):
with laspy.open(lazData_path[0]) as fh: with laspy.open(path) as fh:
# Print metadata properties # Print metadata properties
print("File Version:", fh.header.version) print("File Version:", fh.header.version)
print("Point Count:", fh.header.point_count) print("Point Count:", fh.header.point_count)
...@@ -30,9 +29,22 @@ def about_laz_file(): ...@@ -30,9 +29,22 @@ def about_laz_file():
return [las.header.version, las.header.point_count, las.header.scale, las.header.offset] return [las.header.version, las.header.point_count, las.header.scale, las.header.offset]
def find_folder_files(direcory):
files = []
for root, _, fileNames in os.walk(direcory):
for fileName in fileNames:
files.append(os.path.join(root, fileName))
return files
print(find_folder_files())
# find the height of an area based on the coordinates of it's center # find the height of an area based on the coordinates of it's center
# and it's affiliations (subId and groupId) (soon to be implemented # and it's affiliations (subId and groupId) (soon to be implemented
def calculate_area_data(center, body_of_water): def calculate_area_data(center, body_of_water):
# test dataset
laz_root_path = "server\\lidar_data\\" + body_of_water
laz_data_paths = find_folder_files(laz_root_path)
# container for all the heights in area # container for all the heights in area
area_heights = [] area_heights = []
...@@ -67,8 +79,8 @@ def calculate_area_data(center, body_of_water): ...@@ -67,8 +79,8 @@ def calculate_area_data(center, body_of_water):
map_data = list(filter(lambda point_position: inArea((point_position['properties']['sub_div_center'][0], point_position['properties']['sub_div_center'][1], 0.0), map_zones), map_data)) map_data = list(filter(lambda point_position: inArea((point_position['properties']['sub_div_center'][0], point_position['properties']['sub_div_center'][1], 0.0), map_zones), map_data))
# Refactor lidar data to a readable format # Refactor lidar data to a readable format
iceOver = laspy.read(lazData_path[0]) iceOver = laspy.read(laz_data_paths[0])
iceUnder = laspy.read(lazData_path[1]) iceUnder = laspy.read(laz_data_paths[1])
# add two files together temporary test data(soon to be removed) # add two files together temporary test data(soon to be removed)
ice_points = list(zip(iceOver.X,iceOver.Y,iceOver.Z)) + list(zip(iceUnder.X,iceUnder.Y,iceUnder.Z)) ice_points = list(zip(iceOver.X,iceOver.Y,iceOver.Z)) + list(zip(iceUnder.X,iceUnder.Y,iceUnder.Z))
......
...@@ -119,8 +119,17 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -119,8 +119,17 @@ class IceHTTP(BaseHTTPRequestHandler):
def do_POST(self): def do_POST(self):
if self.path == '/new_lidar_data': if self.path == '/new_lidar_data':
input_new_Lidar_data(self, self.cursor, 1, 'mj\u00f8sa') # hardcoded body of water must change later parsed_path = urlparse(self.path)
query_params = parse_qs(parsed_path.query)
lake_name_param = query_params.get('lake', [''])[0]
lake_name = unquote(lake_name_param) # Decode url param
if lake_name_param:
input_new_Lidar_data(self, self.cursor, 1, lake_name) # hardcoded body of water must change later
else:
self.send_response(400)
self.send_header('Content-type', 'application/json')
self.end_headers()
# Start a server on port 8443 using self defined HTTP class # Start a server on port 8443 using self defined HTTP class
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -5,6 +5,14 @@ from server.data_processing.process_lidar_data import calculate_area_data, about ...@@ -5,6 +5,14 @@ from server.data_processing.process_lidar_data import calculate_area_data, about
# input_new_Lidar_data send new data gathered from the lidar and send it to the database (from the drone, most likely) # input_new_Lidar_data send new data gathered from the lidar and send it to the database (from the drone, most likely)
def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
"""
:param self:
:param cursor:
:param sensorId:
:param bodyOfWater:
:return:
"""
try: try:
print("name=",bodyOfWater) print("name=",bodyOfWater)
# hard coded coordinates # hard coded coordinates
...@@ -12,15 +20,18 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): ...@@ -12,15 +20,18 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
longitude = 10.723823 longitude = 10.723823
# data about the file read from # data about the file read from
about_laz = about_laz_file() # about_laz = about_laz_file() cannot do this if data is changed
scale_factor = max(about_laz[2]) # scale_factor = max(about_laz[2])
scale_factor = max([0.01])
time_now = datetime.now().utcnow().replace(microsecond=0)
# create a new measurement with the time the data is sent, sensor type, where # create a new measurement with the time the data is sent, sensor type, where
# and an estimate of average thickness of ice on water body # and an estimate of average thickness of ice on water body
cursor.execute(''' cursor.execute('''
INSERT INTO Measurement(MeasurementID, SensorID, TimeMeasured, WaterBodyName, CenterLat, CenterLon) VALUES INSERT INTO Measurement(MeasurementID, SensorID, TimeMeasured, WaterBodyName, CenterLat, CenterLon) VALUES
(?,?,?,?,?,?); (?,?,?,?,?,?);
''', (1, sensorId, datetime.utcnow().replace(microsecond=0), bodyOfWater, latitude, longitude)) ''', (1, sensorId, time_now, bodyOfWater, latitude, longitude))
# auto generate new measurement id # auto generate new measurement id
measurement_id = cursor.lastrowid measurement_id = cursor.lastrowid
...@@ -29,6 +40,19 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): ...@@ -29,6 +40,19 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
areas_data = calculate_area_data((latitude, longitude), bodyOfWater) areas_data = calculate_area_data((latitude, longitude), bodyOfWater)
lidar_json_data = [] lidar_json_data = []
subdiv_json_data = []
measurement_data = {
'measurement_id': measurement_id,
'TimeMeasured': time_now,
'CenterLat': latitude,
'CenterLon': longitude,
'Sensor': {
'SensorId': 2,
'SensorType': "LiDar",
"Active": True,
}
}
if(areas_data): if(areas_data):
# store lidar data in jason formate # store lidar data in jason formate
...@@ -55,23 +79,25 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): ...@@ -55,23 +79,25 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
sub_center = (map_lat, map_lng) sub_center = (map_lat, map_lng)
# set up json formate # set up json formate
lidar_read = { lidar_read = {
'MeasurementId': str(measurement_id), 'SubdivId': subId,
'SubId': str(subId), 'MinThickness': minimum_thickness,
'SubCenter': str(sub_center), 'AvgThickness': average,
'Heights': str(heights) 'CenLatitude': sub_center[0],
'CenLongitude': sub_center[1],
'Accuracy': scale_factor,
} }
lidar_json_data.append(lidar_read) subdiv_json_data.append(lidar_read)
# input the newly generated measurement_id and whole average thickness
cursor.execute('''
UPDATE Measurement
SET measurementID = ?
WHERE MeasurementID IS NULL;
''', (int(measurement_id),))
else: else:
print('No data found, line 79') print('No data found, line 79')
measurement_json_data = {
'Measurement': measurement_data,
'Subdivisions': subdiv_json_data,
}
lidar_json_data.append(measurement_json_data)
# send the changes to the database # send the changes to the database
cursor.connection.commit() cursor.connection.commit()
......
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