p.rast.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: p.rast
  5. # AUTHOR(S): Jachym Cepicky, Martin Landa, Hamish Bowman
  6. # Converted to Python by Huidae Cho
  7. # PURPOSE: Displays raster map layer in the active map display window.
  8. # COPYRIGHT: (C) 2009 by The GRASS Development Team
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. ############################################################################
  21. #%module
  22. #% description: Displays raster map layer in the active map display window.
  23. #% keywords: display, raster
  24. #%end
  25. #%flag
  26. #% key: n
  27. #% description: Make null cells opaque
  28. #%end
  29. #%flag
  30. #% key: i
  31. #% description: Invert catlist
  32. #% guisection: Selection
  33. #%end
  34. #%option
  35. #% key: map
  36. #% type: string
  37. #% required: yes
  38. #% multiple: no
  39. #% key_desc: name
  40. #% description: Raster map to be displayed
  41. #% gisprompt: old,cell,raster
  42. #%end
  43. #%option
  44. #% key: catlist
  45. #% type: string
  46. #% required: no
  47. #% multiple: yes
  48. #% key_desc: cat[-cat]
  49. #% description: List of categories to be displayed (INT maps)
  50. #% guisection: Selection
  51. #%end
  52. #%option
  53. #% key: vallist
  54. #% type: string
  55. #% required: no
  56. #% multiple: yes
  57. #% key_desc: val[-val]
  58. #% description: List of values to be displayed (FP maps)
  59. #% guisection: Selection
  60. #%end
  61. #%option
  62. #% key: bg
  63. #% type: string
  64. #% required: no
  65. #% multiple: no
  66. #% key_desc: color
  67. #% description: Background color (for null)
  68. #% gisprompt: old_color,color,color
  69. #%end
  70. #%option
  71. #% key: opacity
  72. #% type: string
  73. #% required: no
  74. #% multiple: no
  75. #% key_desc: val
  76. #% answer: 100
  77. #% description: Set opacity between 0-100%
  78. #%end
  79. import sys
  80. import os
  81. import grass.script as grass
  82. def construct_command(cmd):
  83. line = cmd
  84. for key, val in options.iteritems():
  85. if val != "":
  86. line += " %s=%s" % (key, val)
  87. for key, val in flags.iteritems():
  88. if val == True:
  89. line += " -%s" % key
  90. return line
  91. def main():
  92. cmd_file = grass.gisenv()["GRASS_PYCMDFILE"]
  93. if cmd_file == "" or os.path.exists(cmd_file) == False:
  94. grass.message(_("GRASS_PYCMDFILE - File not found. Run p.mon."), "e")
  95. return
  96. cmd = construct_command("d"+os.path.basename(sys.argv[0])[1:-3])
  97. fp = open(cmd_file, "a")
  98. fp.write("%s\n" % cmd)
  99. fp.close()
  100. if __name__ == "__main__":
  101. options, flags = grass.parser()
  102. main()