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

update: divided into tiles

parent c9003def
No related branches found
No related tags found
2 merge requests!5Clhp map,!4Clhp map
......@@ -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':
......
No preview for this file type
......@@ -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
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