python - 打开大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.
解决方案
你可以在更小的部分上工作,更像是窗户。下面的代码从 (0, 0) 点读取 400x400 窗口。
with rasterio.open('/content/drive/MyDrive/LINEasia/test2.tif') as f:
w = f.read(1, window=Window(0, 0, 400, 400))
推荐阅读
- reactjs - React 中非常快速的 setState 调用的性能问题?
- python - 从不接受位置参数的集合中设置为字典关键字
- c# - 如何取回设计视图?
- wordpress - 注意: register_rest_route 被错误调用
- javascript - 为什么函数“点击”会记住来自 JSON 的数据?
- amazon-web-services - AWS 将文件上传到 S3 REST API - 此请求缺少必需的标头:x-amz-content-sha256
- django - Dajngo 内联表单集和必填字段的错误
- powerbi - 简单的 IF DAX 函数 (PowerBI)
- csv - AWK:如何合并 CSV 文件并消除包含某些值的行?
- swiftui - 如何在选项卡视图中使用公共变量?