import?gdal import?numpy?as?np from?scipy?import?ndimage?as?nd file?=?r"D:\微信公眾號(hào)\數(shù)據(jù)填補(bǔ)\處理前.tif" outfile?=?r"D:\微信公眾號(hào)\數(shù)據(jù)填補(bǔ)\處理后.tif" ds?=?gdal.Open(file) cols?=?ds.RasterXSize rows?=?ds.RasterYSize geo?=?ds.GetGeoTransform() proj?=?ds.GetProjection() band?=?ds.GetRasterBand(1) d_type?=?band.DataType nodata?=?band.GetNoDataValue() data?=?(ds.ReadAsArray()).astype(np.float32) data[data?==nodata]?=?np.nan mask?=?np.isnan(data) ind?=?nd.distance_transform_edt(mask,? ????????????????????????????????return_distances=False,? ????????????????????????????????return_indices=True) data?=?data[tuple(ind)] driver?=?gdal.GetDriverByName("GTiff") outds?=?driver.Create(outfile,?cols,?rows,?1,?d_type) outds.SetGeoTransform(geo) outds.SetProjection(proj) outband?=?outds.GetRasterBand(1) outband.WriteArray(data) outband.SetNoDataValue(nodata)
測(cè)試數(shù)據(jù):
百度網(wǎng)盤(pán):https://pan.baidu.com/s/1ZqAlIe4vGBF7SvTMNhhfrg
密 碼:e3pd