gdal 2.1栅格化 [英] gdal 2.1 Rasterize
本文介绍了gdal 2.1栅格化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在gdal 2.1中使用gdal时是否可以设置数据类型(Byte,Float32)?当前,我使用gdal.Translate转换为Byte,但这效率低下.
Is it possible to set the data type (Byte, Float32) when using gdal.Rasterize in gdal 2.1? Currently, I use gdal.Translate to convert to Byte, but this is inefficient.
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' ...)
,但我希望尽可能避免这种情况.有什么想法吗?
but I would prefer to avoid this if possible. Any ideas?
推荐答案
如果您使用的是gdal 2.1.2,请使用gdal.RasterizeOptions(),就像在命令行上使用它一样:
If you are in gdal 2.1.2, use gdal.RasterizeOptions() as if you were using it on the command line:
opts_str = '-ot Byte'
rast_opts = gdal.RasterizeOptions(options=opts_str)
这篇关于gdal 2.1栅格化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文