From 37b5fb5b4bbfb7a029d9725ad06930859f1f6f53 Mon Sep 17 00:00:00 2001
From: Hoa Ben The Nguyen <hbnguye@stud.ntnu.no>
Date: Fri, 22 Mar 2024 15:06:54 +0100
Subject: [PATCH] change: format the new data to meter instead of offset of
 offset

---
 server/data_processing/process_lidar_data.py | 12 ++++++++----
 server/map/input_new_data.py                 |  6 +++---
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/server/data_processing/process_lidar_data.py b/server/data_processing/process_lidar_data.py
index cb09c886..540691d4 100644
--- a/server/data_processing/process_lidar_data.py
+++ b/server/data_processing/process_lidar_data.py
@@ -32,7 +32,7 @@ def about_laz_file():
 
 # check if lidar points is within range of the area selected
 def inArea(position, areaRange):
-    y, x, _ = position
+    y, x, _ = position # position to be checked
     if (abs(areaRange[0][0]) > x > abs(areaRange[1][0])) and (abs(areaRange[0][1]) > abs(y) > abs(areaRange[1][1])):
         return True
     else:
@@ -46,14 +46,14 @@ def distance(point1, point2):
 
 # find the closest point in json list
 def closest_points(point, list, coords_taken):
-    closest_point = None
+    closest_point_found = None
     closest_dist = float('inf')
     for current_point in list:
         dist = distance(point, current_point['properties']['sub_div_center'][0])
         if dist < closest_dist and current_point not in coords_taken:
             closest_dist = dist
-            closest_point = current_point
-    return closest_point
+            closest_point_found = current_point
+    return closest_point_found
 
 # Calculation of height in an area from las files
 def find_height(points):
@@ -98,10 +98,14 @@ def calculate_area_data(center, body_of_water):
 
     # grid cell offset
     cell_x, cell_y = map_data['tile_width'], map_data['tile_height']
+    # convert the offset to meter
+    cell_x = 111.320 * cell_x
+    cell_y = 111.320 * math.cos(60) * cell_y
 
     # set the limit of the area compared to local coordinates
     area_limit = calculate_corners(center[0], center[1], (cell_x, cell_y))
 
+    # grid data
     map_data = map_data['features']
 
     print(map_data[0]['properties']['sub_div_center'])
diff --git a/server/map/input_new_data.py b/server/map/input_new_data.py
index 36af3b4e..849a75b2 100644
--- a/server/map/input_new_data.py
+++ b/server/map/input_new_data.py
@@ -39,9 +39,9 @@ def input_new_Lidar_data(self, cursor, bodyOfWater):
                 # lng and lat relative to map
                 map_lat, map_lng = area[2]
 
-                if(len(area[2]) != 0):
-                    average = sum(area[2])/len(area[2])
-                    minimum_thickness = min(area[2])
+                if(len(area[3]) != 0):
+                    average = sum(area[3])/len(area[3])
+                    minimum_thickness = min(area[3])
                 else:
                     average = 0
                     minimum_thickness = 0
-- 
GitLab