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

updaet: try to append tiles to map

parent a7577b80
No related branches found
No related tags found
2 merge requests!5Clhp map,!4Clhp map
......@@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:io';
import '../consts.dart';
import 'marker_data.dart';
import 'package:path_provider/path_provider.dart';
// fetchMarkerTemplate requests all marker data from the server
Future<List<Measurement>> fetchMarkerData() async {
......@@ -26,7 +27,14 @@ Future<List<Measurement>> fetchMarkerData() async {
// Attempt to parse response to Measurement object only if the body
// contains correctly formatted data
if (jsonData != null && jsonData is List) {
print(jsonData.map((data) => Measurement.fromJson(data)).toList());
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory();
String filePath = '${appDocumentsDirectory.path}/last_update.txt';
try { // Write most recent time of update to file
await File(filePath).writeAsString('${DateTime.now()}', mode: FileMode.write);
print('Update time written to file');
} catch (error) { print('Error in writing to file: $error');}
return jsonData.map((data) => Measurement.fromJson(data)).toList();
} else {
throw Exception('Failed to parse marker data: Unexpected response format');
......
......@@ -3,9 +3,6 @@ import 'dart:convert';
import 'dart:io';
import '../consts.dart';
import 'dart:typed_data';
import 'dart:io';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
/// Fetch relation data from server
Future<Uint8List> fetchRelation() async {
......@@ -24,14 +21,6 @@ Future<Uint8List> fetchRelation() async {
var responseBody = await response.transform(utf8.decoder).join();
if (responseBody.isNotEmpty) {
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory();
String filePath = '${appDocumentsDirectory.path}/last_update.txt';
try { // Write most recent time of update to file
await File(filePath).writeAsString('${DateTime.now()}', mode: FileMode.write);
print('Update time written to file');
} catch (error) { print('Error in writing to file: $error');}
// Return relation data from the response body
return Uint8List.fromList(utf8.encode(responseBody));
} else {
......
import 'dart:typed_data';
import 'package:latlong2/latlong.dart';
import '../marker_handler/marker_data.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_maps/maps.dart';
import '../consts.dart';
import 'dart:typed_data';
/// A class containing thickness for each subdivision of the map.
class IceThicknessModel {
......
No preview for this file type
import json
import geopandas as gpd
import pandas as pd
from shapely.geometry import Polygon
......@@ -16,8 +17,13 @@ def get_relation(self, body_of_water: str):
if len(polygons) <= 1:
print("Failed to convert to polygons")
# Convert response data to JSON string
response_json = json.dumps(divide_relation(polygons))
# Divide relation into tiles and append tiles to relation object
tiles = divide_relation(polygons)
# polygon_data = pd.concat([polygon_data, gpd.GeoDataFrame(tiles)], ignore_index=True)
# Transform geojson to json -> syncfusion_flutter_maps lib requires json
geojson_dict = json.loads(polygon_data.to_json())
response_json = json.dumps(geojson_dict)
# Set headers
self.send_response(200)
......@@ -39,12 +45,12 @@ def divide_relation(polygons):
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
if rows == 0 or cols == 0: # Skip polygons that are smaller than the division size
continue
for row in range(rows):
for col in range(cols):
tile_bbox = Polygon([
tile_bbox = Polygon([ # Calculate coordinate for current place in column and row
(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),
......@@ -56,6 +62,16 @@ def divide_relation(polygons):
if len(tiles) <= 1:
print("Failed to divide polygons into tiles")
tiles_json = [{"SubDivID": tile["SubDivID"], "coordinates": list(tile["polygon"].exterior.coords)} for tile in
tiles]
# Format each tile object with coordinate, type, and subdivision id tags
tiles_json = []
for tile in tiles:
coordinates = list(tile["polygon"].exterior.coords)
polygon_json = {
"type": "Polygon",
"coordinates": [[(coord[0], coord[1]) for coord in coordinates]],
"SubDivID": tile["SubDivID"]
}
tiles_json.append(polygon_json)
# Return all tiles for current polygon
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