美文网首页
numpy array to geotif using gdal

numpy array to geotif using gdal

作者: ab02f58fd803 | 来源:发表于2021-09-18 16:06 被阅读0次

    使用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
    

    相关文章

      网友评论

          本文标题:numpy array to geotif using gdal

          本文链接:https://www.haomeiwen.com/subject/hdhygltx.html