r.in.gdalwarp.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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
  42. #% key: input
  43. #% type: string
  44. #% label: Raster file or files to be imported
  45. #% description: If multiple files are specified they will be patched together.
  46. #% multiple: yes
  47. #% required : yes
  48. #%end
  49. #%option
  50. #% key: output
  51. #% type: string
  52. #% description: Name for resultant raster map. Each band will be name output.bandname
  53. #% required : yes
  54. #%end
  55. #%option
  56. #% key: s_srs
  57. #% type: string
  58. #% description: Source projection in gdalwarp format
  59. #% required : yes
  60. #%end
  61. #%option
  62. #% key: method
  63. #% type: string
  64. #% description: Reprojection method to use
  65. #% options:near,bilinear,cubic,cubicspline
  66. #% answer:near
  67. #% required: yes
  68. #%end
  69. #%option
  70. #% key: warpoptions
  71. #% type: string
  72. #% description: Additional options for gdalwarp
  73. #% required : no
  74. #%end
  75. import os
  76. import sys
  77. import atexit
  78. from grass.script import core as grass
  79. path = os.path.join(os.getenv('GISBASE'), 'etc', 'r.in.wms')
  80. sys.path.append(path)
  81. import gdalwarp
  82. def cleanup():
  83. if tmp:
  84. grass.run_command('g.remove', rast = tmp, quiet = True)
  85. def main():
  86. # show progress infromation and grass.info() by default
  87. os.environ['GRASS_VERBOSE'] = '1'
  88. return gdalwarp.GDALWarp(flags, options).run()
  89. if __name__ == "__main__":
  90. options, flags = grass.parser()
  91. tmp = None
  92. atexit.register(cleanup)
  93. sys.exit(main())