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

update: the comments

parent a5213d66
No related branches found
No related tags found
No related merge requests found
......@@ -5,26 +5,17 @@ from math import pi, cos
EARTH = 6378.137 # Radius of the earth in kilometer
METER = (1 / ((2 * pi / 360) * EARTH)) / 1000 # 1 meter in degree
# find real world coordinates to lidar
#
# p - area using real world coordinate
# l - area using lidar coordinate(pointcloud)
# max_limit - maximum area limit of a lidar scann in real world coordinates
def position_relative_to_pointcloud(l1, l2, p1, p2, center_lim, max_lim):
center_l = tuple((a+b)/2 for a, b in zip(l1,l2))
return [
((p1[0] - center_lim[0]) * ((l1[0] - l2[0]) / (max_lim[2][0] - max_lim[0][0])) + center_l[0],
(p1[1] - center_lim[1]) * ((l1[1] - l2[1]) / (max_lim[2][1] - max_lim[0][1])) + center_l[1]),
((p2[0] - center_lim[0]) * ((l1[0] - l2[0]) / (max_lim[2][0] - max_lim[0][0])) + center_l[0],
(p2[1] - center_lim[1]) * ((l1[1] - l2[1]) / (max_lim[2][1] - max_lim[0][1])) + center_l[1]),
]
#print(position_relative_to_pointcloud((-20,20), (-10,30), (1,3), (2,2), (2.5,2.5), [(5,5),(0,5),(0,0),(5,0)]))
#print(position_relative_to_pointcloud((-3299999, 4608018), (-3200001, 4687153), (61.47620866851029, 8.961138281887507), (61.95241733702057, 6.8508373935926645), (61, 11), [(61.95241733702057, 15.125349549679886), (60.04758266297943, 15.125349549679886), (60.04758266297943, 6.8746504503201145), (61.95241733702057, 6.8746504503201145)]))
# check if lidar points is within range of the area selected
def inArea(position, areaRange):
"""
finds out if position is in area's range
:param position: current checked position in
:param areaRange: range of checked position, containing a touple with max and min limit
:return: True if position is in range otherwise False
"""
x, y, _ = position # position to be checked
#print((areaRange[0][0])," < ",x," < ",(areaRange[1][0])," and ",(areaRange[0][1])," < ",(y)," < ",(areaRange[1][1])," ",((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])):
return True
else:
......@@ -32,12 +23,27 @@ def inArea(position, areaRange):
# find distance between two points
def distance(point1, point2):
"""
calculates the distance between two points
:param point1: first point
:param point2: second points
:return: the distance between two points
"""
y1, x1 = point1
y2, x2 = point2
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):
"""
finds the closest points within a list of points and returns the closest point that has not been taken
:param point: position to check for closest points
:param list: list of points in an area
:param coords_taken: list of coordinates that has been taken
:return: the closest to point that has not been taken
"""
closest_point_found = None
closest_dist = float('inf')
for current_point in list:
......@@ -49,6 +55,12 @@ def closest_points(point, list, coords_taken):
# Calculation of height in an area from las files
def find_height(points):
"""
finds the heights of a list of points that has grouped together points with identical XY coordinates
:param points: a list of points in an area
:return: the heights within a list of points
"""
if len(points) == 0:
return [0]
height_differences = [] # final container for height data
......@@ -76,11 +88,12 @@ def find_height(points):
return height_differences
def calculate_corners(lat, lng, area_offset):
"""Calculate corners of polygon based on a center coordinate
"""
Calculate corners of polygon based on a center coordinate
Arguments:
lat -- center latitude
lng -- center longitude
:param lat -- center latitude
:param lng -- center longitude
:return: a list of the corners of the polygon based on a center coordinate
"""
# From https://stackoverflow.com/questions/7477003/calculating-new-longitude-latitude-from-old-n-meters
# Formulas:
......@@ -100,6 +113,15 @@ def calculate_corners(lat, lng, area_offset):
# separate the zones into smaller area, into a grid
def define_gridareas(lat, lng, area_offset, grid_size):
"""
Define the grid areas of a zones center and offset
:param lat: center latitude of the grid
:param lng: center longitude of the grid
:param area_offset: offset between center to corner
:param grid_size: number of zone divisions into grid
:return: list of corners of each grid, based on the number of grid divisions and offset of the zone
"""
# container for an area turned into a grid of areas
grided_area = []
......@@ -134,6 +156,15 @@ def define_gridareas(lat, lng, area_offset, grid_size):
# separate the zones into smaller area, into a grid
def define_grid_lidardata(max_area, grid_size, points):
"""
Define the grid of the lidar data and divide each point to its designated area,
based on maximum limited area, grid size and points position on the grid
:param max_area: corner coordinates of its maximum area
:param grid_size: number of area divisions into grids
:param points: list of points
:return: list of grid with all the points inside its designated grid
"""
# container for an area turned into a grid of areas
grided_area = []
......@@ -165,4 +196,24 @@ def define_grid_lidardata(max_area, grid_size, points):
return grided_area
#[1,2,2,3,4,5,6,3,4,6,8,9,5,3,5.7,8,5,3]
#print(define_gridareas(60,10,1500,4))
#print(define_gridareas(3435693.5,6299200.0, 400000,4))
\ No newline at end of file
#print(define_gridareas(3435693.5,6299200.0, 400000,4))
'''
# find real world coordinates to lidar
#
# p1 - area using real world coordinate
# p2 - area using real world coordinate
# l1 - min area limit lidar coordinate(pointcloud)
# l2 - max area limit lidar coordinate(pointcloud)
# max_limit - maximum area limit of a lidar scann in real world coordinates
def position_relative_to_pointcloud(l1, l2, p1, p2, center_lim, max_lim):
center_l = tuple((a+b)/2 for a, b in zip(l1,l2))
return [
((p1[0] - center_lim[0]) * ((l1[0] - l2[0]) / (max_lim[2][0] - max_lim[0][0])) + center_l[0],
(p1[1] - center_lim[1]) * ((l1[1] - l2[1]) / (max_lim[2][1] - max_lim[0][1])) + center_l[1]),
((p2[0] - center_lim[0]) * ((l1[0] - l2[0]) / (max_lim[2][0] - max_lim[0][0])) + center_l[0],
(p2[1] - center_lim[1]) * ((l1[1] - l2[1]) / (max_lim[2][1] - max_lim[0][1])) + center_l[1]),
]
#print(position_relative_to_pointcloud((-20,20), (-10,30), (1,3), (2,2), (2.5,2.5), [(5,5),(0,5),(0,0),(5,0)]))
#print(position_relative_to_pointcloud((-3299999, 4608018), (-3200001, 4687153), (61.47620866851029, 8.961138281887507), (61.95241733702057, 6.8508373935926645), (61, 11), [(61.95241733702057, 15.125349549679886), (60.04758266297943, 15.125349549679886), (60.04758266297943, 6.8746504503201145), (61.95241733702057, 6.8746504503201145)]))
'''
......@@ -11,6 +11,12 @@ from server.data_processing.area_processing import calculate_corners, define_gri
# Info about data
def about_laz_file(path):
"""
write info about the lidar's raw data
:param path: path to the lidar data
:return: list with info about version, point_count, scale in meters and offset in meters
"""
with laspy.open(path) as fh:
# Print metadata properties
print("File Version:", fh.header.version)
......@@ -30,6 +36,12 @@ def about_laz_file(path):
return [las.header.version, las.header.point_count, las.header.scale, las.header.offset]
def find_folder_files(direcory):
"""
find all files in a directory
:param direcory: path to directory
:return: list with all file paths within directory
"""
files = []
for root, _, fileNames in os.walk(direcory):
for fileName in fileNames:
......@@ -39,6 +51,14 @@ def find_folder_files(direcory):
# 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, body_of_water, path):
"""
calculate area
:param center: center point of area to be calculated
:param body_of_water: body of water area belongs to
:param path: path to lidar data
:return: the calculated ice thickness in designated area
"""
# container for all the heights in area
area_heights = []
......@@ -85,7 +105,6 @@ def calculate_area_data(center, body_of_water, path):
# define all the sub-areas within the area, lidar coordinates
grid_area_lidar_heights = define_grid_lidardata((min_point, max_point), grid_size, ice_points)
print('grid height: ', grid_area_lidar_heights)
sub_area_heights = list(zip(grid_sub_area, grid_area_lidar_heights))
# find the heights of each sub-area => area-heights
......@@ -94,14 +113,6 @@ def calculate_area_data(center, body_of_water, path):
start = (sub_area[0][2])
end = (sub_area[0][0])
#test data
# zone coordinates sett to be relative to the lidar data's point cloud
#print("l1 = ", min_point, " l2 = ", max_point)
#print("p1 = ", start, " p2 = ", end)
#print("center_lim = ", center)
#print("max_lim = ", area_limit)
#areazone = position_relative_to_pointcloud(min_point, max_point, start, end, center, area_limit)
#print("area",areazone)
# calculate map zones height
ys, xs = start
ye, xe = end
......@@ -113,18 +124,12 @@ def calculate_area_data(center, body_of_water, path):
current_map_zone = closest_points(sub_center, part_of_subarea_of_waterbody, taken_coords)
sub_center = current_map_zone['properties']['sub_div_center']
taken_coords.append(sub_center)
print("item added", sub_center, " len ", len(taken_coords))
else:
print("sub area not found on map")
continue
current_zone_id = current_map_zone['properties']['sub_div_id']
# filter data within sub-area zones
#print(areazone[0][0]," < ",ice_points[0][0]," < ",areazone[1][0])
#print(areazone[0][1]," > ",ice_points[0][1]," > ",areazone[1][1])
#points_in_area = list(filter(lambda point_position: inArea(point_position, areazone), ice_points))
if current_map_zone is not None:
# sub_id center heights
area_heights.append((current_zone_id, sub_center, sub_area[1]))
......
......@@ -6,12 +6,12 @@ from server.data_processing.process_lidar_data import calculate_area_data, about
# 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):
"""
send the sensors data of the bodyOfWater to database and update the jsonfile for specific body of water
:param self:
:param cursor:
:param sensorId:
:param bodyOfWater:
:return:
:param self (BaseHTTPRequestHandler): A instance of a BaseHTTPRequestHandler
:param cursor (cursor): An Sqlite3 cursor object that points to the database
:param sensorId: Id of the sensor used to measure the data
:param bodyOfWater (str): The name of the requested file/lake
"""
try:
# print("name=",bodyOfWater)
......@@ -138,7 +138,7 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
else:
# Temporary not gonna use:
# Just temporary, not gonna use:
with open(file_path, "w") as file:
file.write("[{\"MeasurementID\": 1,\"TimeMeasured\": \"2024-04-15 16:23:28.620516\",\"CenterLat\": 60.841532,\"CenterLon\": 10.717878,\"Sensor\": {\"SensorID\": 2,\"SensorType\": \"LiDar\",\"Active\": true},\"Subdivisions\": []},{\"MeasurementID\": 2,\"TimeMeasured\": \"2024-04-15 16:23:28.620516\",\"CenterLat\": 60.841532,\"CenterLon\": 10.717878,\"Sensor\": {\"SensorID\": 2,\"SensorType\": \"LiDar\",\"Active\": true},\"Subdivisions\": []}]") # Writing an empty JSON object
......
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