打开大型 geotif 文件

问题描述

我有非常大的 geotif 文件。但我无法在 colab 中打开它。内存不够。所以我一直在运行它开始崩溃。可以过来帮我吗?

import numpy as np
from Rasterio.plot import show
import os
import matplotlib.pyplot as plt
%matplotlib inline

# Data dir
data_dir = "data"

# Filepath
fp = os.path.join(data_dir,"/content/drive/MyDrive/LINEasia/test2.tif")

# Open the raster file in read mode
raster = Rasterio.open(fp)

# Read NIR channel (channel number 4)
nir = raster.read(1)

# Calculate some stats to check the data
#print(red.mean())
print(nir.mean())
print(type(nir))

# Visualize
show(nir,cmap='terrain')
}```

uncompressed file size around 3GB. 

解决方法

您可以处理更小的部分,更像是窗户。下面的代码从 (0,0) 点读取 400x400 窗口。

with rasterio.open('/content/drive/MyDrive/LINEasia/test2.tif') as f:
    w = f.read(1,window=Window(0,400,400))