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

change: a little more organized

parent 0cd1b498
No related branches found
No related tags found
No related merge requests found
import math
from itertools import groupby
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
# check if lidar points is within range of the area selected
def inArea(position, areaRange):
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:
return False
# find distance between two points
def distance(point1, point2):
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):
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_found = current_point
return closest_point_found
# Calculation of height in an area from las files
def find_height(points):
print(points, " 5 ")
height_differences = [] # final container for height data
# sort the points
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]))]
# loop through the groups to find the difference in height
for group in groupCoords:
if len(group) < 2 or group[0] == group[1]:
continue # jump over iteration if there is only one coordinate or lidar registered the same point twice
# find max and min height
min_height = min(coords[2] for coords in group)
max_height = max(coords[2] for coords in group)
# difference between them
difference = max_height - min_height
height_differences.append(difference)
# list of thickness in an area
return height_differences
def calculate_corners(lat, lng, area_offset):
"""Calculate corners of polygon based on a center coordinate
......
......@@ -3,11 +3,10 @@ import laspy
import json
import math
import utm # src: https://github.com/Turbo87/utm
from itertools import groupby
from server.data_processing.area_processing import calculate_corners, define_gridareas
from server.data_processing.area_processing import (calculate_corners, define_gridareas, inArea,
find_height, closest_points)
# hard coded files for test data
# hard coded files for test datas
lazData_path = ["server/example_lidar_data/ot_N_000005_1.laz", "server/example_lidar_data/ot_N_000033_1.laz"]
# Info about data
......@@ -30,58 +29,6 @@ def about_laz_file():
return [las.header.version, las.header.point_count, las.header.scale, las.header.offset]
# check if lidar points is within range of the area selected
def inArea(position, areaRange):
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:
return False
# find distance between two points
def distance(point1, point2):
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):
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_found = current_point
return closest_point_found
# Calculation of height in an area from las files
def find_height(points):
print(points, " 5 ")
height_differences = [] # final container for height data
# sort the points
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]))]
# loop through the groups to find the difference in height
for group in groupCoords:
if len(group) < 2 or group[0] == group[1]:
continue # jump over iteration if there is only one coordinate or lidar registered the same point twice
# find max and min height
min_height = min(coords[2] for coords in group)
max_height = max(coords[2] for coords in group)
# difference between them
difference = max_height - min_height
height_differences.append(difference)
# list of thickness in an area
return height_differences
# 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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment