From 7aad32021f6b78b5c1c509f90a756a420c7c9a36 Mon Sep 17 00:00:00 2001 From: Hoa Ben The Nguyen <hbnguye@stud.ntnu.no> Date: Fri, 22 Mar 2024 11:15:44 +0100 Subject: [PATCH] change: made area_processing functions more addaptable to different offset from different lakes --- server/data_processing/area_processing.py | 9 ++++--- server/data_processing/process_lidar_data.py | 27 ++++++++------------ server/map/input_new_data.py | 2 +- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/server/data_processing/area_processing.py b/server/data_processing/area_processing.py index 649e18a6..30a56794 100644 --- a/server/data_processing/area_processing.py +++ b/server/data_processing/area_processing.py @@ -12,11 +12,12 @@ def calculate_corners(lat, lng, area_offset): """ # From https://stackoverflow.com/questions/7477003/calculating-new-longitude-latitude-from-old-n-meters # Formulas: - lat_pos = lat + (area_offset * METER) - lng_pos = lng + (area_offset * METER) / cos(lat * (pi / 180)) + offset_lng, offset_lat = area_offset + lat_pos = lat + (offset_lat * METER) + lng_pos = lng + (offset_lng * METER) / cos(lat * (pi / 180)) - lat_neg = lat - (area_offset * METER) - lng_neg = lng - (area_offset * METER) / cos(lat * (pi / 180)) + lat_neg = lat - (offset_lat * METER) + lng_neg = lng - (offset_lng * METER) / cos(lat * (pi / 180)) return [ (lat_neg, lng_pos), # top left diff --git a/server/data_processing/process_lidar_data.py b/server/data_processing/process_lidar_data.py index 51d927cd..cb09c886 100644 --- a/server/data_processing/process_lidar_data.py +++ b/server/data_processing/process_lidar_data.py @@ -42,13 +42,10 @@ def inArea(position, areaRange): def distance(point1, point2): y1, x1 = point1 y2, x2 = point2 - print(y1," 2 ",x1) - print(y2," 3 ",x2) return math.sqrt(abs(y2 - y1)**2 + abs(x2 - x1)**2) # find the closest point in json list def closest_points(point, list, coords_taken): - print(point, " 4 ") closest_point = None closest_dist = float('inf') for current_point in list: @@ -64,7 +61,7 @@ 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])) + 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]))] @@ -87,34 +84,32 @@ def find_height(points): # 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, cell_size, body_of_water): - # map application size to meters - cell_size_to_meters = cell_size * 600000 - +def calculate_area_data(center, body_of_water): # container for all the heights in area area_heights = [] # zone coords taken taken_coords = [] - # set the limit of the area compared to local coordinates - area_limit = calculate_corners(center[0],center[1], cell_size_to_meters) # read json data with path to data for specific water body file_name = "server/lake_relations/" + body_of_water + "_div.json" with open(file_name) as data: map_data = json.load(data) + # grid cell offset + cell_x, cell_y = map_data['tile_width'], map_data['tile_height'] + + # set the limit of the area compared to local coordinates + area_limit = calculate_corners(center[0], center[1], (cell_x, cell_y)) + map_data = map_data['features'] + print(map_data[0]['properties']['sub_div_center']) map_zones = [area_limit[1],area_limit[3]] - print(map_zones) - 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)) - print(len(map_data)) - # Refactor lidar data to a readable format iceOver = laspy.read(lazData_path[0]) iceUnder = laspy.read(lazData_path[1]) @@ -125,7 +120,7 @@ def calculate_area_data(center, cell_size, body_of_water): min_point = min(ice_points) # define all the sub-areas within the area, local coordinates - grid_area_heights = define_gridareas(60,10, 1500,4) + grid_area_heights = define_gridareas(60,10, (cell_x, cell_y),4) # find the heights of each sub-area => area-heights for sub_area in grid_area_heights: @@ -159,5 +154,5 @@ def calculate_area_data(center, cell_size, body_of_water): return area_heights -#print(calculate_area_data((61,11), 0.04,'mjosa')) +print(calculate_area_data((61,11), 0.04,'mjosa')) diff --git a/server/map/input_new_data.py b/server/map/input_new_data.py index 0c5275e4..36af3b4e 100644 --- a/server/map/input_new_data.py +++ b/server/map/input_new_data.py @@ -28,7 +28,7 @@ def input_new_Lidar_data(self, cursor, bodyOfWater): measurement_id = cursor.lastrowid # calculate the area of to be calculated based on the coordinates given to the calculation model - areas_data = calculate_area_data((latitude, longitude), 0.04, bodyOfWater) + areas_data = calculate_area_data((latitude, longitude), bodyOfWater) print(len(areas_data)) lidar_json_data = [] -- GitLab