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

change format of json data

parent 74888a04
No related branches found
No related tags found
No related merge requests found
import json
import math
import os
import laspy
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, \
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
def about_laz_file():
with laspy.open(lazData_path[0]) as fh:
def about_laz_file(path):
with laspy.open(path) as fh:
# Print metadata properties
print("File Version:", fh.header.version)
print("Point Count:", fh.header.point_count)
......@@ -30,9 +29,22 @@ def about_laz_file():
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
# and it's affiliations (subId and groupId) (soon to be implemented
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
area_heights = []
......@@ -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))
# Refactor lidar data to a readable format
iceOver = laspy.read(lazData_path[0])
iceUnder = laspy.read(lazData_path[1])
iceOver = laspy.read(laz_data_paths[0])
iceUnder = laspy.read(laz_data_paths[1])
# 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))
......
......@@ -119,8 +119,17 @@ class IceHTTP(BaseHTTPRequestHandler):
def do_POST(self):
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
if __name__ == "__main__":
......
......@@ -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)
def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
"""
:param self:
:param cursor:
:param sensorId:
:param bodyOfWater:
:return:
"""
try:
print("name=",bodyOfWater)
# hard coded coordinates
......@@ -12,15 +20,18 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
longitude = 10.723823
# data about the file read from
about_laz = about_laz_file()
scale_factor = max(about_laz[2])
# about_laz = about_laz_file() cannot do this if data is changed
# 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
# and an estimate of average thickness of ice on water body
cursor.execute('''
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
measurement_id = cursor.lastrowid
......@@ -29,6 +40,19 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
areas_data = calculate_area_data((latitude, longitude), bodyOfWater)
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):
# store lidar data in jason formate
......@@ -55,23 +79,25 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
sub_center = (map_lat, map_lng)
# set up json formate
lidar_read = {
'MeasurementId': str(measurement_id),
'SubId': str(subId),
'SubCenter': str(sub_center),
'Heights': str(heights)
'SubdivId': subId,
'MinThickness': minimum_thickness,
'AvgThickness': average,
'CenLatitude': sub_center[0],
'CenLongitude': sub_center[1],
'Accuracy': scale_factor,
}
lidar_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),))
subdiv_json_data.append(lidar_read)
else:
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
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