首页 > 解决方案 > 打开大geotif文件

问题描述

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

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. 

标签: pythonrasterramgeopandasgeotiff

解决方案


你可以在更小的部分上工作,更像是窗户。下面的代码从 (0, 0) 点读取 400x400 窗口。

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

推荐阅读