diff --git a/server/main.py b/server/main.py index 989e1c30ef336b29029bfefdd10ba3e6cc0c95f3..647d223ddedb221a7e61752d10a441b0e80cc584 100644 --- a/server/main.py +++ b/server/main.py @@ -37,10 +37,10 @@ class IceHTTP(BaseHTTPRequestHandler): self.wfile.write(b"Root path hit!") elif self.path == '/update_map': # NB: should be POST? - get_all_markers(self, self.cursor, False, 'Mjosa') # Get all markers + get_all_markers(self.cursor, False, 'Mjosa') # Get all markers # NB: temporary hardcoded waterBodyName elif self.path == '/get_valid_markers': # NB: should be POST? - get_all_markers(self, self.cursor, True, 'Mjosa') # Get only valid markers + get_all_markers(self.cursor, True, 'Mjosa') # Get only valid markers # NB: temporary hardcoded waterBodyName elif self.path == '/get_relation': get_relation(self, 'Mjosa') # NB temp hardcoded value @@ -49,9 +49,6 @@ class IceHTTP(BaseHTTPRequestHandler): if self.path == '/get_weather_data': 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 - # Terminate server on key press q def on_key_press(server, event, cursor, conn): if event.name == 'q': diff --git a/server/map/__pycache__/get_relation.cpython-311.pyc b/server/map/__pycache__/get_relation.cpython-311.pyc index 1760906d6404076504fcbd8abf46308b0a8dab2a..52d93ce095e8b69937d65db4bbf026a67c5c6a81 100644 Binary files a/server/map/__pycache__/get_relation.cpython-311.pyc and b/server/map/__pycache__/get_relation.cpython-311.pyc differ diff --git a/server/map/get_relation.py b/server/map/get_relation.py index a24d62ae220232a70a2deeef09df56c48eee09be..616adfa31f6f7298fcf8172fabab7f7fa3d111ac 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -16,16 +16,8 @@ def get_relation(self, body_of_water: str): if len(polygons) <= 1: print("Failed to convert to polygons") - tiles = [] - - for polygon in polygons: - tiles.extend(divide_relation(polygon)) # Divide each polygon from relation and append to tiles - - # Convert polygon coordinates to lists - tiles_json = [list(tile.exterior.coords) for tile in tiles] - # Convert response data to JSON string - response_json = json.dumps(tiles_json) + response_json = json.dumps(divide_relation(polygons)) # Set headers self.send_response(200) @@ -36,30 +28,34 @@ def get_relation(self, body_of_water: str): self.wfile.write(response_json.encode('utf-8')) -def divide_relation(polygon): +def divide_relation(polygons): # Define tile size tile_size = 0.01 - - x_min, y_min, x_max, y_max = polygon.bounds - rows = int((y_max - y_min) / tile_size) - cols = int((x_max - x_min) / tile_size) - + id = 1 tiles = [] - if rows == 0 or cols == 0: # Return if the polygon is too small - return [] - - for row in range(rows): - for col in range(cols): - tile_bbox = Polygon([ - (x_min + col * tile_size, y_min + row * tile_size), - (x_min + (col + 1) * tile_size, y_min + row * tile_size), - (x_min + (col + 1) * tile_size, y_min + (row + 1) * tile_size), - (x_min + col * tile_size, y_min + (row + 1) * tile_size) - ]) - tiles.append(tile_bbox) + for polygon in polygons: + x_min, y_min, x_max, y_max = polygon.bounds + rows = int((y_max - y_min) / tile_size) + cols = int((x_max - x_min) / tile_size) + + if rows == 0 or cols == 0: # Skip small polygons + continue + + for row in range(rows): + for col in range(cols): + tile_bbox = Polygon([ + (x_min + col * tile_size, y_min + row * tile_size), + (x_min + (col + 1) * tile_size, y_min + row * tile_size), + (x_min + (col + 1) * tile_size, y_min + (row + 1) * tile_size), + (x_min + col * tile_size, y_min + (row + 1) * tile_size) + ]) + tiles.append({"SubDivID": id, "polygon": tile_bbox}) + id += 1 if len(tiles) <= 1: - print("Failed to divide polygon into tiles") + print("Failed to divide polygons into tiles") - return tiles + tiles_json = [{"SubDivID": tile["SubDivID"], "coordinates": list(tile["polygon"].exterior.coords)} for tile in + tiles] + return tiles_json