如何在python中使用gdal打开geotiff图像? [英] How do I open geotiff images with gdal in python?

查看:549
本文介绍了如何在python中使用gdal打开geotiff图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行以下代码:

I am trying to run the following code:

from osgeo import gdal
import sys

# this allows GDAL to throw Python Exceptions
src_ds = gdal.Open( "fused.tif" )
src_ds.show()

但是我收到以下错误:

Traceback (most recent call last):
    File ".../gdalopen1.py", line 5, in module src_ds.show()
AttributeError: 'Dataset' object has no attribute 'show'

为什么会这样?

推荐答案

以下代码打开一个光栅文件,并将光栅带读取到一个numpy数组中.

The following code opens a raster file and reads a band of the raster into a numpy array.

from osgeo import gdal
ds = gdal.Open('input.tif', gdal.GA_ReadOnly)
rb = ds.GetRasterBand(1)
img_array = rb.ReadAsArray()

这篇关于如何在python中使用gdal打开geotiff图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆