
360
|
Chapter 6, Mapping on Your Desktop
#74 Plot Wireless Network Viewsheds with GRASS
HACK
map; otherwise, we leave it out. (Note that r.mapcalc does loads more than
this; take a look at its manpage to get a sense of its scope.)
Generating the Line-of-Sight Layer
The following is the entirety of a GRASS script we concocted called r.slice.sh,
a shell script that wraps r.mapcalc to generate r.los pattern-map layers:
#!/bin/bash
for i
do
case $i in
arc=*)
arc=${i#arc=} ;;
azi*=*)
azimuth=${i#azi*=} ;;
map=*)
map=${i#map=} ;;
coord*=*)
coord=${i#coord*=}; x=${coord%,*}; y=${coord#*,} ;;
esac
done
if [ ! "$arc" -o ! "$azimuth" -o ! "$map" -o ! "$x" -o ! "$y" ];
then
echo "Usage: $(basename $0)"
echo " map=raster coordinates=x,y arc=value azimuth=value"
exit -1
fi
r.mapcalc <<EOF
$map = eval( \\
min = $azimuth - ($arc / 2), \\
max = $azimuth + ($arc / 2), \\
theta = atan( y( ) - $y, x( ) - $x ), \\
if( \\
((theta >= min) && (theta <= max)) || \\
((theta - 360 >= min) && (theta - 360 <= max)), \\
1, 0 ) \\
)
EOF
r.colors map=$map color=rules <<EOF
0 black
1 white
EOF
Once we have all the parameters we need, we feed them into r.mapcalc using
shell substitution in a here document. The extra clause in the r.mapcalc code
involving the
theta - 360 calculation handles the edge case where the