From a023e1afb52d4781c56c91b1d6538d85819b91e5 Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Wed, 20 Mar 2024 12:25:38 +0100
Subject: [PATCH] update: tile center calculation

---
 server/map/get_relation.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/server/map/get_relation.py b/server/map/get_relation.py
index a2f455bc..0aa7c7fc 100644
--- a/server/map/get_relation.py
+++ b/server/map/get_relation.py
@@ -53,8 +53,11 @@ def cut_map(self, body_of_water: str):  # NB: implement body_of_water
     sub_div_id = 0
     for tile in divided_map: # NB temporarily limited to 5 tiles
 
-        # Round coordinates to 4 decimals
-        center = round(tile.centroid.coords[0][0], 4), round(tile.centroid.coords[0][1], 4)
+        # 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(tile.centroid.coords[0][0], 4), round(tile.centroid.coords[0][1], 4)
+
         rounded_coordinates = []
         if isinstance(tile, Polygon):
             for coords in tile.exterior.coords:
@@ -135,9 +138,7 @@ def write_json_to_file(path: str, file_name: str, json_data: dict):
         json.dump(json_data, f)
 
 
-'''
 def get_divided_map(file_name):
-    geo_data = gpd.read_file("server/map/mjosa.geojson")
+    geo_data = gpd.read_file("server/map/" + file_name + ".geojson")
     polygon_data = geo_data[geo_data['geometry'].geom_type == 'Polygon']
     polygons = [Polygon(polygon.exterior) for polygon in polygon_data['geometry']]
-'''
-- 
GitLab