Skip to content
Snippets Groups Projects
Commit ec169a02 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

merge: with main

parents 884b15f1 19c84eaf
No related branches found
No related tags found
2 merge requests!5Clhp map,!4Clhp map
Showing
with 106 additions and 57 deletions
No preview for this file type
No preview for this file type
No preview for this file type
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
def calculate_corners(lat, lng, area_offset):
"""Calculate corners of polygon based on a center coordinate
Arguments:
lat -- center latitude
lng -- center longitude
"""
# 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))
lat_neg = lat - (area_offset * METER)
lng_neg = lng - (area_offset * METER) / cos(lat * (pi / 180))
return [
(lat_neg, lng_pos), # top left
(lat_pos, lng_pos), # top right
(lat_pos, lng_neg), # bottom right
(lat_neg, lng_neg) # bottom left
]
'''return [(60.7798, 10.7062), # NB: temporary hardcoded values
(60.7553, 10.7433),
(60.7718, 10.7975),
(60.7966, 10.7405)]'''
# separate the zones into smaller area, into a grid
def define_gridareas(lat, lng, area_offset, grid_size, dimension, subId, groupId):
a = dimension + subId + groupId # soon to be implemented
print(a)
grided_area = [] # container for an area turned into a grid of areas
# find the main area's corner positions
main_area = calculate_corners(lat, lng, area_offset)
# find the main area's range size
area_size = (main_area[0][0] - main_area[2][0], main_area[0][1] - main_area[2][1])
# find each subareas vector to it's center
dist_to_subcenter = (area_size[0]/(grid_size*2), area_size[1]/(grid_size*2))
# find subareas size relative to main area
subarea_offset = area_offset/grid_size
# find the center coordinates of each area in grid to find the corner areas
for y in range(grid_size-1):
relative_size_lng = y / grid_size
for x in range(grid_size-1):
relative_size_lat = x / grid_size
lat_pos = main_area[0][0] + relative_size_lat * area_size[0] - dist_to_subcenter[0]
lng_pos = main_area[0][1] + relative_size_lng * area_size[1] - dist_to_subcenter[1]
# use the center of sub areas to find the corner of each subarea
grided_area.append(calculate_corners(lat_pos, lng_pos,subarea_offset))
return grided_area
#print(calculate_corners(60,10,1500))
#print(define_gridareas(60,10,1500,4))
\ No newline at end of file
import numpy as np
import laspy
from itertools import groupby
from process_lidar_data import calculate_corners, define_gridareas
# 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"]
# Info about data
......@@ -22,6 +24,7 @@ with laspy.open(lazData_path[0]) as fh:
for r, c in zip(bins, counts):
print(' {}:{}'.format(r, c))
# check if lidar points is within range of the area selected
def inArea(position, areaRange):
x, y, _ = position
if (areaRange[0][0] < x < areaRange[1][0]) and (areaRange[0][1] > y > areaRange[1][1]):
......@@ -29,52 +32,66 @@ def inArea(position, areaRange):
else:
return False
# Calculation of height gotten from las files
# Calculation of height in an area from las files
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]))
# 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]))]
height_differences = []
groupss = []
for groups in groupCoords:
if len(groups) < 2 or groups[0] == groups[1]:
continue
# 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
min_height = min(coords[2] for coords in groups)
max_height = max(coords[2] for coords in groups)
# 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)
groupss.append(groups)
# list of thickness in a area
return height_differences
# areas
def height_in_area(area):
# 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 height_in_area(center):
# container for all the heights in area
area_heights = []
# Limit the data to specific areas
# this is only temporary data for coordinates in arctic
# areas = [
# [(-3671212, 7898422), (-3200175, 4699978)],
# [(60.815356, 10.672022), (60.774878, 10.768867)],
# ]
# NB: is only for the test data should be removed after
# specified the area and it's range
area = calculate_corners(center, 1500)
area = (area[0], area[2])
# NB: is only for the test data (soon to be removed)
areazone = [(((area[0]) * ((-3671212/60.815356) - (-3200175/60.774878))) - 3200175, (area[1] * ((7898422/10.768867) - (4699978/10.672022))) + 4699978),
(((area[0] - 100) * ((-3671212/60.815356) - (-3200175/60.774878))) - 3200175, ((area[1] - 1) * ((7898422/10.768867) - (4699978/10.672022))) + 4699978)]
# Refactor data format
# Refactor lidar data to a readable format
iceOver = laspy.read(lazData_path[0])
iceUnder = laspy.read(lazData_path[1])
# 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))
area_heights = []
ice_points = list(filter(lambda position: inArea(position, areazone), ice_points))
# area height in all the subsections
grid_area_heights = define_gridareas(areazone, 1500, 20)
area_heights = find_height(ice_points)
# find the heights of each sub-area => 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))
return area_heights
No preview for this file type
No preview for this file type
No preview for this file type
File added
No preview for this file type
import json
from math import pi, cos
# get_markers requests all marker data or valid markers, converts the data to json, and writes
......@@ -64,7 +63,7 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName):
'Active': bool(row[6])
},
'Subdivisions': [sub_division], # Array of sub_division objects
'Corners': calculate_corners(row[3], row[4]),
'Corners': [],
# Returns list of corners calculated based on center coordinates
}
......@@ -89,37 +88,3 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName):
# Write marker data to response object
self.wfile.write(marker_data.encode('utf-8'))
EARTH = 6378.137 # Radius of the earth in kilometer
METER = (1 / ((2 * pi / 360) * EARTH)) / 1000 # 1 meter in degree
OFFSET = 20 # Offset in meters
def calculate_corners(lat, lng):
"""Calculate corners of polygon based on a center coordinate
Arguments:
lat -- center latitude
lng -- center longitude
"""
# From https://stackoverflow.com/questions/7477003/calculating-new-longitude-latitude-from-old-n-meters
# Formulas:
'''
lat_pos = lat + (OFFSET * METER)
lng_pos = lng + (OFFSET * METER) / cos(lat * (pi / 180))
lat_neg = lat - (OFFSET * METER)
lng_neg = lng - (OFFSET * METER) / cos(lat * (pi / 180))
return [
(lat_neg, lng_pos),
(lat_pos, lng_pos),
(lat_pos, lng_neg),
(lat_neg, lng_neg)
] '''
return [(60.7798, 10.7062), # NB: temporary hardcoded values
(60.7553, 10.7433),
(60.7718, 10.7975),
(60.7966, 10.7405)]
......@@ -2,23 +2,27 @@ import json
from datetime import datetime
from server.data_processing.process_lidar_data import height_in_area
# 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):
try:
# 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
cursor.execute('''
INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName, WholeAverageThickness) VALUES
(?,?,?,?);
''', ( sensorId, datetime.utcnow().replace(microsecond=0), bodyOfWater,0))
''', ( sensorId, datetime.utcnow().replace(microsecond=0), bodyOfWater, 0))
# auto generate new measurement id
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
cursor.execute('''
SELECT CenterLatitude, CenterLongitude, SubDivisionID, GroupID
FROM SubDivision
......@@ -26,6 +30,7 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
''')
position_data = cursor.fetchall()
# soon to be removed
if(position_data):
for row in position_data:
latitude, longitude, subID, groupID = row
......@@ -42,10 +47,12 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
else:
print('No data')
# send the changes to the database
cursor.connection.commit()
print("suc_ceed")
# error handling
except Exception as e:
print("An error occurred", e)
# rollback in case of error
......
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