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

update: calculate lat and lng based on distance in km

parent 2f31ddfe
No related branches found
No related tags found
1 merge request!14Clhp map
Showing with 38 additions and 12 deletions
...@@ -12,7 +12,8 @@ const String mapEndpoint = "update_map"; ...@@ -12,7 +12,8 @@ const String mapEndpoint = "update_map";
// Map variables // Map variables
String selectedLake = 'Mjøsa'; // NB should be initialised to last selected lake String selectedLake = 'Mjøsa'; // NB should be initialised to last selected lake
Uint8List selectedRelation = Uint8List(0); Uint8List selectedRelation = Uint8List(0);
List<Measurement> selectedMarkerList = []; List<Measurement> selectedMeasurements = [];
List<SubDiv> selectedSubdivisions = [];
SubDiv? selectedSubDiv; SubDiv? selectedSubDiv;
LatLng mapCenter = LatLng(60.8000, 10.8471); // NB may not be necessary LatLng mapCenter = LatLng(60.8000, 10.8471); // NB may not be necessary
......
...@@ -86,7 +86,7 @@ class _DefaultPageState extends State<DefaultPage> { ...@@ -86,7 +86,7 @@ class _DefaultPageState extends State<DefaultPage> {
child: ListView( child: ListView(
children: [ children: [
MapContainerWidget( MapContainerWidget(
measurements: selectedMarkerList, measurements: selectedMeasurements,
relation: selectedRelation, relation: selectedRelation,
serverConnection: serverConnection, serverConnection: serverConnection,
), ),
......
...@@ -6,7 +6,7 @@ import 'package:app/consts.dart'; ...@@ -6,7 +6,7 @@ import 'package:app/consts.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../data_classes.dart'; import '../data_classes.dart';
import '../server_requests/fetch_markers.dart'; import '../server_requests/fetch_measurements.dart';
import '../server_requests/fetch_relation.dart'; import '../server_requests/fetch_relation.dart';
/// initialiseState makes three requests to the server, one requesting /// initialiseState makes three requests to the server, one requesting
...@@ -14,6 +14,7 @@ import '../server_requests/fetch_relation.dart'; ...@@ -14,6 +14,7 @@ import '../server_requests/fetch_relation.dart';
/// and the last requesting the list of all system lakes /// and the last requesting the list of all system lakes
Future<void> initialiseState(bool fetchSearchOptions) async { Future<void> initialiseState(bool fetchSearchOptions) async {
bool serverConnection = true; bool serverConnection = true;
bool internetConnection = false;
late Future<List<Measurement>> markerListFuture; late Future<List<Measurement>> markerListFuture;
late Future<Uint8List> relationFuture; late Future<Uint8List> relationFuture;
...@@ -24,7 +25,9 @@ Future<void> initialiseState(bool fetchSearchOptions) async { ...@@ -24,7 +25,9 @@ Future<void> initialiseState(bool fetchSearchOptions) async {
FetchResult fetchResult = await loadMeasurements(); FetchResult fetchResult = await loadMeasurements();
List<Measurement> measurements = fetchResult.measurements; List<Measurement> measurements = fetchResult.measurements;
selectedMarkerList = measurements; selectedMeasurements = measurements;
print("Loaded from files: Meas.len: ${selectedMeasurements.length}, rel.len: ${selectedRelation.length}");
} else { // Try to fetch measurement data from server } else { // Try to fetch measurement data from server
markerListFuture = fetchMeasurements().then((fetchResult) { markerListFuture = fetchMeasurements().then((fetchResult) {
...@@ -52,7 +55,7 @@ Future<void> initialiseState(bool fetchSearchOptions) async { ...@@ -52,7 +55,7 @@ Future<void> initialiseState(bool fetchSearchOptions) async {
//selectedRelation = await relationFuture; //selectedRelation = await relationFuture;
selectedRelation = await relationFuture; // NB update once fixed selectedRelation = await relationFuture; // NB update once fixed
selectedMarkerList = await markerListFuture; selectedMeasurements = await markerListFuture;
} }
} catch (e) { } catch (e) {
// Handle any errors that occur during the initialization process // Handle any errors that occur during the initialization process
......
...@@ -12,7 +12,7 @@ Future<void> _exportIceData() async { ...@@ -12,7 +12,7 @@ Future<void> _exportIceData() async {
final file = File('${directory?.path}/ice_data_$selectedLake.json'); final file = File('${directory?.path}/ice_data_$selectedLake.json');
// Convert JSON data to string // Convert JSON data to string
final jsonString = jsonEncode(selectedMarkerList); final jsonString = jsonEncode(selectedMeasurements);
// Write JSON data to file // Write JSON data to file
await file.writeAsString(jsonString); await file.writeAsString(jsonString);
......
...@@ -37,7 +37,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -37,7 +37,7 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
bool isSatTapped = false; // Satellite button tap state tracker bool isSatTapped = false; // Satellite button tap state tracker
bool isMapTapped = false; // OSM button tap state tracker bool isMapTapped = false; // OSM button tap state tracker
Measurement? selectedMeasurement = selectedMarkerList[0]; Measurement? selectedMeasurement = selectedMeasurements[0];
// Initialise lastUpdate variable from persistent storage if server fetch fails // Initialise lastUpdate variable from persistent storage if server fetch fails
Future<void> checkAndSetLastUpdate() async { Future<void> checkAndSetLastUpdate() async {
......
No preview for this file type
import os import os
import json import json
from math import cos, sqrt, fabs
import random import random
import geopandas as gpd import geopandas as gpd
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
...@@ -8,6 +9,20 @@ from shapely.geometry import Polygon, LineString, MultiLineString ...@@ -8,6 +9,20 @@ from shapely.geometry import Polygon, LineString, MultiLineString
from server.consts import LAKE_RELATIONS_PATH from server.consts import LAKE_RELATIONS_PATH
'''
# 0
starting coordinate (x,y)
# 1
1 deg lat = 111.32km
1 deg lng = 40075km * cos( lat ) / 360
# 2 Formulas for calculating a distance in kilometers to a distance in latitude and longitude
lat = distance_in_km/111.32km
lng = (distance_in_km × 360)/(40075km × cos(lat))
'''
# Read a json file with relation data and send to response object # Read a json file with relation data and send to response object
def cut_map(self, cursor, lake_name: str): def cut_map(self, cursor, lake_name: str):
...@@ -22,10 +37,12 @@ def cut_map(self, cursor, lake_name: str): ...@@ -22,10 +37,12 @@ def cut_map(self, cursor, lake_name: str):
divided_map = [] divided_map = []
for polygon in polygons: dist_in_km = 0.08 # NB placeholder
cell_width = 0.04 cell_size = dist_in_km * 10
cell_height = 0.02 # NB could be calculated based on cell_width and distance from equator cell_width = cell_size / 111.32
cell_height = (cell_size * 360) / (40075 * cos(cell_width))
for polygon in polygons:
lines = create_grid(polygon, cell_width, cell_height) lines = create_grid(polygon, cell_width, cell_height)
lines.append(polygon.boundary) lines.append(polygon.boundary)
lines = unary_union(lines) lines = unary_union(lines)
...@@ -79,6 +96,8 @@ def cut_map(self, cursor, lake_name: str): ...@@ -79,6 +96,8 @@ def cut_map(self, cursor, lake_name: str):
INSERT INTO BodyOfWater(Name) VALUES (?); INSERT INTO BodyOfWater(Name) VALUES (?);
''', (lake_name,)) ''', (lake_name,))
plot_map(divided_map)
write_json_to_file(lake_name, feature_collection) write_json_to_file(lake_name, feature_collection)
self.send_response(200) self.send_response(200)
......
This diff is collapsed.
[ [
"Mj\u00c3\u00b8sa", "Mjøsa",
"Skumsj\u00c3\u00b8en" "Skumsjøen",
"Gjersjøen",
"Gjersjøen",
"Skumsjøen"
] ]
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment