diff --git a/app/lib/widgets/choropleth_map.dart b/app/lib/widgets/choropleth_map.dart index c8455d93c8fd5b04138a1ff6f1389e128879972e..5645260444f3ee03af4a153f210cff59d0057467 100644 --- a/app/lib/widgets/choropleth_map.dart +++ b/app/lib/widgets/choropleth_map.dart @@ -1,4 +1,3 @@ -import 'dart:math'; import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:syncfusion_flutter_maps/maps.dart'; diff --git a/server/main.py b/server/main.py index aeef2812c6c1cb28501bd88d531585e8b372791a..2295e3ebd0a1daa5ffaada2d542b4b357bff073a 100644 --- a/server/main.py +++ b/server/main.py @@ -2,7 +2,7 @@ from flask import Flask from http.server import HTTPServer, BaseHTTPRequestHandler from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT from map.get_markers import get_all_markers -from map.get_relation import get_relation +from map.get_relation import cut_map from APIs.get_weather import get_weather import ssl import sqlite3 @@ -37,10 +37,10 @@ class IceHTTP(BaseHTTPRequestHandler): self.wfile.write(b"The root path provides no functionality. Please use a valid endpoint") elif self.path == '/update_map': # NB: should be POST? - get_all_markers(self, self.cursor, 'Mjosa') # Get all markers + get_all_markers(self, self.cursor, 'mjosa') # Get all markers # NB: temporary hardcoded waterBodyName elif self.path == '/get_relation': - get_relation(self, 'Mjosa') # NB temp hardcoded value + cut_map(self, 'Mjosa') # NB temp hardcoded value def do_POST(self): if self.path == '/get_weather_data': diff --git a/server/map/get_markers.py b/server/map/get_markers.py index 799f723a0ec44299c30751498051c1a06d0499d6..7288d2f0e68e46f8f8808a9325d9026b8d4245b5 100644 --- a/server/map/get_markers.py +++ b/server/map/get_markers.py @@ -1,4 +1,5 @@ import json +from get_relation import cut_map # get_markers requests all marker data or valid markers, converts the data to json, and writes @@ -87,11 +88,11 @@ def get_all_markers(self, cursor, waterBodyName): def calculateColor(thickness: int): # NB not final colors nor ranges - if 0 < thickness < 4: + if 0 < thickness <= 4: return 0xFFff0000 # Red - elif 4 < thickness < 6: + elif 4 < thickness <= 6: return 0xFFff9400 # Orange - elif 6 < thickness < 8: + elif 6 < thickness <= 8: return 0xFFb1ff00 # Green elif thickness > 8: return 0xFF00d6ff # Blue diff --git a/server/map/get_relation.py b/server/map/get_relation.py index 9f175ee845665081bfa35be119597a11bd3ec0ee..a2f455bcf2c6b9430c8f8756a7cfb28801d8b92a 100644 --- a/server/map/get_relation.py +++ b/server/map/get_relation.py @@ -7,9 +7,9 @@ import json import os # Read a json file with relation data and send to response object -def get_relation(self, body_of_water: str): # NB: implement body_of_water +def cut_map(self, body_of_water: str): # NB: implement body_of_water # Read relation from GeoJson file and extract all polygons - geo_data = gpd.read_file("server/map/mjosa.geojson") + geo_data = gpd.read_file("server/map/" + body_of_water + ".json") polygon_data = geo_data[geo_data['geometry'].geom_type == 'Polygon'] polygons = [Polygon(polygon.exterior) for polygon in polygon_data['geometry']] @@ -19,8 +19,9 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water divided_map = [] for polygon in polygons: - cell_size = 0.04 - lines = create_grid(polygon, cell_size) + cell_width = 0.04 + cell_height = 0.04 + lines = create_grid(polygon, cell_width, cell_height) lines.append(polygon.boundary) lines = unary_union(lines) lines = linemerge(lines) @@ -74,7 +75,8 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water feature_collection = { 'type': 'FeatureCollection', - 'features': features + 'features': features, + 'tile_count': sub_div_id, # Add the last subdivision ID as number of tiles } self.send_response(200) @@ -84,7 +86,7 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water self.wfile.write(json.dumps(feature_collection).encode('utf-8')) -def create_grid(poly: Polygon, cell_size): +def create_grid(poly: Polygon, cell_width, cell_height): # Retrieve bounds of the entire polygon bounds = poly.bounds @@ -96,14 +98,14 @@ def create_grid(poly: Polygon, cell_size): while y <= max_y: line = LineString([(min_x, y), (max_x, y)]) grid_lines.append(line) - y += cell_size + y += cell_height # Vertical lines x = min_x while x <= max_x: line = LineString([(x, min_y), (x, max_y)]) grid_lines.append(line) - x += cell_size + x += cell_width return grid_lines