[英]Extracting raster attribute table from raster using gdalinfo
_rat = subprocess.check_output('gdalinfo -json ' + dataset_uri, shell=True)
I want to extract the raster attribute table of a .tif file. 我想提取.tif文件的栅格属性表。 In the command above, I am able to get the info into
_rat
but not sure how to extract the rat
section from _rat. 在上面的命令中,我能够将信息获取到
_rat
但是不确定如何从_rat中提取出rat
部分。 Any suggestions? 有什么建议么?
In your code, _rat
is a string that is valid JSON. 在您的代码中,
_rat
是有效的JSON字符串。 You can convert that JSON into a python dict
that will allow you to access the elements with ease. 您可以将该JSON转换为python
dict
,从而使您可以轻松访问元素。 gdalinfo
doesn't provide the full raster attribute table as I recall, but there is still band-level statistics that are meaningful. 我记得,
gdalinfo
没有提供完整的栅格属性表,但是仍然有有意义的波段级统计信息。
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']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.