在使用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')
I am aware that it is possible to use
subprocess.check_call('gdal_rasterize', '-ot', 'byte' ...)
但如果有可能的话,我希望避免这种情况。你有什么好主意吗?
tifftemp
- 你正在将其光栅化的数据集设置为正确的类型,那么就应该没问题。 - Benjamin