-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_createGeoJsonFortune500.py
40 lines (32 loc) · 1.22 KB
/
6_createGeoJsonFortune500.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
import json
# create a geojson file from Fortune 500 json data
def convert_to_geojson(input_file, output_file):
with open(input_file, 'r') as f:
data = json.load(f)
geojson = {
"type": "FeatureCollection",
"features": []
}
for item in data:
coordinates = item["headquarterCoordinates"].replace("Point(", "").replace(")", "").split()
feature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [float(coordinates[0]), float(coordinates[1])]
},
"properties": {
"rank": item["rank"],
"company": item["company"],
"revenues": item["revenues"],
"profits": item["profits"],
"year": item["year"],
"qid": item["qid"],
"wikiDataName": item["wikiDataName"],
"industry": item["industry"]
}
}
geojson["features"].append(feature)
with open(output_file, 'w') as f:
json.dump(geojson, f, indent=4)
convert_to_geojson('./data_fortune500/uniqueCompaniesWithQidsAndWithIndustrySector.json', './data_fortune500/x_sp500Companies.geojson')