supun nayake
supun nayake

Reputation: 17

Open large geotif file

I have very large geotif file. But I can not open it in colabs. RAM is not enough. So all the time I run it began crash. can come one help me with this?

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. 

Upvotes: 0

Views: 1008

Answers (1)

Baran Bursalı
Baran Bursalı

Reputation: 360

You can work on smaller portions more like windows. Below code reads 400x400 window from (0, 0) point.

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

Upvotes: 3

Related Questions