网络编程
位置:首页>> 网络编程>> Python编程>> 利用python GDAL库读写geotiff格式的遥感影像方法

利用python GDAL库读写geotiff格式的遥感影像方法

作者:彩虹弯弯  发布时间:2023-08-31 13:15:06 

标签:python,GDAL,geotiff

如下所示:


from osgeo import gdal
import numpy as np
def read_tiff(inpath):
 ds=gdal.Open(inpath)
 row=ds.RasterXSize
 col=ds.RasterYSize
 band=ds.RasterCount
 geoTransform=ds.GetTransform()
 proj=ds.GetTransform()
 data=np.zeros([row,col,band])
 for i in range(band):
  dt=ds.GetRasterBand(1)
  data[:,:,i]=dt.ReadAsArray(0,0,col,row)
 return data

def array2raster(outpath,array,geoTransform,proj):
cols=array.shape[1]
rows=array.shape[0]
driver=gdal.GetDriverByName('Gtiff')
outRaster=driver.Create(newRasterfn,cols,rows,1,gdal.GDT_Byte)
outRaster.SetGeoTransform(geoTransform)#参数2,6为水平垂直分辨率,参数3,5表示图片是指北的
outband=outRaster.GetRasterBand(1)
outband.WriteArray(array)
outRaster.SetProjection(proj)#将几何对象的数据导出为wkt格式
outRaster.FlushCache()

if _name=="_main_":

data,geoTransform,proj=read_tiff('d:/a.tif')

array2raster("d:/b.tif",np.zeros[2400,2400],geoTransform,proj)

利用python GDAL库读写geotiff格式的遥感影像,并生成与原影像具有相同地理坐标和投影坐标的geotiff格式图片。

来源:https://blog.csdn.net/qq_20340733/article/details/78316347

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com