[GRASS-user] What's wrong with this r.mapcalc usage?
Tom Russo
russo at bogodyn.org
Wed Jan 30 13:07:06 EST 2008
The other day I tried to perform an operation with r.mapcalc that didn't
work the way I expected.
I have a map, SAO that is 1 in some places and null elsewhere. It represents
an area of interest.
I have two other maps, call 'em A and B, that are elevation models over
two areas overlapped by SAO's non-null elements. They are null outside the
areas where they have valid elevation, and they represent adjoining areas.
I wanted to select all points covered by non-null pixels of SAO that have
elevation over 11,000 feet. The first thing I tried was this input
to r.mapcalc:
if(!isnull(SAO),
if(!isnull(A)&&A>=11000,
1,
if(!isnull(B)&&B>=11000,
1,
null()
)
),
null()
)
(Whitespace added here just so I can be sure to match parens as I type it
in from memory) Here, I'm expecting that anywhere that A is null, the third
argument of the "if(!isnull(A)[...],1,[...] would be evaluated, and that
it would result in the same thing as if I'd done an r.patch on A and B to
get C, then just tested like
"if(!isnull(SAO),if(!isnull(C)&&C>=11000,1,null()),null())". I thought I
would be saving the time and space of doing an r.patch.
What I got, however, was as if I'd left out the if involving B --- I got
all those pixels overlapping SAO and A where elevation was >=11000 feet, and
nulls where SAO overlapped B.
(Yes, g.region was set so that all of the non-null extent of SAO was included,
and yes, there were pixels that should have matched the criteria)
I tried a bunch of variations on this, never getting the result I wanted. In
the end, I just did two separate runs of r.mapcalc:
m1=SAO*if(!isnull(A)&&A>=11000,1,null())
m2=SAO*if(!isnull(B)&&B>=11000,1,null())
and an r.patch, which saved me no effort at all, even counting the time wasted
experimenting.
Can someone spot my blindingly obvious mistake or misconception on how
r.mapcalc's 3-argument if function is supposed to work? I can't.
--
Tom Russo KM5VY SAR502 DM64ux http://www.swcp.com/~russo/
Tijeras, NM QRPL#1592 K2#398 SOC#236 AHTB#1 http://kevan.org/brain.cgi?DDTNM
"And, isn't sanity really just a one-trick pony anyway? I mean all you get is
one trick, rational thinking, but when you're good and crazy, oooh, oooh,
oooh, the sky is the limit!" --- The Tick
More information about the grass-user
mailing list