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

change: working calculation model that sends with sensor and group id, is tested

parent 93a56eb1
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
from math import pi, cos 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 EARTH = 6378.137 # Radius of the earth in kilometer
METER = (1 / ((2 * pi / 360) * EARTH)) / 1000 # 1 meter in degree METER = (1 / ((2 * pi / 360) * EARTH)) / 1000 # 1 meter in degree
...@@ -34,6 +38,7 @@ def define_gridareas(lat, lng, area_offset, grid_size): ...@@ -34,6 +38,7 @@ def define_gridareas(lat, lng, area_offset, grid_size):
#a = dimension + subId + groupId soon to be implemented #a = dimension + subId + groupId soon to be implemented
#print(a) #print(a)
grided_area = [] # container for an area turned into a grid of areas grided_area = [] # container for an area turned into a grid of areas
#points = []
# find the main area's corner positions # find the main area's corner positions
main_area = calculate_corners(lat, lng, area_offset) main_area = calculate_corners(lat, lng, area_offset)
...@@ -47,8 +52,6 @@ def define_gridareas(lat, lng, area_offset, grid_size): ...@@ -47,8 +52,6 @@ def define_gridareas(lat, lng, area_offset, grid_size):
group_id = 0 group_id = 0
i=0 i=0
j=0
# find the center coordinates of each area in grid to find the corner areas # find the center coordinates of each area in grid to find the corner areas
for y in (range(grid_size)): for y in (range(grid_size)):
relative_size_lng = y / grid_size relative_size_lng = y / grid_size
...@@ -68,8 +71,20 @@ def define_gridareas(lat, lng, area_offset, grid_size): ...@@ -68,8 +71,20 @@ def define_gridareas(lat, lng, area_offset, grid_size):
# use the center of sub areas to find the corner of each subarea # use the center of sub areas to find the corner of each subarea
corners = calculate_corners(lat_pos, lng_pos, subarea_offset) corners = calculate_corners(lat_pos, lng_pos, subarea_offset)
grided_area.append((sub_id, group_id + i%2, corners)) 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 return grided_area
#print(define_gridareas(-60,10,1500,4)) #print(define_gridareas(-60,10,10000,4))
print(define_gridareas(3435693.5,6299200.0, 20000000000,4)) #print(define_gridareas(3435693.5,6299200.0, 400000,4))
\ No newline at end of file \ No newline at end of file
...@@ -29,9 +29,9 @@ with laspy.open(lazData_path[0]) as fh: ...@@ -29,9 +29,9 @@ with laspy.open(lazData_path[0]) as fh:
# check if lidar points is within range of the area selected # check if lidar points is within range of the area selected
def inArea(position, areaRange): def inArea(position, areaRange):
x, y, _ = position x, y, _ = position
print(areaRange[0][0], " > ", x, " > ", areaRange[1][0], ") and (", areaRange[0][1], " < ", y, " < ", areaRange[1][1])
if (areaRange[0][0] > x > areaRange[1][0]) and (areaRange[0][1] < y < areaRange[1][1]): if (areaRange[0][0] > x > areaRange[1][0]) and (areaRange[0][1] < y < areaRange[1][1]):
print("inside area") #print(areaRange[0][0]," > ",x," > ",areaRange[1][0],") and (",areaRange[0][1]," < ",y," < ",areaRange[1][1])
#print("inside area", position)
return True return True
else: else:
return False return False
...@@ -97,9 +97,10 @@ def calculate_area_data(center): ...@@ -97,9 +97,10 @@ def calculate_area_data(center):
#areazone = ((((-3200175 / area[0][0]) - ( - 3671212 / area[2][0]))), #areazone = ((((-3200175 / area[0][0]) - ( - 3671212 / area[2][0]))),
# ((7898422 / area[0][1]) - (area[2][1] / 4699978))) # ((7898422 / area[0][1]) - (area[2][1] / 4699978)))
#area = calculate_corners(center[0],center[1], 1500) area = calculate_corners(center[0],center[1], 1500)
print("area", area)
areazone = calculate_corners(3435693.5,7550000.0, 20000000000) #areazone = calculate_corners(3496480.06669129,7681517.961979784, 400000)
#print(area[0]," area ", area[2]) #print(area[0]," area ", area[2])
#start_point = areazone[0] #start_point = areazone[0]
...@@ -117,14 +118,27 @@ def calculate_area_data(center): ...@@ -117,14 +118,27 @@ def calculate_area_data(center):
# add two files together temporary test data(soon to be removed) # 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)) 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 # area height in all the subsections
#grid_area_heights = define_gridareas(-3435693.5,6299200.0, 20000000000,4) #grid_area_heights = define_gridareas(-3435693.5,6299200.0, 20000000000,4)
grid_area_heights = define_gridareas(3435693.5,7550000.0, 20000000000,4) #grid_area_heights = define_gridareas(3496480.06669129,7681517.961979784, 400000,4)
grid_area_heights = define_gridareas(60,10, 1500,4)
print("",grid_area_heights)
# find the heights of each sub-area => area-heights # find the heights of each sub-area => area-heights
for sub_area in grid_area_heights: for sub_area in grid_area_heights:
start = min(sub_area[2])
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)
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])) #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])) #sub_vector = tuple(x - y for x, y in zip(sub_area[2][2], sub_area[2][0]))
...@@ -148,17 +162,15 @@ def calculate_area_data(center): ...@@ -148,17 +162,15 @@ def calculate_area_data(center):
# tuple(x + y for x, y in zip(zone_limit[1], start_point))) # tuple(x + y for x, y in zip(zone_limit[1], start_point)))
#print("zone_limit",zone_limit) #print("zone_limit",zone_limit)
print(type(ice_points[0])) #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, ((int(-sub_area[2][0][0]),int(sub_area[2][0][1])),(int(-sub_area[2][2][0]),int(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, (((-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)) #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("ice",ice_points)
#area_heights.append((sub_area[0],sub_area[1],find_height(ice_points)))
print(-3>-4) return area_heights
print(calculate_area_data((60.0,10.0))) #print(calculate_area_data((60.0,10.0)))
No preview for this file type
...@@ -38,28 +38,31 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): ...@@ -38,28 +38,31 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
print("area") print("area")
print(areas_data) print(areas_data)
if(areas_data): if(areas_data):
print("areas data",areas_data)
for area in areas_data: for area in areas_data:
#if(len(area[2]) != 0): if(len(area[2]) != 0):
average = sum(area[2])/len(area[2]) average = sum(area[2])/len(area[2])
#else: minimum_thickness = min(area[2])
#average = 0 else:
average = 0
minimum_thickness = 0
total_measurement_average += average total_measurement_average += average
cursor.execute(''' cursor.execute('''
INSERT INTO SubDivision(MeasurementID, SubDivisionID, GroupID, MinimumThickness, AverageThickness, CenterLatitude, CenterLongitude, Accuracy) VALUES INSERT INTO SubDivision(MeasurementID, SubDivisionID, GroupID, MinimumThickness, AverageThickness, CenterLatitude, CenterLongitude, Accuracy) VALUES
(?,?,?,?,?,?,?,?); (?,?,?,?,?,?,?,?);
''',(measurement_id, area[0], area[1], float(min(area[2])), float(average), float(latitude), float(longitude), float(1))) ''',(measurement_id, area[0], area[1], float(minimum_thickness), float(average), float(latitude), float(longitude), float(1)))
total_measurement_average = total_measurement_average / len(areas_data) 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 (soon to be implemented)
cursor.execute(''' cursor.execute('''
UPDATE Measurement UPDATE Measurement
SET measurementID = ? AND WholeAverageThickness = ? SET measurementID = ?, WholeAverageThickness = ?
WHERE MeasurementID IS NULL AND WholeAverageThickness = 0; WHERE MeasurementID IS NULL AND WholeAverageThickness = 0;
''', (int(measurement_id), total_measurement_average),) ''', (int(measurement_id), total_measurement_average), )
else: else:
print('No data found') print('No data found')
print("uwu3")
# send the changes to the database # send the changes to the database
cursor.connection.commit() cursor.connection.commit()
...@@ -70,4 +73,4 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): ...@@ -70,4 +73,4 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
except Exception as e: except Exception as e:
print("An error occurred", e) print("An error occurred", e)
# rollback in case of error # rollback in case of error
cursor.connection.rollback() cursor.connection.rollback()
\ No newline at end of file
No preview for this file type
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