利用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装饰器decorator用法实例

本文实例讲述了Python装饰器decorator用法。分享给大家供大家参考。具体分析如下: 1. 闭包(closure) 闭包是Python所支持的一种特性,它让在非global sc...

python中的多线程实例教程

本文以实例形式较为详细的讲述了Python中多线程的用法,在Python程序设计中有着比较广泛的应用。分享给大家供大家参考之用。具体分析如下: python中关于多线程的操作可以使用th...

pytorch使用 to 进行类型转换方式

pytorch使用 to 进行类型转换方式

在程序中,有多种方法进行强制类型转换。 本博文将介绍一个非常常用的方法:to()方法。 我们通常使用它来进行GPU和CPU的类型转换,但其实也可以用来进行torch的dtype转换。 常...

pandas数据筛选和csv操作的实现方法

1. 数据筛选 a b c 0 0 2 4 1 6 8 10 2 12 14 16 3 18 20 22 4 24 26 28 5 30 32 34 6 36 38 40 7 42...

基于DataFrame筛选数据与loc的用法详解

DataFrame筛选数据与loc用法 python中pandas下的DataFrame是一个很不错的数据结构,附带了许多操作、运算、统计等功能。 如何从一个DataFrame中筛选中出...