Advertisement
Abhisek92

windowed_rw.py

Sep 8th, 2021
1,300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import rasterio as rio
  2.  
  3. src_path = "specify input image path"
  4. dst_path = "specify output image path"
  5. win_height = 1024  # Change as required
  6. win_width = 1024  # Change as required
  7.  
  8.  
  9. with rio.open(src_path, 'r') as src:
  10.     meta = src.profile.copy()
  11.     img_h = src.height
  12.     img_w = src.width
  13.     r_offsets = range(0, src.height, win_height))
  14.     c_offsets = range(0, src.width, win_width))
  15.     for r_off, c_off in zip(r_offsets, c_offsets):
  16.         win = Window(row_off=r_off, col_off=c_off, height=win_height, width=win_width)
  17.         img = src.read(window=win)
  18.         # Do your processing here
  19.        
  20.         # update meta for output image as required
  21.         # for example meta['count'] = 64 to change the no. of bands in the output image
  22.         with rio.open(dst_path, 'w', **meta) as dst:
  23.             dst.write(img) # Write array to file, not necessarily have to image
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement