3
############################################################################
5
# MODULE: r.plane for GRASS 5.7; based on r.plane for GRASS 5
6
# AUTHOR(S): CERL?; updated to GRASS 5.7 by Michael Barton
7
# Dec 2004: Alessandro Frigeri & Ivan Marchesini
8
# Modified to produce floating and double values maps
9
# PURPOSE: Creates a raster plane map from user specified inclination and azimuth
10
# COPYRIGHT: (C) 2004 by the GRASS Development Team
12
# This program is free software under the GNU General Public
13
# License (>=v2). Read the file COPYING that comes with GRASS
16
#############################################################################
19
#% description: Creates raster plane map given dip (inclination), aspect (azimuth) and one point.
20
#% keywords: raster, elevation
25
#% gisprompt: new,cell,raster
26
#% description: Name of raster plane to be created
34
#% description: Dip of plane. Value must be between -90 and 90 degrees
42
#% description: Azimuth of the plane. Value must be between 0 and 360 degrees
48
#% description: Easting coordinate of a point on the plane
54
#% description: Northing coordinate of a point on the plane
60
#% description: Elevation coordinate of a point on the plane
66
#% options: int,float,double
67
#% description: Type of the raster map to be created
71
if [ -z "$GISBASE" ] ; then
72
echo "You must be in GRASS GIS to run this program." >&2
76
if [ "$1" != "@ARGS_PARSED@" ] ; then
77
exec g.parser "$0" "$@"
82
#### check if we have awk
83
if [ ! -x "`which awk`" ] ; then
84
g.message -e "awk required, please install awk or gawk first"
88
#### setup temporary file
89
TEMPFILE="`g.tempfile pid=$$`"
90
if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
91
g.message -e "unable to create temporary files"
95
#### trap ctrl-c so that we can clean up tmp
96
trap 'rm -f "$TEMPFILE"*' 2 3 15
98
# setting environment, so that awk works properly in all languages
103
### setup enviro vars ###
105
az="$GIS_OPT_AZIMUTH"
106
ea="$GIS_OPT_EASTING"
107
no="$GIS_OPT_NORTHING"
108
el="$GIS_OPT_ELEVATION"
115
### test input values ###
116
diptest=`echo "$dip" | awk '{ printf("%8d", int($1 + 0.5))'}`
117
if [ "$diptest" -lt -90 -o "$diptest" -gt 90 ]
119
g.message -e "Sorry, dip must be greater than -90 and less than 90.\
120
Please enter a valid value."
124
aztest=`echo "$az" | awk '{ printf("%8d", int($1 + 0.5))'}`
125
if [ "$aztest" -lt 0 -o "$aztest" -ge 360 ]
127
g.message -e "Sorry, azimuth must be no less than 0 and less than 360"
133
g.message "Preparing to produce a CELL map.."
138
if [ $type = "float" ]
140
g.message "Preparing to produce an FCELL map.."
145
if [ $type = "double" ]
147
g.message "Preparing to produce a DCELL map.."
152
# these tests will fail for negative lat/lon?
153
eaint=`echo "$ea" | awk '{ printf "%d",int($1 + 0.5) }'`
154
if test "$eaint" -le `echo "$e" | cut -d. -f1` -a "$eaint" -ge `echo "$w" | cut -d. -f1`
159
g.message -e "Sorry, point must be within current region"
160
g.message -e "Current region:"
161
g.message -e "west: $w east: $e"
165
noint=`echo "$no" | awk '{ printf "%d", int($1 + 0.5) }'`
166
if test "$noint" -gt `echo "$s" | cut -d. -f1` -a "$noint" -lt `echo "$n" | cut -d. -f1`
171
g.message -e "Sorry, point must be within current region"
172
g.message -e "Current region:"
173
g.message -e "south: $s north: $n"
178
### now the actual algorithm in awk (stored in a temporary file) ###
179
cat > "$TEMPFILE" << EOF
184
rows = (north-south) / nsres
185
cols = (east-west) / ewres
186
printf("east: %d\n",east)
187
printf("west: %d\n",west)
188
printf("south: %d\n",south)
189
printf("north: %d\n",north)
190
printf("cols: %d\n",cols)
191
printf("rows: %d\n",rows)
197
pi=3.14159265358979323846
200
tandip=(sin(dip2)/cos(dip2))
201
northc=north-(0.5*nsres)
202
southc=south+(0.5*nsres)
203
eastc=east-(0.5*ewres)
204
westc=west+(0.5*ewres)
206
for (y=northc; y >= southc; y=y-nsres) {
207
for (x=westc; x <= eastc; x=x+ewres) {
210
dist = sqrt((dx*dx) + (dy*dy))
215
gamma = atan2((dx/dist),(dy/dist))
218
h=(d*sin(dip2)/cos(dip2))
230
for (z=1; z <= cells; z++) {
232
printf " %d",new_elev[z]
235
printf " %f",new_elev[z]
243
### execute awk and remove temporary file ###
245
awk -f "$TEMPFILE" -v east=$e west=$w north=$n south=$s ea=$ea no=$no typeflag=$typeflag \
246
nsres=$nsres ewres=$ewres dip=$dip az=$az el=$el "$TEMPFILE" > "$TEMPFILE".2
250
g.message "Running r.in.ascii, please stand by.."
251
r.in.ascii `echo $typeflag` i="$TEMPFILE".2 o=$name
253
r.support "$name" hist="$PROG name=$name dip=$dip azimuth=$az easting=$ea \\"
254
r.support "$name" hist="northing=$no elevation=$el type=$type"
257
g.message message="Raster map <$name> generated by r.plane \
258
at point $ea E, $no N, elevation $el with dip=$dip degrees and \
259
aspect=$az degrees ccw from north."
260
#echo "$dat, user: $user"