[GRASS-user] split adjacent categories

Hello,

I have a raster with different categories (adjacent patches) but when I
buffer this raster file I get a buffer for the whole area and not for each
single patch.

I thought of a loop ( r.mapcalc "select patch cat x" - r.buffer x -
r.mapcalc " set buffer of patch x to null()" ) and then r.patch.

I already did some experiences with

COUNTER = 1

# while [ $COUNTER -lt $max ]; do
while [ $COUNTER < $max ]; do
        echo The counter is $COUNTER
  
  r.mapcalc "t1 = if(rast_in == $COUNTER,1,null())"
  r.buffer input=t1 output=b.$COUNTER distance=500

  let COUNTER=COUNTER+1
    
   done

but failed because COUNTER was not recognized and I don't know at all, if
these bash statements work at all using GRASS.

I welcome any other idea.

Martin

while [ $COUNTER < $max ]; do
       echo The counter is $COUNTER

r.mapcalc "t1 = if(rast_in == $COUNTER,1,null())"
r.buffer input=t1 output=b.$COUNTER distance=500

let COUNTER=COUNTER+1
  
  done

but failed because COUNTER was not recognized and I don't know at all, if
these bash statements work at all using GRASS.

I welcome any other idea.

Shouldn't your bash variables be quoted within the loop?

while [ "$COUNTER" -lt "$MAX" ] ; do

Similarly for the let statement:

let "COUNTER=COUNTER+1"

?

~ Eric.

On Donnerstag, 10. Januar 2008 20:00:16 Patton, Eric wrote:

>while [ $COUNTER < $max ]; do
> echo The counter is $COUNTER
>
> r.mapcalc "t1 = if(rast_in == $COUNTER,1,null())"
> r.buffer input=t1 output=b.$COUNTER distance=500
>
> let COUNTER=COUNTER+1
>
> done
>
>but failed because COUNTER was not recognized and I don't know at all, if
>these bash statements work at all using GRASS.
>
>I welcome any other idea.

Shouldn't your bash variables be quoted within the loop?

while [ "$COUNTER" -lt "$MAX" ] ; do

Similarly for the let statement:

let "COUNTER=COUNTER+1"

thanks - I added it but the first part:

COUNTER = 1

already caused

COUNTER: command not found

can this bash scripting be used in GRASS like that at all?

Martin

thanks - I added it but the first part:

COUNTER = 1

already caused

COUNTER: command not found

can this bash scripting be used in GRASS like that at all?

Martin

Try getting rid of the extra spaces around the assignment statement:

COUNTER=1

~ Eric.

Where was COUNTER not recognized? In the r.mapcalc program or in the while loop?

In bash, for you to define a variable you can't put spaces between the
variable and the equal sign

try COUNTER=1 and NOT COUNTER = 1

On Jan 10, 2008 5:12 PM, Martin Wegmann
<wegmann@biozentrum.uni-wuerzburg.de> wrote:

On Donnerstag, 10. Januar 2008 20:00:16 Patton, Eric wrote:
> >while [ $COUNTER < $max ]; do
> > echo The counter is $COUNTER
> >
> > r.mapcalc "t1 = if(rast_in == $COUNTER,1,null())"
> > r.buffer input=t1 output=b.$COUNTER distance=500
> >
> > let COUNTER=COUNTER+1
> >
> > done
> >
> >but failed because COUNTER was not recognized and I don't know at all, if
> >these bash statements work at all using GRASS.
> >
> >I welcome any other idea.
>
> Shouldn't your bash variables be quoted within the loop?
>
> while [ "$COUNTER" -lt "$MAX" ] ; do
>
> Similarly for the let statement:
>
> let "COUNTER=COUNTER+1"

thanks - I added it but the first part:

COUNTER = 1

already caused

COUNTER: command not found

can this bash scripting be used in GRASS like that at all?

Martin

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

On Thursday 10 January 2008 20:17:24 Patton, Eric wrote:

>thanks - I added it but the first part:
>
>COUNTER = 1
>
>already caused
>
>COUNTER: command not found
>
>can this bash scripting be used in GRASS like that at all?
>
>Martin

Try getting rid of the extra spaces around the assignment statement:

COUNTER=1

thanks everybody - now it's working:

#!/bin/bash

echo -n "input:"
read input

r.to.vect $input output=tttemp feature=area --o
v.to.rast tttemp output=tttemp_in use=cat --o

g.remove vect=tttemp

max=`r.info -r "tttemp_in" | grep max | cut -f2 -d=`

COUNTER=`r.info -r "tttemp_in" | grep min | cut -f2 -d=`

# while [ $COUNTER -lt $max ]; do
while [ "$COUNTER" -le "$max" ];

do
        echo counter ist "$COUNTER"
        
        r.mapcalc "tttemp_1 = if(tttemp_in == "$COUNTER",1,null())"

        r.mapcalc "tttemp_inv = if(isnull(tttemp_1),1,null())" >/dev/null 2>&1
        r.buffer input=tttemp_inv output=tttemp_buffer distances=100 --o
        r.mapcalc "tttemp_area."$COUNTER" =if(isnull(tttemp_buffer),1,null())"

        let "COUNTER=COUNTER+1"

done

var1=1

var2=0

# until [ "$var1" -eq "$max" ]

while [ "$var1" -le $max ]

do
        echo "$var1" plus "$var2"
        r.mapcalc "tttemp_area.0 = tttemp_area.1"
        r.patch input=tttemp_area.$var1,p.$var2 output=p."$var1" --o
    
        var1=$(( $var1 + 1 ))
        var2=$(( $var2 + 1 ))
done