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

fix: cell_size url param parsing

parent f4bf30a0
No related branches found
No related tags found
1 merge request!14Clhp map
...@@ -101,9 +101,15 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -101,9 +101,15 @@ class IceHTTP(BaseHTTPRequestHandler):
lake_name = query_params.get('lake', [None])[0] lake_name = query_params.get('lake', [None])[0]
if lake_name is not None: if lake_name is not None:
cell_size = query_params.get('cell_size', [''])[0] cell_size = query_params.get('cell_size', [''])[0]
cell_size_param = unquote(cell_size) # Decode url param
if cell_size is not None:
cut_map(self, cursor, lake_name, cell_size) if cell_size_param: # Check if cell_size_param is not an empty string
try:
# Try to convert the value to a float and the map
cell_size_float = float(cell_size_param)
cut_map(self, cursor, lake_name, cell_size_float)
except ValueError:
print("Error: cell_size_param is not a valid float")
else: else:
cut_map(self, cursor, lake_name) cut_map(self, cursor, lake_name)
else: else:
......
No preview for this file type
...@@ -20,12 +20,11 @@ starting coordinate (x,y) ...@@ -20,12 +20,11 @@ starting coordinate (x,y)
# 2 Formulas for calculating a distance in kilometers to a distance in latitude and longitude # 2 Formulas for calculating a distance in kilometers to a distance in latitude and longitude
lat = distance_in_km/111.32km lat = distance_in_km/111.32km
lng = (distance_in_km × 360)/(40075km × cos(lat)) lng = (distance_in_km × 360)/(40075km × cos(lat))
''' '''
# Read a json file with relation data and send to response object # Read a json file with relation data and send to response object
def cut_map(self, cursor, lake_name: str, cell_size_in_km=0.5): def cut_map(self, cursor, lake_name: str, cell_size_in_km: float = 0.5):
""" """
Cuts a map into a grid based on a selected cell size Cuts a map into a grid based on a selected cell size
...@@ -50,7 +49,7 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km=0.5): ...@@ -50,7 +49,7 @@ def cut_map(self, cursor, lake_name: str, cell_size_in_km=0.5):
# Convert the cell size to degrees # Convert the cell size to degrees
cell_size = cell_size_in_km * 10 cell_size = cell_size_in_km * 10
cell_width = cell_size / 111.32 cell_width = cell_size / 111.32
# A slightly more complicated formula is required to calculate the height to ensure that # A slightly more complicated formula is required to calculate the height. This ensures that
# the height in km is equal to the width in km regardless of the latitude. # the height in km is equal to the width in km regardless of the latitude.
cell_height = (cell_size * 360) / (40075 * cos(cell_width)) cell_height = (cell_size * 360) / (40075 * cos(cell_width))
......
[ [
"Mjøsa", "Mjøsa",
"Skumsjøen" "Skumsjøen",
"Skumsjøen"
] ]
\ No newline at end of file
This diff is collapsed.
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