-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson2geojson_point.py
More file actions
90 lines (68 loc) · 2.41 KB
/
Copy pathjson2geojson_point.py
File metadata and controls
90 lines (68 loc) · 2.41 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import json
def latitude_dms_to_decimal(coordinate):
degrees = int(coordinate[:2])
minutes = int(coordinate[2:4])
seconds = float(coordinate[4:-1])
direction = coordinate[-1]
decimal = degrees + (minutes / 60) + (seconds / 3600)
if direction in ['S', 'W']:
decimal = -decimal
return decimal
def longitude_dms_to_decimal(coordinate):
degrees = int(coordinate[:3])
minutes = int(coordinate[3:5])
seconds = float(coordinate[5:-1])
direction = coordinate[-1]
decimal = degrees + (minutes / 60) + (seconds / 3600)
if direction in ['S', 'W']:
decimal = -decimal
return decimal
def convert_json_to_geojson(json_data):
features = []
for item in json_data:
if "Data" in item:
for obj in item["Data"]["Object"]:
properties = {
"Identification": obj["Identification"],
"Name": obj["Name"],
"Elevation_FT": obj["Elevation_FT"],
"Elevation_M": obj["Elevation_M"]
}
for detail in obj['Runway_detail']:
properties2 = {
"runway": detail['Runway'],
"surface": detail['Surface']
}
properties.update(properties2)
latitude = latitude_dms_to_decimal(obj["Geo_lat"])
longitude = longitude_dms_to_decimal(obj["Geo_long"])
print(str(latitude) + " - " + str(longitude))
geometry = {
"type": "Point",
"coordinates": [longitude, latitude]
}
feature = {
"type": "Feature",
"geometry": geometry,
"properties": properties
}
features.append(feature)
geojson_data = {
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": features
}
return geojson_data
# Read JSON file
with open('input.json') as json_file:
json_data = json.load(json_file)
# Convert JSON to GeoJSON
geojson_data = convert_json_to_geojson(json_data)
# Write GeoJSON to file
with open('output.geojson', 'w') as geojson_file:
json.dump(geojson_data, geojson_file, indent=4)