[GRASS-user] v.to.rast shell script

I was wondering if anyone could suggest a simple shell script to automate the process of running v.to.rast on all layers in a single vector in GRASS?

Thank you,
John

John Tull wrote:

I was wondering if anyone could suggest a simple shell script to
automate the process of running v.to.rast on all layers in
a single vector in GRASS?

sure, just a bash for loop + g.mlist will do it:

for MAP in `g.mlist vect` ; do
   echo v.to.rast in="$MAP" out="`echo $MAP | tr '[:lower:]' '[:upper:]'`"
done

in that example the other v.to.rast options would have to be constant of
course.

To avoid mistakes I like to capitalize a map name if it is going to be
both a vector and raster map. Probably there is some simple sed command
to just do the first character. otherwise just use "out=$MAP".

Hamish

Hamish:

On Sep 19, 2008, at 6:45 PM, Hamish wrote:

John Tull wrote:

I was wondering if anyone could suggest a simple shell script to
automate the process of running v.to.rast on all layers in
a single vector in GRASS?

sure, just a bash for loop + g.mlist will do it:

for MAP in `g.mlist vect` ; do
  echo v.to.rast in="$MAP" out="`echo $MAP | tr '[:lower:]' '[:upper:]'`"
done

in that example the other v.to.rast options would have to be constant of
course.

To avoid mistakes I like to capitalize a map name if it is going to be
both a vector and raster map. Probably there is some simple sed command
to just do the first character. otherwise just use "out=$MAP".

Thank you for your quick response. This, with the addition of 'type=vect' will give me a list of vectors, but I was wanting a list of layers within a single vector. I am guessing there might be a way to cajole v.info into doing this, but am not sure how at this point.

Thanks,
John

On Sep 19, 2008, at 7:07 PM, John C. Tull wrote:

Hamish:

On Sep 19, 2008, at 6:45 PM, Hamish wrote:

John Tull wrote:

I was wondering if anyone could suggest a simple shell script to
automate the process of running v.to.rast on all layers in
a single vector in GRASS?

sure, just a bash for loop + g.mlist will do it:

for MAP in `g.mlist vect` ; do
echo v.to.rast in="$MAP" out="`echo $MAP | tr '[:lower:]' '[:upper:]'`"
done

in that example the other v.to.rast options would have to be constant of
course.

To avoid mistakes I like to capitalize a map name if it is going to be
both a vector and raster map. Probably there is some simple sed command
to just do the first character. otherwise just use "out=$MAP".

Thank you for your quick response. This, with the addition of 'type=vect' will give me a list of vectors, but I was wanting a list of layers within a single vector. I am guessing there might be a way to cajole v.info into doing this, but am not sure how at this point.

Thanks,
John

Ok, applying my little grey cells (as Poirot would say) to the problem at hand, I believe I have resolved this as follows:

for LAYER in `v.category -g option=report in=vect | awk '{print $1}' | uniq` ; do
    v.to.rast in=vect layer="$LAYER" out=vect_$LAYER use=val
done

Hamish: thanks for the basis from which to suss the rest.

John

John Tull wrote:

>> I was wondering if anyone could suggest a simple shell script to
>> automate the process of running v.to.rast on all layers in
>> a single vector in GRASS?

HB:

> sure, just a bash for loop + g.mlist will do it:
>
> for MAP in `g.mlist vect` ; do
> echo v.to.rast in="$MAP" out="`echo $MAP | tr '[:lower:]'
> '[:upper:]'`"
> done

JH:

Thank you for your quick response. This, with the addition of
'type=vect' will give me a list of vectors, but I was wanting a list
of layers within a single vector. I am guessing there might be a way
to cajole v.info into doing this, but am not sure how at this point.

ah, sorry. reading too quickly.

for LAYER in `v.info -c fields --quiet | cut -f2 -d'|'` ; do
  echo "Layer is [$LAYER]"
done

(cut takes the second field and uses | as the field separator)

Instead of 'v.info -c' you could use db.columns or 'db.describe -c'.
Those two will only work if the map (ie DB) is in the current mapset.

add " | grep -v CHARACTER" or " | grep 'INT\|DOUBLE'" if you wish to
skip text columns.

Hamish

John:

Ok, applying my little grey cells (as Poirot would say) to the problem
at hand, I believe I have resolved this as follows:

for LAYER in `v.category -g option=report in=vect | awk '{print $1}' |
uniq` ; do
    v.to.rast in=vect layer="$LAYER" out=vect_$LAYER use=val
done

And my little grey cells are still to brittle to read that you wanted
layer numbers not map names or attribute columns.

oh well, glad you found a solution.

Hamish