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

update: split into horizontal sections from grid

parent 5e7028a9
No related branches found
No related tags found
1 merge request!6Clhp map
No preview for this file type
...@@ -33,7 +33,10 @@ def get_relation(self, body_of_water: str): ...@@ -33,7 +33,10 @@ def get_relation(self, body_of_water: str):
#hrz_lines = grid_lines[0] # Horizontal coordinates #hrz_lines = grid_lines[0] # Horizontal coordinates
#vrt_lines = grid_lines[1] # Vertical coordinates #vrt_lines = grid_lines[1] # Vertical coordinates
hrz_lines = [60.7530, 60.5931] # Horizontal coordinates hrz_lines = grid_lines[1] # Horizontal coordinates
for line in hrz_lines:
print("line: ", line)
vrt_lines = [11.0413] # Vertical coordinates vrt_lines = [11.0413] # Vertical coordinates
# Cut polygon into horizontal sections # Cut polygon into horizontal sections
...@@ -49,6 +52,8 @@ def get_relation(self, body_of_water: str): ...@@ -49,6 +52,8 @@ def get_relation(self, body_of_water: str):
divided_map.append(polygon) divided_map.append(polygon)
break
tiles = gpd.GeoDataFrame(geometry=divided_map) tiles = gpd.GeoDataFrame(geometry=divided_map)
# NB test plot # NB test plot
...@@ -88,12 +93,12 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool): ...@@ -88,12 +93,12 @@ def cut_polygon_in_two(polygon: Polygon, divisor: float, horizontal: bool):
for point in exterior_coords: for point in exterior_coords:
point = Point(point) # Convert coordinates to Shapely Point object point = Point(point) # Convert coordinates to Shapely Point object
if horizontal: # Horizontal split if horizontal: # Horizontal split
if point.y > divisor: if point.y < divisor:
split_shape.append(point) split_shape.append(point)
else: else:
remaining_shape.append(point) remaining_shape.append(point)
else: # Vertical split else: # Vertical split
if point.x > divisor: if point.x < divisor:
split_shape.append(point) split_shape.append(point)
else: else:
remaining_shape.append(point) remaining_shape.append(point)
...@@ -125,8 +130,12 @@ def create_grid_coords(polygon: Polygon, cell_size: float): ...@@ -125,8 +130,12 @@ def create_grid_coords(polygon: Polygon, cell_size: float):
x_coords = np.arange(min_x, max_x, cell_size) x_coords = np.arange(min_x, max_x, cell_size)
y_coords = np.arange(min_y, max_y, cell_size) y_coords = np.arange(min_y, max_y, cell_size)
if len(x_coords) == 0 or len(y_coords) == 0: # Round the coordinates to 4 decimals
x_coords_rounded = np.around(x_coords, decimals=4)
y_coords_rounded = np.around(y_coords, decimals=4)
if len(x_coords_rounded) == 0 or len(y_coords_rounded) == 0:
raise ValueError("No grid points generated") raise ValueError("No grid points generated")
# Return tuple of list of x coordinates and list of y coordinates # Return tuple of list of x coordinates and list of y coordinates
return x_coords, y_coords return x_coords_rounded, y_coords_rounded
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