Abhisek92

set_nodata.py

Mar 24th, 2022 (edited)
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import numpy as np
  2. import rasterio as rio
  3.  
  4. def set_nodata(image_path, nodata=0):
  5.     with rio.open(image_path, 'r+') as src:
  6.         src.nodata = np.array(nodata, dtype=np.dtype(src.meta['dtype'])).item()
  7.  
  8. if __name__ == '__main__':
  9.     import argparse
  10.     parser = argparse.ArgumentParser(
  11.         description=(
  12.             'Set user provided no-data value to specified geo-image'
  13.         )
  14.     )
  15.     parser.add_argument(
  16.         '-i', '--input',
  17.         metavar='Input Image',
  18.         action='store',
  19.         type=str,
  20.         required=True,
  21.         dest='import_path',
  22.         help='Specify input image path'
  23.     )
  24.     parser.add_argument(
  25.         '-v', '--value',
  26.         metavar='No-data Value',
  27.         action='store',
  28.         type=str,
  29.         required=True,
  30.         dest='nd',
  31.         help='Specify no-data value'
  32.     )
  33.     args = parser.parse_args()
  34.     set_nodata(args.import_path, float(args.nd))
  35.  
Add Comment
Please, Sign In to add comment