rhemisphere.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. # Markus Neteler, 2006
  3. # This program is free software under the GNU General Public
  4. # License (>=v2). Read the file COPYING that comes with GRASS
  5. # for details.
  6. # Test cases for 2D raster data
  7. # generate a hemisphere to test slope, aspect, curvatures
  8. # some definitions:
  9. BOXLENGTH=1000 # side length of test area
  10. RADIUS=500 # half BOXLENGTH
  11. ############
  12. if [ -z "$GISBASE" ] ; then
  13. echo "You must be in GRASS GIS to run this program." >&2
  14. exit 1
  15. fi
  16. # some functions - keep order here
  17. TMP="disk.$$"
  18. cleanup()
  19. {
  20. echo "Removing temporary map"
  21. g.remove --q -f type=raster name=$TMP > /dev/null
  22. }
  23. ########################
  24. g.region n=$BOXLENGTH s=0 w=0 e=$BOXLENGTH -p res=1
  25. X="(col() - $RADIUS)"
  26. Y="($RADIUS - row())"
  27. r="sqrt($X^2 + $Y^2)"
  28. #Mask out unwanted parts (check for <= ??):
  29. r.mapcalc "$TMP = if($r<$RADIUS,$r,null())"
  30. ALPHA="acos ($TMP/$RADIUS)"
  31. HEIGHT="$RADIUS * sin($ALPHA)"
  32. r.mapcalc "hemisphere = $HEIGHT"
  33. cleanup
  34. g.message "Generated raster map <hemisphere>"
  35. #echo "Now generate aspect + slope on <hemisphere>"