numpy array to geotif using gdal

2021-09-18  本文已影响0人  ab02f58fd803

使用GADL库进行读取和保存

import gdal

file = "GLASS_FAPAR_2001217_GEO500m_NEChina.tif"
ds = gdal.Open(file)
band = ds.GetRasterBand(1)
arr = band.ReadAsArray()
[rows, cols] = arr.shape

arr_out = arr.copy()

driver = gdal.GetDriverByName("GTiff")
outFileName = 'new.tif'
outdata = driver.Create(outFileName, cols, rows, 1,  band.DataType)
outdata.SetGeoTransform(ds.GetGeoTransform())##sets same geotransform as input
outdata.SetProjection(ds.GetProjection())##sets same projection as input
outdata.GetRasterBand(1).WriteArray(arr_out)
#outdata.GetRasterBand(1).SetNoDataValue(10000)##if you want these values transparent
outdata.FlushCache() ##saves to disk!!
outdata = None
band=None
ds=None
上一篇下一篇

猜你喜欢

热点阅读