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

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

如下所示:


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

标签:python,GDAL,geotiff
0
投稿

猜你喜欢

  • Python3自动生成MySQL数据字典的markdown文本的实现

    2021-04-29 15:21:18
  • asp日期函数运用--生成简单的日历

    2008-08-15 13:47:00
  • Python虚拟环境Virtualenv使用教程

    2022-04-15 00:22:21
  • 基于Go Int转string几种方式性能测试

    2024-05-08 10:17:04
  • 浅谈django的render函数的参数问题

    2022-07-10 18:39:20
  • Django实现上传图片功能

    2022-01-06 13:57:44
  • SQLServer 跨库查询实现方法

    2024-01-29 02:02:25
  • Python实现曲线拟合的最小二乘法

    2022-03-24 16:13:25
  • 关于vue中的时间格式转化问题

    2024-05-13 09:44:07
  • python:目标检测模型预测准确度计算方式(基于IoU)

    2023-04-17 08:51:19
  • Python使用poplib模块和smtplib模块收发电子邮件的教程

    2023-11-02 14:58:34
  • asp如何编写sql语句来查询|搜索数据记录

    2008-10-09 12:35:00
  • 如何得到数据库中所有表名 表字段及字段中文描述

    2024-01-24 23:58:40
  • 公网远程访问局域网SQL Server数据库

    2024-01-22 01:38:21
  • Python类的继承、多态及获取对象信息操作详解

    2023-09-09 21:27:52
  • Ubuntu Server 16.04下mysql8.0安装配置图文教程

    2024-01-21 21:54:37
  • CentOS 5.5使用yum来安装LAMP(php运行环境)

    2023-11-14 12:15:52
  • python编码最佳实践之总结

    2023-02-07 21:04:44
  • pandas pd.cut()与pd.qcut()的具体实现

    2022-08-03 03:41:36
  • Python中字典的基本知识初步介绍

    2021-08-25 11:41:40
  • asp之家 网络编程 m.aspxhome.com