With the answer on my previous question, I was able to set up reading a raster by blocks. I did some computation and now I try to write the result into another raster. However, the program fails with error code 139 and Segmentation fault (core dumped)
. My code:
with rasterio.drivers():
with rasterio.open(asterPath,'r') as src:
with rasterio.open(ndviPath,'w',driver='GTiff', width=src.shape[0], height=src.shape[1], count=1, dtype=np.float32) as dst:
for index, window in src.block_windows(2):
red = src.read(2, window=window)
nir = src.read(3, window=window)
#compute ndvi as NumPy 2d array, dtype float32
dst.write_band(1,ndvi,window=window)
As a sanity check, I tried to fill ndvi array with zeros. It worked outside the loop, but not within, so I must have misunderstood something about writing by block with rasterio. All I know about rasterio is this manual (including the other doc files in the same repository). So how to save the NDVI data to a raster by block?
I'm on Ubuntu 14.04 and I use Python 2.7, Gdal 1.10.1, NumPy 1.8.2 and Rasterio 0.26.0 installed from source the way suggested for Linux at the Rasterio site.