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

update: make more square-ish tiles

parent 549fc51e
No related branches found
No related tags found
1 merge request!10Clhp map
Source diff could not be displayed: it is too large. Options to address this: view the blob.
No preview for this file type
......@@ -3,9 +3,11 @@ from shapely.geometry import Polygon, LineString, MultiLineString
from shapely.ops import linemerge, unary_union, polygonize
import matplotlib.pyplot as plt
import random
import math
import json
import os
# Read a json file with relation data and send to response object
def cut_map(self, body_of_water: str): # NB: implement body_of_water
# Read relation from GeoJson file and extract all polygons
......@@ -20,7 +22,8 @@ def cut_map(self, body_of_water: str): # NB: implement body_of_water
for polygon in polygons:
cell_width = 0.04
cell_height = 0.04
cell_height = 0.02 # NB could be calculated based on cell_width and distance from equator
lines = create_grid(polygon, cell_width, cell_height)
lines.append(polygon.boundary)
lines = unary_union(lines)
......@@ -51,11 +54,11 @@ def cut_map(self, body_of_water: str): # NB: implement body_of_water
features = []
sub_div_id = 0
for tile in divided_map: # NB temporarily limited to 5 tiles
for tile in divided_map:
# Calculate tile center based on bounds, and round down to two decimals
min_x, min_y, max_x, max_y = tile.bounds
center = round(max_x-min_x, 4), round(max_y-min_y, 4)
center = round(max_x - min_x, 4), round(max_y - min_y, 4)
# center = round(tile.centroid.coords[0][0], 4), round(tile.centroid.coords[0][1], 4)
rounded_coordinates = []
......@@ -79,7 +82,7 @@ def cut_map(self, body_of_water: str): # NB: implement body_of_water
feature_collection = {
'type': 'FeatureCollection',
'features': features,
'tile_count': sub_div_id, # Add the last subdivision ID as number of tiles
'tile_count': sub_div_id, # Add the last subdivision ID as number of tiles
}
write_json_to_file("server/lake_relations", "mjosa", feature_collection)
......@@ -144,8 +147,9 @@ def get_divided_map(file_name):
polygon_data = geo_data[geo_data['geometry'].geom_type == 'Polygon']
polygons = [Polygon(polygon.exterior) for polygon in polygon_data['geometry']]
# Returns a list of [(sub_div_id, sub_div_center)]
def get_id_and_center(file_name):
def get_id_and_center(file_name): # NB buggy
# Expected format: [(id, [x,y]), (id, [x,y])]
geo_data = gpd.read_file("server/lake_relations/" + file_name + "_div.json")
subdivisions = []
......@@ -161,3 +165,4 @@ def get_id_and_center(file_name):
}
subdivisions.append(subdivision)
return subdivisions
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