_rat = subprocess.check_output('gdalinfo -json ' + dataset_uri, shell=True)
I want to extract the raster attribute table of a .tif file. In the command above, I am able to get the info into _rat
but not sure how to extract the rat
section from _rat. Any suggestions?
In your code, _rat
is a string that is valid JSON. You can convert that JSON into a python dict
that will allow you to access the elements with ease. gdalinfo
doesn't provide the full raster attribute table as I recall, but there is still band-level statistics that are meaningful.
import json
import subprocess
dataset_uri = 'input.tif'
_rat = subprocess.check_output('gdalinfo -json ' + dataset_uri, shell=True)
data = json.loads(_rat) # load json string into dictionary
print data
# to get band-level data
bands = data['bands']
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments