Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. #!/bin/sh -x
  2. ############################################################################
  3. #
  4. # MODULE: r.hillshade.multi
  5. #
  6. # AUTHOR(S): Emmanuel Sambale esambale@yahoo.com emmanuel.sambale@gmail.com
  7. # with comments and improvement from the GRASS user mailing list.
  8. #
  9. # PURPOSE: Creates a multidirectional, oblique-weighted, shaded-relief image
  10. # from an input DEM image. Original ARC 6.0.1 GRID procedure was
  11. # from Mark, Robert. 1992. Multidirectional, oblique-weighted,
  12. # shaded-relief image of the Island of Hawaii. U.S. Geological
  13. # Survey. Menlo Park, CA 94025. Available online:
  14. #
  15. # COPYRIGHT: (C) 2006 by the GRASS Development Team
  16. #
  17. # This program is free software under the GNU General Public
  18. # License (>=v2). Read the file COPYING that comes with GRASS
  19. # for details.
  20. #
  21. #############################################################################
  22.  
  23. #%Module
  24. #% description: Creates a multidirectional, oblique-weighted, shaded-relief image from an input DEM image. The input DEM should cropped to the area of interest only.
  25. #%End
  26. #%flag
  27. #% key: r
  28. #% description: Remove temporary maps
  29. #%END
  30. #%option
  31. #% key: input
  32. #% type: string
  33. #% gisprompt: old,cell,raster
  34. #% description: Name of DEM
  35. #% required : yes
  36. #%End
  37. #%option
  38. #% key: window
  39. #% type: integer
  40. #% description: Window size for aspect resampling default is 5. Window size must be odd.
  41. #% answer : 5
  42. #% required : yes
  43. #%END
  44.  
  45. if [ -z "$GISBASE" ]
  46. then
  47. echo ""
  48. echo "You must be in GRASS GIS to run this program"
  49. echo ""
  50. exit 1
  51. fi
  52.  
  53. if [ "$1" != "@ARGS_PARSED@" ]
  54. then
  55. exec g.parser "$0" "$@"
  56. fi
  57.  
  58.  
  59. unset LC_ALL
  60. export LC_NUMERIC=C
  61.  
  62. #set to current input map region
  63. g.region rast=$GIS_OPT_input -p
  64.  
  65. # Compute hillshade at azimuth 225, 270, 315 and 360 at 30 degrees sun illumination angle
  66. echo ""
  67. echo "Computing hillshade at azimuth 225, 270, 315 and 360 at 30 degrees sun illumination angle ..."
  68. echo "The azimuth of the sun in degrees to the east of north (a value between 0 and 360 degrees) "
  69. r.shaded.relief map=$GIS_OPT_input shadedmap=shade225 altitude=30 azimuth=225 zmult=1 scale=1
  70. r.shaded.relief map=$GIS_OPT_input shadedmap=shade270 altitude=30 azimuth=270 zmult=1 scale=1
  71. r.shaded.relief map=$GIS_OPT_input shadedmap=shade315 altitude=30 azimuth=315 zmult=1 scale=1
  72. r.shaded.relief map=$GIS_OPT_input shadedmap=shade360 altitude=30 azimuth=360 zmult=1 scale=1
  73.  
  74. # Resample DEM map
  75. echo ""
  76. echo "Resampling DEM map from the given window size $GIS_OPT_window"
  77. echo ""
  78. #g.region res=100
  79. r.resample in=$GIS_OPT_input out=res1000
  80. #g.region res=30
  81. r.neighbors in=res1000 out=res1 method=average size="$GIS_OPT_window"
  82.  
  83. # compute aspect map
  84. echo ""
  85. echo "Computing aspect map..."
  86. echo "Aspect is calculated counterclockwise from east"
  87. r.slope.aspect elevation=res1 format=degrees prec=float aspect=aspect1 zfactor=1.0 min_slp_allowed=0.0
  88. #"re-orient aspect"
  89. r.mapcalc "aspect=aspect1 + 90"
  90. # compute weights 225, 270, 315 and 360
  91.  
  92. echo ""
  93. echo "computing weights..."
  94. echo ""
  95. r.mapcalc "w225 = sin((aspect - 225)*sin(aspect - 225))"
  96. r.mapcalc "w270 = sin((aspect - 270)*sin(aspect - 270))"
  97. r.mapcalc "w315 = sin((aspect - 315)*sin(aspect - 315))"
  98. r.mapcalc "w360 = sin((aspect)*sin(aspect))"
  99.  
  100.  
  101. #compute weighted
  102. r.mapcalc "weightedshade = (((w225 * shade225) + (w270 * shade270) + (w315 * shade315) + (w360 * shade360))/2)"
  103.  
  104. if [ $GIS_FLAG_r -eq 1 ] ; then
  105. echo ""
  106. echo "Temporary files deleted ...."
  107. g.remove rast=shade225,shade270,shade315,shade360,w225,w270,w315,w360,aspect,res1,res1000
  108. fi
  109.  
  110. echo ""
  111. echo "Weighted hillshade image created raster name weightedshade."
  112. echo ""
  113.  
  114. #display
  115. r.colors map=weightedshade color=grey
  116. d.mon select=x0
  117. d.erase
  118. d.rast weightedshade
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement