使用时,rasterio
我可以执行以下任一方法来获取栅格的单个波段:
import rasterio
import numpy as np
dataset = rasterio.open('filepath')
# note that if you have the full dataset read in with image = dataset.read() you can do:
image = dataset.read()
print(image.shape)
red_band = image[2, :, :] # this
print(red_band.shape)
# which is equal to simply doing
red_band_read = dataset.read(3)
print(red_band_read.shape)
if np.array_equal(red_band_read, red_band):
print('They are the same.')
它会打印出来:
(8, 250, 250)
(250, 250)
(250, 250)
They are the same.
但我很好奇哪个“更好”?我假设索引到 numpy 数组比从文件中读取要快得多,但是打开其中一些大型卫星图像会占用大量内存。有什么好的理由去做其中一个吗?