简体   繁体   English

在Python中创建堆叠栅格图像的numpy数组

[英]Create numpy array of stacked raster image in Python

I'm trying to read a stacked raster image as a numpy array. 我正在尝试将堆叠的栅格图像读取为numpy数组。 Actually I'd like to read all bands. 实际上,我想阅读所有乐队。 But when I check array dimension, there is anything just 0. Please tell me why? 但是当我检查数组维数时,只有0。请告诉我为什么? and what should I do for this? 我应该怎么做?

>>> import numpy, gdal, gdalconst, os, pandas
>>> os.chdir(r'N:\PhenologyMOD09\ImagesUsed\Condition\ndvi\Filter_tiff')
>>> gdal.AllRegister()
>>> inRas = gdal.Open("2000_allbands.tif", gdalconst.GA_ReadOnly)
>>> myarray = numpy.array([gdal.Open("2000_allbands.tif", gdalconst.GA_ReadOnly).ReadAsArray()
                for name, descr in inRas.GetSubDatasets()])

>>> myarray.shape
(0,)

Thanks in advance 提前致谢

Here is a simplified version of what you want to do: 这是您要执行的操作的简化版本:

from osgeo import gdal
inRas = gdal.Open("2000_allbands.tif")
myarray = inRas.ReadAsArray()
print(myarray.shape)  # (num_bands, y_size, x_size)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM