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

change: made area_processing functions more addaptable to different offset from different lakes

parent a323d232
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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'))
......@@ -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 = []
......
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