1

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.

asked Aug 19, 2015 at 11:20
1
  • Can you share some info about the GDAL version, rasterio version, stack trace, operating system, and how you installed rasterio? Commented Aug 19, 2015 at 15:46

1 Answer 1

1

@geowurster's request on stack trace made me do one more debugging round. The raster's dimensions were 5033x5665 pixels, and I found that it crashes while writing the tile including pixels (0-63)x(4992-5055). I assigned the dimensions to the new raster in the wrong order, so it tried to write outside the raster. I switched the shape indexes and it works:

with rasterio.open(ndviPath,'w',driver='GTiff', width=src.shape[1], height=src.shape[0], count=1, dtype=np.float32) as dst:
answered Aug 20, 2015 at 6:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.