Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinate sanity check #716

Merged
merged 16 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data/coords_override.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"0510":{
quarz12 marked this conversation as resolved.
Show resolved Hide resolved
"lat":48.14884,
"lon":11.56790
}
}
25 changes: 24 additions & 1 deletion data/processors/coords.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import copy
import logging

import json
quarz12 marked this conversation as resolved.
Show resolved Hide resolved
import utm
from processors.public_transport import _distance_via_great_circle
quarz12 marked this conversation as resolved.
Show resolved Hide resolved
quarz12 marked this conversation as resolved.
Show resolved Hide resolved


def assert_buildings_have_coords(data):
Expand All @@ -23,6 +24,12 @@ def assign_coordinates(data):
Assign coordinates to all entries (except root) and make sure they match the data format.
"""
# TODO: In the future we might calculate the coordinates from OSM data
with open("coords_override.json") as file:
overrides=json.load(file)

for iid, override in overrides.items():
override["source"]="manual_override"
data[iid]["coords"]=override
quarz12 marked this conversation as resolved.
Show resolved Hide resolved

error = False

Expand Down Expand Up @@ -118,9 +125,25 @@ def check_coords(input_data):
f"(UTM coordinates are either from the Roomfinder or automatically calculated).",
)

def validate_coords(input_data):
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
for iid, data in input_data.items():
if not data["type"] =="room":
continue
coords=data["coords"]
parent_coords=input_data[data["parents"][-1]]["coords"]
quarz12 marked this conversation as resolved.
Show resolved Hide resolved

if coords["lat"]==parent_coords["lat"] and coords["lon"]==parent_coords["lon"]:
continue

CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
distance_to_parent=_distance_via_great_circle(coords["lat"],coords["lon"],parent_coords["lat"],parent_coords["lon"])

if distance_to_parent>100:
quarz12 marked this conversation as resolved.
Show resolved Hide resolved
logging.warn(f"{iid} {data['coords']} has a distance of {distance_to_parent}m to " +
f"{data['parents'][-1]} {input_data[data['parents'][-1]]['coords']}")
quarz12 marked this conversation as resolved.
Show resolved Hide resolved

def add_and_check_coords(data):
"""Add coordinates to all entries and check for issues"""
assert_buildings_have_coords(data)
assign_coordinates(data)
check_coords(data)
validate_coords(data)