square_mouse_selection.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #! /bin/sh
  2. # This program is free software under the GPL (>=v2)
  3. # Read the COPYING file that comes with GRASS for details.
  4. #this script select a square area using mouse
  5. #%Module
  6. #% description: Select a rectangular area
  7. #%End
  8. #%option
  9. #% key: raster
  10. #% type: string
  11. #% description: raster map to to analyse
  12. #% required: yes
  13. #%end
  14. #%option
  15. #% key: vector
  16. #% type: string
  17. #% description: vector to overlay
  18. #% required: no
  19. #%end
  20. #%option
  21. #% key: site
  22. #% type: string
  23. #% description: site to overlay
  24. #% required: no
  25. #%end
  26. #%option
  27. #% key: config
  28. #% type: string
  29. #% description: name of configuration file where insert areas
  30. #% required: yes
  31. #%end
  32. #%option
  33. #% key: north
  34. #% type: string
  35. #% description: nothern edge (use only with f flag)
  36. #% required: no
  37. #%end
  38. #%option
  39. #% key: south
  40. #% type: string
  41. #% description:south edge (use only with f flag)
  42. #% required: no
  43. #%end
  44. #%option
  45. #% key: east
  46. #% type: string
  47. #% description: east edge(use only with f flag)
  48. #% required: no
  49. #%end
  50. #%option
  51. #% key: west
  52. #% type: string
  53. #% description: west edge(use only with f flag)
  54. #% required: no
  55. #%end
  56. #%flag
  57. #% key: f
  58. #% description: sample frame yet selected
  59. #%end
  60. f_path="$GISBASE/etc/r.li.setup"
  61. # Check if we have grass
  62. if test "$GISBASE" = ""; then
  63. echo "You must be in GRASS GIS to run this program." >&2
  64. exit 1
  65. fi
  66. if [ "$1" != "@ARGS_PARSED@" ] ; then
  67. exec g.parser "$0" "$@"
  68. fi
  69. # open x1 monitor
  70. d.mon stop=x1
  71. d.mon start=x1
  72. g.region rast=$GIS_OPT_raster
  73. #### set temporary files
  74. TMP="`g.tempfile pid=$$`"
  75. if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
  76. echo "ERROR: unable to create temporary files" 1>&2
  77. exit 1
  78. fi
  79. #saving starting values
  80. g.region -g | grep "n=" | cut -f2 -d'=' > $TMP.var
  81. read s_n < $TMP.var
  82. g.region -g | grep "s=" | cut -f2 -d'=' > $TMP.var
  83. read s_s < $TMP.var
  84. g.region -g | grep "e=" | cut -f2 -d'=' > $TMP.var
  85. read s_e < $TMP.var
  86. g.region -g | grep "w=" | cut -f2 -d'=' > $TMP.var
  87. read s_w < $TMP.var
  88. g.region -g | grep "nsres=" | cut -f2 -d'=' > $TMP.var
  89. read s_nsres < $TMP.var
  90. g.region -g | grep "ewres=" | cut -f2 -d'=' > $TMP.var
  91. read s_ewres < $TMP.var
  92. echo "START $s_n|$s_s|$s_e|$s_w|$s_nsres|$s_ewres" >> $GIS_OPT_conf
  93. # show the sampling frame
  94. if [ $GIS_FLAG_f -eq 1 ] ; then
  95. g.region n=$GIS_OPT_north s=$GIS_OPT_south e=$GIS_OPT_east w=$GIS_OPT_west
  96. fi
  97. d.rast -o map=$GIS_OPT_raster
  98. if [ -n "$GIS_OPT_vector" ] ; then
  99. d.vect map=$GIS_OPT_vector
  100. fi
  101. if [ -n "$GIS_OPT_site" ] ; then
  102. d.vect map=$GIS_OPT_site
  103. fi
  104. #let draw area
  105. d.zoom
  106. #ask if the selected area is right
  107. export name=$TMP #where write the answer
  108. $GRASS_WISH $f_path/square_query
  109. read ok < $TMP.var
  110. if [ $ok -eq 0 ] ; then
  111. echo "NO" >> $GIS_OPT_conf
  112. fi
  113. if [ $ok -eq 1 ] ; then
  114. #write the square boundaries
  115. g.region -g | grep "n=" | cut -f2 -d'=' > $TMP.var
  116. read n < $TMP.var
  117. g.region -g | grep "s=" | cut -f2 -d'=' > $TMP.var
  118. read s < $TMP.var
  119. g.region -g | grep "e=" | cut -f2 -d'=' > $TMP.var
  120. read e < $TMP.var
  121. g.region -g | grep "w=" | cut -f2 -d'=' > $TMP.var
  122. read w < $TMP.var
  123. g.region -g | grep "nsres=" | cut -f2 -d'=' > $TMP.var
  124. read nsres < $TMP.var
  125. g.region -g | grep "ewres=" | cut -f2 -d'=' > $TMP.var
  126. read ewres < $TMP.var
  127. echo "SQUAREAREA $n|$s|$e|$w|$nsres|$ewres" >> $GIS_OPT_conf
  128. fi
  129. #close monitor
  130. d.mon stop=x1
  131. # clean tmp files
  132. rm -f $TMP*