gpt4 book ai didi

python - gdal 2.1栅格化

转载 作者:太空狗 更新时间:2023-10-30 02:28:01 27 4
gpt4 key购买 nike

在 gdal 2.1 中使用 gdal.Rasterize 时是否可以设置数据类型(Byte、Float32)?目前,我使用 gdal.Translate 转换为字节,但效率很低。

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' ...)

但如果可能的话,我宁愿避免这种情况。有什么想法吗?

最佳答案

这已在 GDAL 2.1.3 中修复。以前,数据类型是硬编码的,不会在 Python 绑定(bind)中公开。参见 https://trac.osgeo.org/gdal/ticket/6710 .

关于python - gdal 2.1栅格化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38399632/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com