-
Notifications
You must be signed in to change notification settings - Fork 0
/
out_geojson.py
74 lines (57 loc) · 1.82 KB
/
out_geojson.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import json
import sqlite3
conn = sqlite3.connect("asr.sqlite3")
conn.row_factory = sqlite3.Row
cur = conn.cursor()
count = 0
coords = {
row["unique_system_identifier"]: row
for row in cur.execute("SELECT * FROM application_coordinates")
if row["longitude_total_seconds"] and row["latitude_total_seconds"]
}
print("loaded", len(coords), "coords")
entities = {
row["unique_system_identifier"]: row
for row in cur.execute("SELECT * FROM registration_entities")
}
print("loaded", len(entities), "registration entities")
features = []
for row in cur.execute("SELECT * FROM registration_data"):
if row["date_dismantled"] or not row["date_constructed"]:
continue
if row["unique_system_identifier"] not in coords:
continue
co = coords[row["unique_system_identifier"]]
lon = (float(co["longitude_total_seconds"]) / 3600) * (
-1 if co["longitude_direction"] == "W" else 1
)
lat = (float(co["latitude_total_seconds"]) / 3600) * (
-1 if co["latitude_direction"] == "S" else 1
)
properties = {}
properties.update({f"reg_{key}": value for key, value in dict(row).items()})
properties.update(
{
f"entity_{key}": value
for key, value in dict(entities[row["unique_system_identifier"]]).items()
}
)
features.append(
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [lon, lat],
},
"properties": properties,
}
)
print("writing", len(features), "features")
geojson_data = {
"type": "FeatureCollection",
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}},
"features": features,
}
with open("asr.geojson", "w") as f:
json.dump(geojson_data, f)
print("all set!")