GDAL分幅数据切瓦片。不拼接直接切

    技术2022-07-14  70

    gdal提供很多现成的工具比如gdal2tiles是可以生成瓦片。但是在处理分幅tif的时候需要修改一些代码达到分幅切片的目的。

    首先添加一个函数

    def combine(former_tile, dstile): for band in range(dstile.RasterCount): array = numpy.max([former_tile.GetRasterBand(band + 1).ReadAsArray(), dstile.GetRasterBand(band + 1).ReadAsArray()], axis=0) dstile.GetRasterBand(band + 1).WriteArray(array)

    下一步找到

    CreateCopy 关键词 入下图修改。

    if os.path.exists(tilefilename): combine(gdal.Open(tilefilename), dstile) out_driver.CreateCopy(tilefilename, dstile, strict=0)

     

    python gdal2tiles.py -v -z 1-13 --resampling=average G:\land\fromglc10v01_0_8.tif G:\tiles

     

     

     

    Processed: 0.016, SQL: 9