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, rotate, reproject
  22. #%end
  23. #%flag
  24. #% key: p
  25. #% description: Don't reproject the data, just patch it
  26. #%end
  27. #%flag
  28. #% key: e
  29. #% description: Extend location extents based on new dataset
  30. #%end
  31. #%flag
  32. #% key: c
  33. #% description: Make color composite image if possible
  34. #%end
  35. #%flag
  36. #% key: k
  37. #% description: Keep band numbers instead of using band color names
  38. #%end
  39. #%option
  40. #% key: input
  41. #% type: string
  42. #% label: Raster file or files to be imported
  43. #% description: If multiple files are specified they will be patched together.
  44. #% multiple: yes
  45. #% required : yes
  46. #%end
  47. #%option
  48. #% key: output
  49. #% type: string
  50. #% description: Name for resultant raster map. 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:nearest,bilinear,cubic,cubicspline
  64. #% answer:nearest
  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. import 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())