diff --git a/server/data_processing/area_processing.py b/server/data_processing/area_processing.py index 81446eda9a0e8829cb02e33a87476e9bb51ae3d5..ada5e41f9b49028a38196f4aa7b98250e31c2bad 100644 --- a/server/data_processing/area_processing.py +++ b/server/data_processing/area_processing.py @@ -1,8 +1,4 @@ from math import pi, cos -import pandas as pd -import numpy as np -import matplotlib.pyplot as plt -import seaborn as sns EARTH = 6378.137 # Radius of the earth in kilometer METER = (1 / ((2 * pi / 360) * EARTH)) / 1000 # 1 meter in degree @@ -28,17 +24,11 @@ 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)]''' # separate the zones into smaller area, into a grid def define_gridareas(lat, lng, area_offset, grid_size): - #a = dimension + subId + groupId soon to be implemented - #print(a) - grided_area = [] # container for an area turned into a grid of areas - #points = [] + # container for an area turned into a grid of areas + grided_area = [] # find the main area's corner positions main_area = calculate_corners(lat, lng, area_offset) @@ -71,18 +61,6 @@ def define_gridareas(lat, lng, area_offset, grid_size): # use the center of sub areas to find the corner of each subarea corners = calculate_corners(lat_pos, lng_pos, subarea_offset) grided_area.append((sub_id, group_id + i%2, corners)) - #points.append(corners[0]) - #points.append(corners[1]) - #points.append(corners[2]) - #points.append(corners[0]) - - #lng = [-point[0] for point in points] - #lat = [point[1] for point in points] - #plt.figure() - #plt.scatter(lng, lat, marker='D') - #plt.xlabel("Longitude") - #plt.ylabel("Latitude") - #plt.show() return grided_area diff --git a/server/data_processing/process_lidar_data.py b/server/data_processing/process_lidar_data.py index 43209e790f54433400d02ae8656e02a30f2d35d1..46162b5a0db5bc9543e95b9332031865ad49a5f0 100644 --- a/server/data_processing/process_lidar_data.py +++ b/server/data_processing/process_lidar_data.py @@ -30,8 +30,6 @@ with laspy.open(lazData_path[0]) as fh: def inArea(position, areaRange): x, y, _ = position if (areaRange[0][0] > x > areaRange[1][0]) and (areaRange[0][1] < y < areaRange[1][1]): - #print(areaRange[0][0]," > ",x," > ",areaRange[1][0],") and (",areaRange[0][1]," < ",y," < ",areaRange[1][1]) - #print("inside area", position) return True else: return False @@ -59,7 +57,7 @@ def find_height(points): difference = max_height - min_height height_differences.append(difference) - # list of thickness in a area + # list of thickness in an area return height_differences # find the height of an area based on the coordinates of it's center @@ -68,49 +66,8 @@ def calculate_area_data(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)], - # ] - - # specified the area and it's range - #area = (area[0], area[2]) - #print("area size") - # NB: is only for the test data (soon to be removed and switched with center) - #areazone = ((((7898422) - (4699978)))/2.0 + 4699978), (((-3671212) - (-3200175)))/2.0 - 3200175 - #areazone = ((-3671212 - (-3200175))/center[0] - 3200175, (7898422 - 4699978)/center[1] + 4699978) - - #print(areazone) - - - # max and min initial (-9.790000, -615.719971) - (696.619995, 96.660004) - # max and min g(idk) (-36709.790000, 78284.280029) - (-36003.380005,78996.660004) - # should be within (-3200175, 4699978) - (-3671212, 7898422) - #print(utm.to_latlon(4699978, -3200175,18,'S')) - - - #areazone = ((((-3200175 + 3671212) / ( area[0][0] - area[2][0]))), - # ((7898422 - 4699978) / (area[0][1] - area[2][1]))) - #areazone = ((((-3200175 / area[0][0]) - ( - 3671212 / area[2][0]))), - # ((7898422 / area[0][1]) - (area[2][1] / 4699978))) - - area = calculate_corners(center[0],center[1], 1500) - print("area", area) - - #areazone = calculate_corners(3496480.06669129,7681517.961979784, 400000) - #print(area[0]," area ", area[2]) - - #start_point = areazone[0] - #areazone = (areazone[2][0] - areazone[0][0], areazone[2][1] - areazone[0][1]) - #print("az",areazone) - - # areazone = [(((center[0]) * ((-3671212 / 60.815356) - (-3200175 / 60.774878))) - 3200175, - # (center[1] * ((7898422 / 10.768867) - (4699978 / 10.672022))) + 4699978), - # (((center[0] - 100) * ((-3671212 / 60.815356) - (-3200175 / 60.774878))) - 3200175, - # ((center[1] - 1) * ((7898422 / 10.768867) - (4699978 / 10.672022))) + 4699978)] + # set the limit of the area compared to local coordinates + area_limit = calculate_corners(center[0],center[1], 1500) # Refactor lidar data to a readable format iceOver = laspy.read(lazData_path[0]) @@ -120,9 +77,8 @@ def calculate_area_data(center): ice_points = list(zip(iceOver.X,iceOver.Y,iceOver.Z)) + list(zip(iceUnder.X,iceUnder.Y,iceUnder.Z)) max_point = max(ice_points) min_point = min(ice_points) - # area height in all the subsections - #grid_area_heights = define_gridareas(-3435693.5,6299200.0, 20000000000,4) - #grid_area_heights = define_gridareas(3496480.06669129,7681517.961979784, 400000,4) + + # define all the sub-areas within the area, local coordinates grid_area_heights = define_gridareas(60,10, 1500,4) # find the heights of each sub-area => area-heights @@ -131,46 +87,17 @@ def calculate_area_data(center): end = max(sub_area[2]) #test data - areazone = [(((min_point[0] - max_point[0]) * ((start[0]-center[0])/(area[1][0]-area[3][0]))) + (min_point[0] - max_point[0])/2 + max_point[0], - (((min_point[1] - max_point[1]) * ((start[1]-center[1])/(area[1][1]-area[3][1]))) + (min_point[1] - max_point[1])/2 + min_point[1])), - ((((min_point[0] - max_point[0]) * ((end[0]-center[0])/(area[1][0]-area[3][0]))) + (min_point[0] - max_point[0])/2 + max_point[0], - (((min_point[1] - max_point[1]) * ((end[1]-center[1])/(area[1][1]-area[3][1])))) + (min_point[1] - max_point[1])/2 + min_point[1]))] - #print("areazone", areazone) + # zone coordinates sett to be relative to the lidar data + areazone = [(((min_point[0] - max_point[0]) * ((start[0]-center[0])/(area_limit[1][0]-area_limit[3][0]))) + (min_point[0] - max_point[0])/2 + max_point[0], + (((min_point[1] - max_point[1]) * ((start[1]-center[1])/(area_limit[1][1]-area_limit[3][1]))) + (min_point[1] - max_point[1])/2 + min_point[1])), + ((((min_point[0] - max_point[0]) * ((end[0]-center[0])/(area_limit[1][0]-area_limit[3][0]))) + (min_point[0] - max_point[0])/2 + max_point[0], + (((min_point[1] - max_point[1]) * ((end[1]-center[1])/(area_limit[1][1]-area_limit[3][1])))) + (min_point[1] - max_point[1])/2 + min_point[1]))] + # filter data within sub-area zones points_in_area = list(filter(lambda point_position: inArea(point_position, areazone), ice_points)) area_heights.append((sub_area[0],sub_area[1],find_height(points_in_area))) - #main_vector = tuple(x - y for x, y in zip(area[2], area[0])) - #sub_vector = tuple(x - y for x, y in zip(sub_area[2][2], sub_area[2][0])) - #relative_to_laz = (tuple(x - y for x, y in zip(sub_area[2][0], area[0])), - # tuple(x + y for x, y in zip(sub_vector, sub_area[2][0]))) - #relative_to_laz = (tuple(x / y for x, y in zip(relative_to_laz[0], main_vector)), - # tuple(x / y for x, y in zip(relative_to_laz[1], sub_area[2][0]))) - #relative_to_laz = (tuple(x * y for x, y in zip(relative_to_laz[0], areazone)), - # tuple(x * y for x, y in zip(relative_to_laz[1], areazone))) - #relative_to_laz = (tuple(x + y for x, y in zip(relative_to_laz[0], start_point)), - # tuple(x + y for x, y in zip(relative_to_laz[1], start_point))) - - #print("areaZone",areazone) - #print("sub area",sub_area) - #print("relativer",relative_to_laz) - - #zone_limit = (tuple(x * y for x, y in zip(relative_to_laz, areazone)), - # tuple(x * y for x, y in zip(sub_area[2][2], areazone))) - #print("zone_limit",zone_limit) - #zone_limit = (tuple(x + y for x, y in zip(zone_limit[0], start_point)), - # tuple(x + y for x, y in zip(zone_limit[1], start_point))) - - #print("zone_limit",zone_limit) - #ice_points = list(filter(lambda point_position: inArea((float(point_position[0]),float(point_position[1]),(float(point_position[2]))), (((-sub_area[2][0][0]), (sub_area[2][0][1])), ((-sub_area[2][2][0]), (sub_area[2][2][1])))), ice_points)) - #ice_points = list(filter(lambda point_position: inArea(point_position, (((-areazone[0][0]),areazone[0][1]),(-areazone[2][0],areazone[2][1]))), ice_points)) - #ice_points = list(filter(lambda point_position: inArea(point_position, (((-3200000,7400000),(-3671212,7898422)))), ice_points)) - - #print("ice",ice_points) - #area_heights.append((sub_area[0],sub_area[1],find_height(ice_points))) - return area_heights -#print(calculate_area_data((60.0,10.0))) diff --git a/server/map/input_new_data.py b/server/map/input_new_data.py index 600cd974cfc058863b1f418d7f12c3346f32c8b6..603a7a5a209dab0b4e2827d73cceeb4eaeeb03b5 100644 --- a/server/map/input_new_data.py +++ b/server/map/input_new_data.py @@ -22,23 +22,12 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): # auto generate new measurement id measurement_id = cursor.lastrowid - - # supposed get all the hardcode the coordinates of the areas we want - # cursor.execute(''' - # SELECT CenterLatitude, CenterLongitude, SubDivisionID, GroupID - # FROM SubDivision - # GROUP BY CenterLatitude, CenterLongitude - # ''') - # position_data = cursor.fetchall() + # calculate the area of to be calculated based on the coordinates given to the calculation model + areas_data = calculate_area_data((latitude, longitude)) - # soon to be removed - print("uwu") - areas_data = calculate_area_data((latitude, longitude)) - print("area") - print(areas_data) if(areas_data): - print("areas data",areas_data) + # calculate data for each zone within the area for area in areas_data: if(len(area[2]) != 0): average = sum(area[2])/len(area[2]) @@ -46,7 +35,10 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): else: average = 0 minimum_thickness = 0 + total_measurement_average += average + + # input the data into the database cursor.execute(''' INSERT INTO SubDivision(MeasurementID, SubDivisionID, GroupID, MinimumThickness, AverageThickness, CenterLatitude, CenterLongitude, Accuracy) VALUES (?,?,?,?,?,?,?,?); @@ -54,8 +46,7 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): total_measurement_average = total_measurement_average / len(areas_data) - print("meas id ", measurement_id) - # input the newly generated measurement_id and whole average thickness (soon to be implemented) + # input the newly generated measurement_id and whole average thickness cursor.execute(''' UPDATE Measurement SET measurementID = ?, WholeAverageThickness = ? @@ -67,7 +58,8 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): # send the changes to the database cursor.connection.commit() - print("suc_ceed") + # Send response + self.send_response(200) # error handling except Exception as e: