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

change: move calclation functions to data processing, add: grid calculation

parent 28e896c6
No related branches found
No related tags found
No related merge requests found
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
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)]
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