separated linking with country and airport

pull/78/head
Konstantin Gründger 2020-11-20 11:49:15 +01:00
rodzic 23abb0955e
commit 5234107606
1 zmienionych plików z 11 dodań i 4 usunięć

Wyświetl plik

@ -339,11 +339,19 @@ def receiver_position_csv_strings_to_db(lines):
agl = EXCLUDED.agl;
""")
# Update receiver country and nearest airport
# Update receiver country
cursor.execute(f"""
UPDATE receivers AS r
SET
country_id = c.gid
FROM countries AS c
WHERE r.country_id IS NULL AND ST_Within(r.location, c.geom);
""")
# Update receiver airport
cursor.execute(f"""
UPDATE receivers AS r
SET
country_id = c.gid,
airport_id = (
SELECT id
FROM airports AS a
@ -353,8 +361,7 @@ def receiver_position_csv_strings_to_db(lines):
ORDER BY ST_DistanceSphere(a.location, r.location)
LIMIT 1
)
FROM countries AS c
WHERE r.country_id IS NULL AND ST_Within(r.location, c.geom);
WHERE r.airport_id IS NULL;
""")
# Insert all the beacons