【发布时间】:2016-07-15 15:15:15
【问题描述】:
在 gdal 2.1 中使用 gdal.Rasterize 时是否可以设置数据类型(Byte, Float32)?目前,我使用 gdal.Translate 转换为 Byte,但这效率低下。
tif = my/target.tif
shp = my/source.shp
tiftemp = my/temp/solution.tif
rasterizeOptions = gdal.RasterizeOptions(xRes=20, yRes=20, allTouched=True etc.)
gdal.Rasterize(tiftemp, shp, options=rasterizeOptions)
#translate to Byte data type (not supported by Rasterize?)
gdal.Translate(tif, tiftemp, outputType=gdal.GDT_Byte,
creationOptions=['COMPRESS=PACKBITS')
我知道可以使用
subprocess.check_call('gdal_rasterize', '-ot', 'byte' ...)
但如果可能的话,我宁愿避免这种情况。有什么想法吗?
【问题讨论】:
-
只要
tifftemp- 您要栅格化的数据集设置为正确的类型,就可以了。 -
gdal.RasterizeOptions(outputType=gdal.GDT_Byte) 引发 TypeError: RasterizeOptions() got an unexpected keyword argument 'outputType'