Advertisement
Abhisek92

gen_fig.py

Sep 9th, 2021
1,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. from pathlib import Path
  2. import rasterio as rio
  3. import numpy as np
  4.  
  5. src_path = Path("")
  6. dst_path = Pat("")
  7. downscale_factor = 10.0
  8.  
  9. with rio.open(src_path, 'r') as src:
  10.     meta = src.meta.copy()
  11.     src_t = meta['transform']
  12.     view_h = int(meta['height'] / downscale_factor)
  13.     view_w = int(meta['width'] / downscale_factor)
  14.    
  15.     view = src.read(
  16.         out_shape=(view_h, view_w),
  17.         resampling=1,
  18.         boundless=False
  19.     )
  20.    
  21.     meta['height'] = view_h
  22.     meta['width'] = view_w
  23.     meta['transform'] = src_t * src_t.scale(downscale_factor, downscale_factor)
  24.     with rio.open(dst_path, 'w', **meta) as dst:
  25.         dst.write(view)
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement