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

change: adapt to json data

parent fb490448
No related branches found
No related tags found
No related merge requests found
import numpy as np
import laspy
import json
import utm # src: https://github.com/Turbo87/utm
from itertools import groupby
from server.data_processing.area_processing import calculate_corners, define_gridareas
......@@ -31,7 +32,7 @@ def about_laz_file():
# 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]):
if (areaRange[0][0] > x > areaRange[1][0]) and (abs(areaRange[0][1]) > abs(y) > abs(areaRange[1][1])):
return True
else:
return False
......@@ -64,12 +65,31 @@ def find_height(points):
# 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):
def calculate_area_data(center, cell_size, body_of_water):
# map application size to meters
cell_size_to_meters = cell_size * 600000
# container for all the heights in area
area_heights = []
# set the limit of the area compared to local coordinates
area_limit = calculate_corners(center[0],center[1], 1500)
area_limit = calculate_corners(center[0],center[1], cell_size_to_meters)
# read json data with path to data for specific water body
file_name = "server/lake_relations/" + body_of_water + "_div.json"
with open(file_name) as data:
map_data = json.load(data)
map_data = map_data['features']
print(map_data[0]['properties']['sub_div_center'][0])
map_zones = [area_limit[1],area_limit[3]]
print(map_zones)
map_data = list(filter(lambda point_position: inArea((point_position['properties']['sub_div_center'][0][1], point_position['properties']['sub_div_center'][0][0],0.0), map_zones), map_data))
print(len(map_data))
# Refactor lidar data to a readable format
iceOver = laspy.read(lazData_path[0])
......@@ -81,7 +101,7 @@ def calculate_area_data(center):
min_point = min(ice_points)
# define all the sub-areas within the area, local coordinates
grid_area_heights = define_gridareas(60,10, 1500,4)
grid_area_heights = define_gridareas(60,10, cell_size_to_meters,4)
# find the heights of each sub-area => area-heights
for sub_area in grid_area_heights:
......@@ -101,5 +121,6 @@ def calculate_area_data(center):
return area_heights
print(calculate_area_data((61,11), 0.04,'mjosa'))
print(abs(-69.9))
......@@ -48,7 +48,7 @@ class IceHTTP(BaseHTTPRequestHandler):
get_weather(self)
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, 'Mjosa') # hardcoded body of water must change later
# Start a server on port 8443 using self defined HTTP class
if __name__ == "__main__":
......
......@@ -3,11 +3,12 @@ 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):
def input_new_Lidar_data(self, cursor, bodyOfWater):
try:
# hard coded coordinates
latitude = 60.0
longitude = 10.0
sensorId = 1
total_measurement_average = 0 # the total average of a measurement
......@@ -27,7 +28,7 @@ def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater):
measurement_id = cursor.lastrowid
# calculate the area of to be calculated based on the coordinates given to the calculation model
areas_data = calculate_area_data((latitude, longitude))
areas_data = calculate_area_data((latitude, longitude), 0.04, bodyOfWater)
if(areas_data):
......
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