-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportjson.py
34 lines (24 loc) · 884 Bytes
/
exportjson.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
import sys
import os
from osgeo import gdal
import json
INPUT_FOLDER = 'input'
kwargs = {
'allMetadata':True,
'format':'json',
}
for subdir, dirs, files in os.walk(INPUT_FOLDER):
for file in files:
filepath = '{}{}{}'.format(subdir, os.sep, file)
if (filepath.endswith(".tif") | filepath.endswith(".tiff")):
try:
ds = gdal.Open(filepath, gdal.GA_ReadOnly)
data = gdal.Info(ds,**kwargs)
filedata = open('{}.json'.format(filepath.split('.')[0]),'w')
json.dump(data,filedata)
print('Pid {} was completed successfully'.format(file.split('.')[0]))
except RuntimeError as e:
print('Unable to open {}'.format(filepath))
print(e)
sys.exit(1)
filedata.close()