r.in.gdalwarp.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: r.in.gdalwarp
  5. #
  6. # AUTHOR(S): Cedric Shock, 2006
  7. # Pythonized by Martin Landa <landa.martin gmail.com>, 2009
  8. #
  9. # PURPOSE: To warp and import data
  10. # (based on Bash script by Cedric Shock)
  11. #
  12. # COPYRIGHT: (C) 2009 Martin Landa, and GRASS development team
  13. #
  14. # This program is free software under the GNU General
  15. # Public License (>=v2). Read the file COPYING that
  16. # comes with GRASS for details.
  17. #
  18. #############################################################################
  19. #%module
  20. #% description: Warps and imports GDAL supported raster file complete with correct NULL values
  21. #% keywords: raster
  22. #% keywords: rotate
  23. #% keywords: reproject
  24. #%end
  25. #%flag
  26. #% key: p
  27. #% description: Don't reproject the data, just patch it
  28. #%end
  29. #%flag
  30. #% key: e
  31. #% description: Extend location extents based on new dataset
  32. #%end
  33. #%flag
  34. #% key: c
  35. #% description: Make color composite image if possible
  36. #%end
  37. #%flag
  38. #% key: k
  39. #% description: Keep band numbers instead of using band color names
  40. #%end
  41. #%option G_OPT_F_INPUT
  42. #% label: Name of raster file or files to be imported
  43. #% description: If multiple files are specified they will be patched together.
  44. #% multiple: yes
  45. #%end
  46. #%option
  47. #% key: output
  48. #% type: string
  49. #% label: Prefix for resultant raster maps.
  50. #% description: Each band will be name output.bandname
  51. #% required : yes
  52. #%end
  53. #%option
  54. #% key: s_srs
  55. #% type: string
  56. #% description: Source projection in gdalwarp format
  57. #% required : yes
  58. #%end
  59. #%option
  60. #% key: method
  61. #% type: string
  62. #% description: Reprojection method to use
  63. #% options:near,bilinear,cubic,cubicspline
  64. #% answer:near
  65. #% required: yes
  66. #%end
  67. #%option
  68. #% key: warpoptions
  69. #% type: string
  70. #% description: Additional options for gdalwarp
  71. #% required : no
  72. #%end
  73. import os
  74. import sys
  75. import atexit
  76. from grass.script import core as grass
  77. path = os.path.join(os.getenv('GISBASE'), 'etc', 'r.in.wms')
  78. sys.path.append(path)
  79. import gdalwarp
  80. def cleanup():
  81. if tmp:
  82. grass.run_command('g.remove', rast = tmp, quiet = True)
  83. def main():
  84. # show progress infromation and grass.info() by default
  85. os.environ['GRASS_VERBOSE'] = '1'
  86. return gdalwarp.GDALWarp(flags, options).run()
  87. if __name__ == "__main__":
  88. options, flags = grass.parser()
  89. tmp = None
  90. atexit.register(cleanup)
  91. sys.exit(main())