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

no progress in calculations, must take later

parent a5cd0aa4
No related branches found
No related tags found
No related merge requests found
File added
No preview for this file type
...@@ -41,7 +41,7 @@ def define_gridareas(lat, lng, area_offset, grid_size): ...@@ -41,7 +41,7 @@ def define_gridareas(lat, lng, area_offset, grid_size):
area_size = (main_area[2][0] - main_area[0][0], main_area[0][1] - main_area[2][1]) area_size = (main_area[2][0] - main_area[0][0], main_area[0][1] - main_area[2][1])
# find each subareas vector to it's center # find each subareas vector to it's center
dist_to_subcenter = (area_size[0]/(grid_size*2), area_size[1]/(grid_size*2)) dist_to_subcenter = (area_size[0]/(grid_size*2), area_size[1]/(grid_size*2))
print(dist_to_subcenter)
# find subareas size relative to main area # find subareas size relative to main area
subarea_offset = area_offset/grid_size subarea_offset = area_offset/grid_size
...@@ -71,4 +71,5 @@ def define_gridareas(lat, lng, area_offset, grid_size): ...@@ -71,4 +71,5 @@ def define_gridareas(lat, lng, area_offset, grid_size):
return grided_area return grided_area
print(define_gridareas(60,10,1500,4)) #print(define_gridareas(-60,10,1500,4))
\ No newline at end of file print(define_gridareas(3435693.5,6299200.0, 20000000000,4))
\ No newline at end of file
import numpy as np import numpy as np
import laspy import laspy
import utm # src: https://github.com/Turbo87/utm
from itertools import groupby from itertools import groupby
from process_lidar_data import calculate_corners, define_gridareas from server.data_processing.area_processing import calculate_corners, define_gridareas
# hard coded files for test data # hard coded files for test data
lazData_path = ["server/example_lidar_data/ot_N_000005_1.laz", "server/example_lidar_data/ot_N_000033_1.laz"] lazData_path = ["server/example_lidar_data/ot_N_000005_1.laz", "server/example_lidar_data/ot_N_000033_1.laz"]
...@@ -27,7 +29,9 @@ with laspy.open(lazData_path[0]) as fh: ...@@ -27,7 +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
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])
if (areaRange[0][0] > x > areaRange[1][0]) and (areaRange[0][1] < y < areaRange[1][1]):
print("inside area")
return True return True
else: else:
return False return False
...@@ -60,7 +64,7 @@ def find_height(points): ...@@ -60,7 +64,7 @@ def find_height(points):
# find the height of an area based on the coordinates of it's center # 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 # and it's affiliations (subId and groupId) (soon to be implemented
def height_in_area(center): def calculate_area_data(center):
# container for all the heights in area # container for all the heights in area
area_heights = [] area_heights = []
...@@ -73,11 +77,39 @@ def height_in_area(center): ...@@ -73,11 +77,39 @@ def height_in_area(center):
# ] # ]
# specified the area and it's range # specified the area and it's range
area = calculate_corners(center, 1500) #area = (area[0], area[2])
area = (area[0], area[2]) #print("area size")
# NB: is only for the test data (soon to be removed) # NB: is only for the test data (soon to be removed and switched with center)
areazone = [(((area[0]) * ((-3671212/60.815356) - (-3200175/60.774878))) - 3200175, (area[1] * ((7898422/10.768867) - (4699978/10.672022))) + 4699978), #areazone = ((((7898422) - (4699978)))/2.0 + 4699978), (((-3671212) - (-3200175)))/2.0 - 3200175
(((area[0] - 100) * ((-3671212/60.815356) - (-3200175/60.774878))) - 3200175, ((area[1] - 1) * ((7898422/10.768867) - (4699978/10.672022))) + 4699978)] #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)
areazone = calculate_corners(3435693.5,7550000.0, 20000000000)
#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)]
# Refactor lidar data to a readable format # Refactor lidar data to a readable format
iceOver = laspy.read(lazData_path[0]) iceOver = laspy.read(lazData_path[0])
...@@ -85,13 +117,48 @@ def height_in_area(center): ...@@ -85,13 +117,48 @@ def height_in_area(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))
# area height in all the subsections # area height in all the subsections
grid_area_heights = define_gridareas(areazone, 1500, 20) #grid_area_heights = define_gridareas(-3435693.5,6299200.0, 20000000000,4)
grid_area_heights = define_gridareas(3435693.5,7550000.0, 20000000000,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:
ice_points = list(filter(lambda point_position: inArea(point_position, (sub_area[0],sub_area[2])), ice_points))
area_heights.append(find_height(ice_points)) #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)
print(type(ice_points[0]))
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, (((-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 return area_heights
print(-3>-4)
print(calculate_area_data((60.0,10.0)))
...@@ -43,15 +43,15 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -43,15 +43,15 @@ class IceHTTP(BaseHTTPRequestHandler):
elif self.path == '/get_valid_markers': # NB: should be POST? elif self.path == '/get_valid_markers': # NB: should be POST?
get_all_markers(self, self.cursor, True, 'Mjosa') # Get only valid markers get_all_markers(self, self.cursor, True, 'Mjosa') # Get only valid markers
# NB: temporary hardcoded waterBodyName # NB: temporary hardcoded waterBodyName
elif self.path == '/get_relation': #elif self.path == '/get_relation':
get_relation(self, 'Mjosa') # NB temp hardcoded value # get_relation(self, 'Mjosa') # NB temp hardcoded value
def do_POST(self): def do_POST(self):
if self.path == '/get_weather_data': if self.path == '/get_weather_data':
get_weather(self) get_weather(self)
elif self.path == '/new_lidar_data': elif self.path == '/new_lidar_data':
input_new_Lidar_data(self,self.cursor, 1, 'Mjosa') # hardcoded body of water must change later input_new_Lidar_data(self,self.cursor, 1, 'Mjosa') # hardcoded body of water must change later
# Terminate server on key press q # Terminate server on key press q
def on_key_press(server, event, cursor, conn): def on_key_press(server, event, cursor, conn):
......
No preview for this file type
No preview for this file type
import json import json
from datetime import datetime from datetime import datetime
from server.data_processing.process_lidar_data import height_in_area from server.data_processing.process_lidar_data import calculate_area_data
# input_new_Lidar_data send new data gathered from the lidar and send it to the database (from the drone, most likely) # input_new_Lidar_data send new data gathered from the lidar and send it to the database (from the drone, most likely)
def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
try: try:
# hard coded coordinates
latitude = 60.0
longitude = 10.0
total_measurement_average = 0 # the total average of a measurement
# create a new measurement with the time the data is sent, sensor type, where # create a new measurement with the time the data is sent, sensor type, where
# and an estimate of average thickness of ice on water body # and an estimate of average thickness of ice on water body
cursor.execute(''' cursor.execute('''
INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName, WholeAverageThickness) VALUES INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName,
(?,?,?,?); WholeAverageThickness, CenterLat, CenterLon) VALUES
''', ( sensorId, datetime.utcnow().replace(microsecond=0), bodyOfWater, 0)) (?,?,?,?,?,?);
''', (sensorId, datetime.utcnow().replace(microsecond=0), bodyOfWater, 0, latitude, longitude))
# auto generate new measurement id # auto generate new measurement id
measurement_id = cursor.lastrowid measurement_id = cursor.lastrowid
# input the newly generated measurement_id and ... average thickness (soon to be implemented)
cursor.execute('''
UPDATE Measurement
SET measurementID = ?
WHERE MeasurementID IS NULL;
''', (int(measurement_id),))
# soon to be removed # supposed get all the hardcode the coordinates of the areas we want
cursor.execute(''' # cursor.execute('''
SELECT CenterLatitude, CenterLongitude, SubDivisionID, GroupID # SELECT CenterLatitude, CenterLongitude, SubDivisionID, GroupID
FROM SubDivision # FROM SubDivision
GROUP BY CenterLatitude, CenterLongitude # GROUP BY CenterLatitude, CenterLongitude
''') # ''')
position_data = cursor.fetchall() # position_data = cursor.fetchall()
# soon to be removed # soon to be removed
if(position_data): print("uwu")
for row in position_data: areas_data = calculate_area_data((latitude, longitude))
latitude, longitude, subID, groupID = row print("area")
heights = height_in_area((latitude,longitude)) print(areas_data)
if(len(heights) > 0): if(areas_data):
print(heights) for area in areas_data:
else: #if(len(area[2]) != 0):
print("No height found") average = sum(area[2])/len(area[2])
average = sum(heights)/len(heights) #else:
#average = 0
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, subID, groupID, float(min(heights)), float(average), float(latitude), float(longitude), float(1))) ''',(measurement_id, area[0], area[1], float(min(area[2])), float(average), float(latitude), float(longitude), float(1)))
total_measurement_average = total_measurement_average / len(areas_data)
# input the newly generated measurement_id and whole average thickness (soon to be implemented)
cursor.execute('''
UPDATE Measurement
SET measurementID = ? AND WholeAverageThickness = ?
WHERE MeasurementID IS NULL AND WholeAverageThickness = 0;
''', (int(measurement_id), total_measurement_average),)
else: else:
print('No data') print('No data found')
print("uwu3")
# send the changes to the database # send the changes to the database
cursor.connection.commit() cursor.connection.commit()
......
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