testscript.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. # Test script for r.viewshed based on a synthetic DEM
  3. # RUN THIS IS ANY GRASS LOCATION, e.g. NC or Spearfish
  4. # create first hemisphere
  5. g.region n=1000 s=0 w=0 e=1000 -p res=1
  6. r.mapcalc 'disk.15031=if(sqrt((col() - 500)^2 + (500 - row())^2)<500,sqrt((col() - 500)^2 + (500 - row())^2),null())'
  7. r.mapcalc 'hemisphere1=500 * sin(acos (disk.15031/500))'
  8. # create second hemisphere
  9. g.region n=500 s=0 w=0 e=500 -p res=1
  10. r.mapcalc 'disk.14947=if(sqrt((col() - 500)^2 + (500 - row())^2)<500,sqrt((col() - 500)^2 + (500 - row())^2),null())'
  11. r.mapcalc 'hemisphere2=500 * sin(acos (disk.14947/500))'
  12. g.remove --q rast=disk.14947,disk.15031
  13. # merge both
  14. r.mapcalc "hemisphere=hemisphere1 + hemisphere2"
  15. d.mon x0
  16. d.rast hemisphere
  17. # run r.viewshed
  18. r.viewshed hemisphere out=hemisphere_viewshed coord=250,250 max=1000000 obs=100 mem=2000 --o
  19. r.shaded.relief hemisphere --o
  20. d.his h=hemisphere_viewshed i=hemisphere.shade
  21. # compare to r.los
  22. r.los hemisphere out=hemisphere_los coord=250,250 max=1000000 obs=100 --o
  23. d.mon x1
  24. d.his h=hemisphere_los i=hemisphere.shade
  25. r.mapcalc "hemisphere_diff = hemisphere_viewshed - hemisphere_los"
  26. r.colors hemisphere_diff color=differences
  27. d.mon x2
  28. d.rast.leg pos=80 map=hemisphere_diff
  29. nviz hemisphere col=hemisphere_viewshed