forked from hotosm/GDAL_scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
odmimages2csv.py
executable file
·50 lines (44 loc) · 1.49 KB
/
odmimages2csv.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
#!/usr/bin/python3
"""
Takes the images.json output from OpenDroneMap and writes a CSV file suitable
for easy viewing as a 3D point layer in QGIS.
NOT a general tool. Unlikely to produce useful results for an arbitrary json
file, but quite likely to work well for the images.json file produced by ODM.
Takes two positional arguments:
1. Input file, /path/to/images.json file from an OpenDroneMap run
2. Output file, /path/to/images.csv would be a sensible choice
"""
import sys
import json
import csv
def odmimages2csv(infile):
"""
Parse flat json and return list of lists suitable for writing as csv.
Assumes all json objects have the same keys. Uses the keys of the first
json object as a header row, then populates the remaining rows with the
values from those keys for all objects.
"""
f = open(infile)
images = json.load(f)
headers = list(images[0].keys())
rows = []
rows.append(headers)
for image in images:
row = []
for header in headers:
item = image[header]
row.append(item)
rows.append(row)
return rows
if __name__ == '__main__':
"""
Takes two positional arguments:
1. Input file, /path/to/images.json file from an OpenDroneMap run
2. Output file, /path/to/images.csv would be a sensible choice
"""
infile = sys.argv[1]
outfile = sys.argv[2]
imagepoints = odmimages2csv(infile)
with open(outfile, 'w') as of:
w = csv.writer(of)
w.writerows(imagepoints)