[GRASS-user] Export multiple files with r.out.arc

Hello!
How can I export multiple raster files created with r.basin with r.out.arc ( I need them to have *.asc extension). Is there a command line to do this in batch mode because I have around 170 files and it is a bit tedious. Please help.
Thank you,
Bogdan Rosca

Hi there,

The best way to do it would be with a script (the simplest being a bash script, but you can script your commands in any language you like). Either just by writing all of the commands into a file and then running the file (e.g.:

r.out.arc map=something
r.out.arc map=something_else

r.out.arc map=last_map

)

Or by processing the output of ‘g.list rast’ and then doing what you want with that. Hope that helps! :slight_smile:

Best,
Daniel

B.Sc. Daniel Lee
Geschäftsführung für Forschung und Entwicklung
ISIS - International Solar Information Solutions GbR
Vertreten durch: Daniel Lee, Nepomuk Reinhard und Nils Räder

Softwarecenter 3
35037 Marburg
Festnetz: +49 6421 379 6256
Mobil: +49 176 6127 7269
E-Mail: Lee@isi-solutions.org
Web: http://www.isi-solutions.org

2012/5/31 Rosca Bogdan <roscao@gmail.com>

Hello!
How can I export multiple raster files created with r.basin with r.out.arc ( I need them to have *.asc extension). Is there a command line to do this in batch mode because I have around 170 files and it is a bit tedious. Please help.
Thank you,
Bogdan Rosca


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

On Thu, May 31, 2012 at 9:40 AM, Rosca Bogdan <roscao@gmail.com> wrote:

Hello!
How can I export multiple raster files created with r.basin with r.out.arc ( I need them to have *.asc extension). Is there a command line to do this in batch mode because I have around 170 files and it is a bit tedious. Please help.
Thank you,
Bogdan Rosca

The only way that I know, it’s with a script. Here is an example that you can use:

  1. Create a plain text with the names of your input maps, line by line:
    map_name_1
    map_name_2
    map_name_3

If your maps have a pattern, like the example above, you can use the next line to create the file:

g.mlist type=rast pattern=map_name* > names

  1. This a little script that would be useful for you purpose. Just put it on the terminal

i=1
for VAR in awk '{print}' names
do
r.out.arc in=$VAR out=$VAR"arc"$i
i=expr $i + 1
done

I hope it helps you


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


David Montoya González
Ing. Forestal, Universidad Nacional de Colombia
Laboratorio de Sistemas Complejos, UNAL Medellin

I’ll have to defer that to the list, I’m not too good at bash scripting:

Well, yes I was thinking to that but I don’t know exactly how to do it. I mean, till now with:
g.mlist -r type=rast pattern=‘fill_mnat’
I have managed to see all rasters that I want to export (fill_mnat - is contained in the middle of the name of all files for export).
Next I think I have to run something like:
for map in g.mlist -r type=rast pattern=‘fill_mnat’ do r.out.arc input=$map output=‘basemap $map .asc’ done but nothing happens. Is this the correct command line?

I’ll have to defer that to the list, I’m not too good at bash scripting:

Well, yes I was thinking to that but I don’t know exactly how to do it. I mean, till now with:
g.mlist -r type=rast pattern=‘fill_mnat’
I have managed to see all rasters that I want to export (fill_mnat - is contained in the middle of the name of all files for export).
Next I think I have to run something like:
for map in g.mlist -r type=rast pattern=‘fill_mnat’ do r.out.arc input=$map output=‘basemap $map .asc’ done but nothing happens. Is this the correct command line?

Try like this:

RASTS=g.mlist rast pat="*fill_mnat*"
for r in $RASTS; do
echo “Processing raster $r”
g.region rast=$r
r.out.asc $r out=$r.asc
done

Note the backticks (`) in the first line.
Also, be aware that some software reads the asc header as cell centers and some as cell corners. GRASS outputs each pixel to the asc file as cell corners. If you need it as centers, add a ‘-c’ to the r.out.asc command.

You are missing some quotes. Try this:

for map in g.mlist -r type=vect pattern='fill_mnat'
do
r.out.arc in=$map out=basemap_$map".asc" type=area
done

On Thu, May 31, 2012 at 11:23 AM, Daniel Lee <lee@isi-solutions.org> wrote:

I’ll have to defer that to the list, I’m not too good at bash scripting:

Well, yes I was thinking to that but I don’t know exactly how to do it. I mean, till now with:
g.mlist -r type=rast pattern=‘fill_mnat’
I have managed to see all rasters that I want to export (fill_mnat - is contained in the middle of the name of all files for export).
Next I think I have to run something like:
for map in g.mlist -r type=rast pattern=‘fill_mnat’ do r.out.arc input=$map output=‘basemap $map .asc’ done but nothing happens. Is this the correct command line?


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


David Montoya González
Ing. Forestal, Universidad Nacional de Colombia
Laboratorio de Sistemas Complejos, UNAL Medellin

Ooops, typo error: r.out.arc NOT r.out.asc

Try like this:

RASTS=g.mlist rast pat="*fill_mnat*"
for r in $RASTS; do
echo “Processing raster $r”
g.region rast=$r
r.out.asc $r out=$r.asc

^^^^^^