Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. def write_blockwise(input_raster, output_raster):
  2. # input_raster and output_raster are gdal class object
  3. """
  4. input_raster = gdal.Open(path_input)
  5. output_raster = gdal.Open(path_output)
  6. """
  7. # Geting dimension of raster
  8. dimension = input_raster.num_band
  9.  
  10. # Iterating over number of bands
  11. for num_band in range(dimension):
  12. print('Processing: Band %d' % (num_band))
  13. input_band = input_raster.ds.GetRasterBand(num_band+1)
  14. output_band = output_raster.GetRasterBand(num_band+1)
  15. block_x, block_y = input_band.GetBlockSize()
  16.  
  17. # We can increase blocksize according our suitability also. It makes no difference
  18. # block_x, block_y = 5000, 5000
  19.  
  20. # Step size
  21. size_x = input_band.XSize
  22. size_y = input_band.YSize
  23.  
  24. # Iterating over total blocks with blocksize as step
  25. for x in range(0, int(size_x), int(block_x)):
  26. if x + block_x < size_x:
  27. col = block_x
  28. else:
  29. col = size_x - x
  30.  
  31. for y in range(0, int(size_y), int(block_y)):
  32. if y + block_y < size_y:
  33. row = block_y
  34. else:
  35. row = size_y - y
  36.  
  37. # Reading specific raster from large TIF
  38. array = input_band.ReadAsArray(x, y, col, row)
  39.  
  40. """
  41. To Do some fancy analysis
  42. """
  43. output_band.WriteArray(array, x, y)
  44. array = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement