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

fix: some parts of new get_measurement data structure

parent 047d6be8
No related branches found
No related tags found
Loading
......@@ -49,7 +49,7 @@ class SubDiv {
double minThickness;
double avgThickness;
LatLng center;
double accuracy;
int accuracy;
Color color;
List<IceStats> iceStats;
......@@ -69,12 +69,12 @@ class SubDiv {
return SubDiv(
sub_div_id: json['SubdivID'].toString(),
groupID: json['GroupID'] ?? 0,
minThickness: json['MinThickness'] ?? 0,
avgThickness: json['AvgThickness'] ?? 0,
minThickness: json['MinThickness'].toDouble ?? 0,
avgThickness: json['AvgThickness'].toDouble ?? 0,
center: json['CenLatitude'] != null && json['CenLongitude'] != null
? LatLng(json['CenLatitude'], json['CenLongitude'])
: LatLng(0.0, 0.0),
accuracy: json['Accuracy'] ?? 0.0,
accuracy: json['Accuracy'] ?? 0,
// Set grey as default color
color: json['Color'] != null ? Color(json['Color']) : Colors.grey,
iceStats: (json['IceStats'] as List<dynamic>?)
......
This diff is collapsed.
No preview for this file type
......@@ -29,6 +29,7 @@ def about_laz_file(path):
return [las.header.version, las.header.point_count, las.header.scale, las.header.offset]
def find_folder_files(direcory):
files = []
for root, _, fileNames in os.walk(direcory):
......@@ -36,7 +37,7 @@ def find_folder_files(direcory):
files.append(os.path.join(root, fileName))
return files
print(find_folder_files())
# 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
......@@ -59,55 +60,57 @@ def calculate_area_data(center, body_of_water):
# grid cell offset
# NB: make these a global var
grid_size = 4
#cell_x, cell_y = map_data['tile_width'], map_data['tile_height']
#cell_x, cell_y = (400*grid_size, 400*grid_size)
# cell_x, cell_y = map_data['tile_width'], map_data['tile_height']
# cell_x, cell_y = (400*grid_size, 400*grid_size)
cell_x, cell_y = (2000, 1000)
# convert the offset to meter
#cell_x = 111.320 * cell_x * 1000
#cell_y = (40075 * math.cos(cell_y) * 1000) / 360
# cell_x = 111.320 * cell_x * 1000
# cell_y = (40075 * math.cos(cell_y) * 1000) / 360
cell_x = 111.320 * cell_x
cell_y = (111.320 * math.cos(60)*cell_y)
cell_y = (111.320 * math.cos(60) * cell_y)
# set the limit of the area compared to local coordinates
area_limit = calculate_corners(center[0], center[1], (cell_x, cell_y))
#area_limit = calculate_corners(sub_center[0], sub_center[1], (cell_x/4, cell_y/4))
# area_limit = calculate_corners(sub_center[0], sub_center[1], (cell_x/4, cell_y/4))
# grid data
map_data = map_data['features']
map_zones = [area_limit[2], area_limit[0]]
map_data = list(filter(lambda point_position: inArea((point_position['properties']['sub_div_center'][0], point_position['properties']['sub_div_center'][1], 0.0), map_zones), map_data))
map_data = list(filter(lambda point_position: inArea(
(point_position['properties']['sub_div_center'][0], point_position['properties']['sub_div_center'][1], 0.0),
map_zones), map_data))
# Refactor lidar data to a readable format
iceOver = laspy.read(laz_data_paths[0])
iceUnder = laspy.read(laz_data_paths[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))
ice_points = list(zip(iceOver.X, iceOver.Y, iceOver.Z)) + list(zip(iceUnder.X, iceUnder.Y, iceUnder.Z))
print(len(ice_points))
ice_points = list(filter(lambda point_position: inArea((point_position[0],point_position[1],0.0),[(-3300000, 4500000), (-3200000, 5000000)]), ice_points))
ice_points = list(filter(lambda point_position: inArea((point_position[0], point_position[1], 0.0),
[(-3300000, 4500000), (-3200000, 5000000)]), ice_points))
print(len(ice_points))
# only for visualizating the testing data
#print("max",max(ice_points))
#print("min",min(ice_points))
# print("max",max(ice_points))
# print("min",min(ice_points))
#x = [points[0] for points in ice_points]
#y = [points[1] for points in ice_points]
# x = [points[0] for points in ice_points]
# y = [points[1] for points in ice_points]
# Plot the points
#plt.plot(x, y, 'bo') # 'bo' specifies blue color and circle markers
#plt.xlabel('X axis')
#plt.ylabel('Y axis')
#plt.title('Plotting Points')
#plt.grid(True) # Add grid
#plt.show()
# plt.plot(x, y, 'bo') # 'bo' specifies blue color and circle markers
# plt.xlabel('X axis')
# plt.ylabel('Y axis')
# plt.title('Plotting Points')
# plt.grid(True) # Add grid
# plt.show()
max_point = max(ice_points)
min_point = min(ice_points)
# define all the sub-areas within the area, local coordinates
grid_sub_area = define_gridareas(center[0], center[1], (cell_x, cell_y),grid_size)
grid_sub_area = define_gridareas(center[0], center[1], (cell_x, cell_y), grid_size)
# 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)
......@@ -122,23 +125,25 @@ def calculate_area_data(center, body_of_water):
start = (sub_area[0][2])
end = (sub_area[0][0])
#test data
# 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)
# 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
sub_center = ((xs + xe)/2, (ys + ye)/2)
sub_center = ((xs + xe) / 2, (ys + ye) / 2)
# check if area is part of water body
part_of_subarea_of_waterbody = list(filter(lambda pos: inArea((pos['properties']['sub_div_center'][0], pos['properties']['sub_div_center'][1], 0.0), [start,end]), map_data))
part_of_subarea_of_waterbody = list(filter(lambda pos: inArea(
(pos['properties']['sub_div_center'][0], pos['properties']['sub_div_center'][1], 0.0), [start, end]),
map_data))
print('sub_area: ', sub_area)
print('part_of_subarea_of_waterbody: ', part_of_subarea_of_waterbody)
if(len(part_of_subarea_of_waterbody) > 0):
if (len(part_of_subarea_of_waterbody) > 0):
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)
......@@ -150,16 +155,15 @@ def calculate_area_data(center, body_of_water):
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))
# 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]))
return area_heights
else:
return [] # return [0] if no data collected from lidar
return [] # return [0] if no data collected from lidar
#print(calculate_area_data((61, 11), 'mj\u00f8sa'))
# print(calculate_area_data((61, 11), 'mj\u00f8sa'))
No preview for this file type
No preview for this file type
......@@ -32,20 +32,24 @@ def get_measurements(self, lake_name):
# Iterate over all fetched rows
for measurement in lidar_data:
processed_subdivs = []
# Create new measurement object
# Create new measurement object with embedded sensor object
new_measurement = {
'MeasurementID': measurement['MeasurementID'],
'TimeMeasured': str(datetime.now()),
'CenterLat': measurement['CenterLat'],
'CenterLon': measurement['CenterLon'],
'Sensor': measurement['Sensor'],
'Subdivisions': [],
'Sensor': {
'SensorID': measurement['Sensor']['SensorID'],
'SensorType': measurement['Sensor']['SensorType'],
'Active': measurement['Sensor']['Active'],
},
'Subdivisions': None,
}
for sub_division in measurement['Subdivisions']:
subdiv_id = sub_division['SubdivID']
center_lat = sub_division['CenLatitude']
center_lng = sub_division['CenLongitude']
thicknesses = sub_division['Heights']
# Create new subdivision object
sub_division = {
......@@ -68,7 +72,7 @@ def get_measurements(self, lake_name):
processed_subdivs.append(sub_division)
# Append processed measurement and subdivisions
new_measurement['Subdivisions'].append(processed_subdivs)
new_measurement['Subdivisions'] = processed_subdivs
measurements.append(new_measurement)
# Populate remaining non-processed subdivisions and create "invalid" or "proxy" measurement to store them
......
......@@ -3,6 +3,7 @@ import os
from datetime import datetime
from server.data_processing.process_lidar_data import calculate_area_data, about_laz_file
# 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):
"""
......@@ -14,7 +15,7 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
:return:
"""
try:
print("name=",bodyOfWater)
print("name=", bodyOfWater)
# hard coded coordinates
latitude = 60.816848
longitude = 10.723823
......@@ -54,7 +55,7 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
}
}
if(areas_data):
if (areas_data):
# store lidar data in jason formate
# calculate data for each zone within the area
for area in areas_data:
......@@ -63,8 +64,8 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
map_lat, map_lng = area[1]
heights = area[2]
if(len(heights) != 0 or sum(heights) == 0):
average = sum(heights)/len(heights)
if (len(heights) != 0 or sum(heights) == 0):
average = sum(heights) / len(heights)
minimum_thickness = min(heights)
else:
average = 0
......@@ -75,7 +76,9 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
cursor.execute('''
INSERT INTO SubdivisionMeasurementData(MeasurementID, TimeMeasured, SubdivID, WaterBodyName, MinimumThickness, AverageThickness, CalculatedSafety, Accuracy) VALUES
(?,?,?,?,?,?,?,?);
''', (measurement_id, time_measured, subId, bodyOfWater, float(minimum_thickness), float(average), float(0.0), scale_factor))
''', (
measurement_id, time_measured, subId, bodyOfWater, float(minimum_thickness), float(average), float(0.0),
scale_factor))
sub_center = (map_lat, map_lng)
# set up json formate
lidar_read = {
......@@ -105,7 +108,7 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
self.send_response(200)
self.send_header('Content-type', "application/json")
self.end_headers()
file_path = "./server/map_handler/lake_relations/"+bodyOfWater+"_lidar_data.json"
file_path = "./server/map_handler/lake_relations/" + bodyOfWater + "_lidar_data.json"
content = None
current_directory = os.getcwd()
......@@ -123,7 +126,6 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
print('No data found, line 101')
content = json.dumps([])
# Write content data to response object
self.wfile.write(content.encode('utf-8'))
......
......@@ -13,7 +13,7 @@
{
"SubdivID": 36,
"MinThickness": -1.0,
"AvgThickness": 1,
"AvgThickness": 1.0,
"CenLatitude": 60.841532,
"CenLongitude": 10.717878,
"Accuracy": 2
......@@ -21,7 +21,7 @@
{
"SubdivID": 83,
"MinThickness": -1.0,
"AvgThickness": 14,
"AvgThickness": 14.0,
"CenLatitude": 60.828326,
"CenLongitude": 10.982563,
"Accuracy": 2
......@@ -29,7 +29,7 @@
{
"SubdivID": 33,
"MinThickness": -1.0,
"AvgThickness": 1,
"AvgThickness": 1.0,
"CenLatitude": 60.771059,
"CenLongitude": 10.698341,
"Accuracy": 2
......@@ -37,7 +37,7 @@
{
"SubdivID": 136,
"MinThickness": -1.0,
"AvgThickness": 9,
"AvgThickness": 9.0,
"CenLatitude": 60.396856,
"CenLongitude": 11.220933,
"Accuracy": 2
......
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