diff --git a/server/data_processing/area_processing.py b/server/data_processing/area_processing.py new file mode 100644 index 0000000000000000000000000000000000000000..b88f1c1ccf62aea4e4c9f49163bd62854e8613be --- /dev/null +++ b/server/data_processing/area_processing.py @@ -0,0 +1,51 @@ +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)]''' + +def define_gridareas(lat, lng, area_offset, grid_size): + return_value = [] + main_area = calculate_corners(lat, lng, area_offset) + area_size = (main_area[0][0] - main_area[2][0], main_area[0][1] - main_area[2][1]) + dist_to_subcenter = (area_size[0]/(grid_size*2), area_size[1]/(grid_size*2)) + subarea_offset = area_offset/grid_size + print(area_size) + print(dist_to_subcenter) + 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] + return_value.append(calculate_corners(lat_pos, lng_pos,subarea_offset)) + + return return_value + +print(calculate_corners(60,10,1500)) +print(define_gridareas(60,10,1500,4)) \ No newline at end of file diff --git a/server/map/get_markers.py b/server/map/get_markers.py index bf7e9e11c1d529040274e69ecc974726bcd88e14..24e856537ccaaee7885831d60742f38a8832d98d 100644 --- a/server/map/get_markers.py +++ b/server/map/get_markers.py @@ -1,6 +1,4 @@ import json -from math import pi, cos - # get_markers requests all marker data or valid markers, converts the data to json, and writes # the data to the response object @@ -91,37 +89,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)]