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

change: processing and setting of measurement calculation

parent 120b01a3
No related branches found
No related tags found
No related merge requests found
......@@ -24,28 +24,37 @@ def calculate_corners(lat, lng, area_offset):
(lat_pos, lng_neg), # bottom right
(lat_neg, lng_neg) # bottom left
]
'''return [(60.7798, 10.7062), # NB: temporary hardcoded values
(60.7553, 10.7433),
(60.7718, 10.7975),
(60.7966, 10.7405)]'''
def define_gridareas(lat, lng, area_offset, grid_size):
return_value = []
'''return [(60.7798, 10.7062), # NB: temporary hardcoded values
(60.7553, 10.7433),
(60.7718, 10.7975),
(60.7966, 10.7405)]'''
# separate the zones into smaller area, into a grid
def define_gridareas(lat, lng, area_offset, grid_size, dimension, subId, groupId):
a = dimension + subId + groupId # soon to be implemented
print(a)
grided_area = [] # container for an area turned into a grid of areas
# find the main area's corner positions
main_area = calculate_corners(lat, lng, area_offset)
# find the main area's range size
area_size = (main_area[0][0] - main_area[2][0], main_area[0][1] - main_area[2][1])
# find each subareas vector to it's center
dist_to_subcenter = (area_size[0]/(grid_size*2), area_size[1]/(grid_size*2))
# find subareas size relative to main area
subarea_offset = area_offset/grid_size
print(area_size)
print(dist_to_subcenter)
# find the center coordinates of each area in grid to find the corner areas
for y in range(grid_size-1):
relative_size_lng = y / grid_size
for x in range(grid_size-1):
relative_size_lat = x / grid_size
lat_pos = main_area[0][0] + relative_size_lat * area_size[0] - dist_to_subcenter[0]
lng_pos = main_area[0][1] + relative_size_lng * area_size[1] - dist_to_subcenter[1]
return_value.append(calculate_corners(lat_pos, lng_pos,subarea_offset))
# use the center of sub areas to find the corner of each subarea
grided_area.append(calculate_corners(lat_pos, lng_pos,subarea_offset))
return return_value
return grided_area
print(calculate_corners(60,10,1500))
print(define_gridareas(60,10,1500,4))
\ No newline at end of file
#print(calculate_corners(60,10,1500))
#print(define_gridareas(60,10,1500,4))
\ No newline at end of file
import numpy as np
import laspy
from itertools import groupby
from process_lidar_data import calculate_corners, define_gridareas
# hard coded files for test data
lazData_path = ["server/example_lidar_data/ot_N_000005_1.laz", "server/example_lidar_data/ot_N_000033_1.laz"]
# Info about data
......@@ -22,6 +24,7 @@ with laspy.open(lazData_path[0]) as fh:
for r, c in zip(bins, counts):
print(' {}:{}'.format(r, c))
# check if lidar points is within range of the area selected
def inArea(position, areaRange):
x, y, _ = position
if (areaRange[0][0] < x < areaRange[1][0]) and (areaRange[0][1] > y > areaRange[1][1]):
......@@ -29,52 +32,66 @@ def inArea(position, areaRange):
else:
return False
# Calculation of height gotten from las files
# Calculation of height in an area from las files
def find_height(points):
height_differences = [] # final container for height data
# sort the points
sorted_coords = sorted(points, key=lambda coord: (coord[0],coord[1]))
# group the sorted points that has the same xy- coordinates together
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
# loop through the groups to find the difference in height
for group in groupCoords:
if len(group) < 2 or group[0] == group[1]:
continue # jump over iteration if there is only one coordinate or lidar registered the same point twice
min_height = min(coords[2] for coords in groups)
max_height = max(coords[2] for coords in groups)
# find max and min height
min_height = min(coords[2] for coords in group)
max_height = max(coords[2] for coords in group)
# difference between them
difference = max_height - min_height
height_differences.append(difference)
groupss.append(groups)
# list of thickness in a area
return height_differences
# areas
def height_in_area(area):
# 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 height_in_area(center):
# container for all the heights in area
area_heights = []
# 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
# specified the area and it's range
area = calculate_corners(center, 1500)
area = (area[0], area[2])
# NB: is only for the test data (soon to be removed)
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
# Refactor lidar data to a readable format
iceOver = laspy.read(lazData_path[0])
iceUnder = laspy.read(lazData_path[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))
area_heights = []
ice_points = list(filter(lambda position: inArea(position, areazone), ice_points))
# area height in all the subsections
grid_area_heights = define_gridareas(areazone, 1500, 20)
area_heights = find_height(ice_points)
# find the heights of each sub-area => area-heights
for sub_area in grid_area_heights:
ice_points = list(filter(lambda point_position: inArea(point_position, (sub_area[0],sub_area[2])), ice_points))
area_heights.append(find_height(ice_points))
return area_heights
......@@ -2,9 +2,11 @@ import json
from datetime import datetime
from server.data_processing.process_lidar_data import height_in_area
# 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):
try:
# 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( SensorID, TimeMeasured, WaterBodyName, WholeAverageThickness) VALUES
(?,?,?,?);
......@@ -13,12 +15,14 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
# auto generate new measurement id
measurement_id = cursor.lastrowid
# input the newly generated measurement_id and ... average thickness (soon to be implemented)
cursor.execute('''
UPDATE Measurement
SET measurementID = ?
WHERE MeasurementID IS NULL;
''', (int(measurement_id),))
# soon to be removed
cursor.execute('''
SELECT CenterLatitude, CenterLongitude, SubDivisionID, GroupID
FROM SubDivision
......@@ -26,6 +30,7 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
''')
position_data = cursor.fetchall()
# soon to be removed
if(position_data):
for row in position_data:
latitude, longitude, subID, groupID = row
......@@ -42,10 +47,12 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
else:
print('No data')
# send the changes to the database
cursor.connection.commit()
print("suc_ceed")
# error handling
except Exception as e:
print("An error occurred", e)
# rollback in case of error
......
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