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

yipeiwu_com6年前Python基础

如下所示:

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格式图片。

以上这篇利用python GDAL库读写geotiff格式的遥感影像方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python禁用键鼠与提权代码实例

要求 利用python实现禁用键盘鼠标 思路 经过查阅资料目前最好的办法是采用ctypes中的dll文件进行编写 from ctypes import * improt time...

Python中针对函数处理的特殊方法

很多语言都提供了对参数或变量进行处理的机制,作为灵活的Python,提供了一些针对函数处理的特殊方法filter(function, sequence): 对sequence中的item...

Python简直是万能的,这5大主要用途你一定要知道!(推荐)

从2015开始国内就开始慢慢接触Python了,从16年开始Python就已经在国内的热度更高了,目前也可以算的上"全民Python"了。 众所周知小学生的教材里面已经有Python了,...

pip matplotlib报错equired packages can not be built解决

pip安装matplotlib 在centos6.5 64bit上用pip安装matplotlib时候报错: * The following required packages ca...

Python模拟登录的多种方法(四种)

Python模拟登录的多种方法(四种)

正文 方法一:直接使用已知的cookie访问 特点:   简单,但需要先在浏览器登录 原理:   简单地说,cookie保存在发起请求的客户端中,服务器利用cookie来区分不同的客户端...