利用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实现随机创建电话号码的方法示例

本文实例讲述了Python实现随机创建电话号码的方法。分享给大家供大家参考,具体如下: 当需要随机的生成一些电话号码的时候,可以使用以下脚本,简单实用,第一个列表中 list列表中的数字...

基于Python 装饰器装饰类中的方法实例

基于Python 装饰器装饰类中的方法实例

title: Python 装饰器装饰类中的方法 comments: true date: 2017-04-17 20:44:31 tags: ['Python', 'Decorate'...

Python 数据可视化pyecharts的使用详解

Python 数据可视化pyecharts的使用详解

什么是pyecharts?   pyecharts 是一个用于生成 Echarts 图表的类库。 echarts是百度开源的一个数据可视化 JS 库,主要用于数据可视化。pyechart...

PyTorch实现更新部分网络,其他不更新

torch.Tensor.detach()的使用 detach()的官方说明如下: Returns a new Tensor, detached from the current gra...

利用python打开摄像头及颜色检测方法

最近两周由于忙于个人项目,一直未发言了,实在是太荒凉了。。。。,上周由于项目,见到Python的应用极为广泛,用起来也特别顺手,于是小编也开始着手学习Python,…下面我就汇报下今天的...