[GRASS-user] Conversion of multiple rasters to PNG files

Hi Community,

I'm relatively new to GRASS/unix style commands and was wondering if anyone
had a quick PERL script that could convert LOTS of raster maps to PNG files
without the repetition of going through one by one. I'm not much of a
programmer otherwise I'd write some kind of loop and have a go. The general
form of my rasters is already in a "Name_$Date" style format so I think this
should be pretty easy? I'm attempting to make video files that illustrate
soil saturation with time. I have about 10 years (daily) of soil moisture
that I'm looking to animate so it's a digestible amount of information.

Thanks for reading/advice!

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Conversion-of-multiple-rasters-to-PNG-files-tp6263692p6263692.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Hi,
you could use the following bash for loop as a
basis for what you want to do:

for file in g.mlist rast pattern=searchpattern*;
do r.out.png input=$file output=“/tmp/”$file".png";
done

Regards,
Daniel

On Tue, Apr 12, 2011 at 5:10 AM, Mortsde <alex.mortsde@gmail.com> wrote:

Hi Community,

I’m relatively new to GRASS/unix style commands and was wondering if anyone
had a quick PERL script that could convert LOTS of raster maps to PNG files
without the repetition of going through one by one. I’m not much of a
programmer otherwise I’d write some kind of loop and have a go. The general
form of my rasters is already in a “Name_$Date” style format so I think this
should be pretty easy? I’m attempting to make video files that illustrate
soil saturation with time. I have about 10 years (daily) of soil moisture
that I’m looking to animate so it’s a digestible amount of information.

Thanks for reading/advice!


View this message in context: http://osgeo-org.1803224.n2.nabble.com/Conversion-of-multiple-rasters-to-PNG-files-tp6263692p6263692.html
Sent from the Grass - Users mailing list archive at Nabble.com.


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

Mortsde wrote:

I'm relatively new to GRASS/unix style commands and was
wondering if anyone
had a quick PERL script that could convert LOTS of raster maps to PNG
files without the repetition of going through one by one. I'm not much
of a programmer otherwise I'd write some kind of loop and have a go.
The general form of my rasters is already in a "Name_$Date" style
format so I think this
should be pretty easy? I'm attempting to make video files that illustrate
soil saturation with time. I have about 10 years (daily) of soil moisture
that I'm looking to animate so it's a digestible amount of information.

some shell script loop scripts here:
  http://grass.osgeo.org/wiki/Movies

but none of those really strike me as beginner-friendly. (mea culpa)

the general idea is:

# set up region
g.region rast=

# use g.mlist to list all relevant maps
g.mlist rast pattern=

# eg throw those map names into a loop
my @maps = system(g.mlist rast pat=soils.*);
my @maps = `g.mlist rast pat=soils.*`;

for my $m (@maps) {
  print $m;
  `d.erase`;
  `d.rast $m`;
   ...
  `d.out.file $png_name`
   ...
}

probably it is good to first run through a loop of all the maps with
'r.info -r' and get the overall range, then create color rules covering
that entire range and in a loop apply it to all maps with r.colors.
that way the color scale stats the same.

Hamish

Daniel,

Thanks for that write up. I just wanted to ask what the purpose of the /tmp/
line was. It seems like the conversion ran through just fine, but I don't
see any of the files saved to a specific place. Is the "/tmp/" listing the
folder directory where the files are written?

daniel mcinerney-2 wrote:

Hi,
you could use the following bash for loop as a
basis for what you want to do:

for file in `g.mlist rast pattern=searchpattern*`;
     do r.out.png input=$file output="/tmp/"$file".png";
done

Regards,
Daniel

On Tue, Apr 12, 2011 at 5:10 AM, Mortsde &lt;alex.mortsde@gmail.com&gt;
wrote:

Hi Community,

I'm relatively new to GRASS/unix style commands and was wondering if
anyone
had a quick PERL script that could convert LOTS of raster maps to PNG
files
without the repetition of going through one by one. I'm not much of a
programmer otherwise I'd write some kind of loop and have a go. The
general
form of my rasters is already in a "Name_$Date" style format so I think
this
should be pretty easy? I'm attempting to make video files that illustrate
soil saturation with time. I have about 10 years (daily) of soil moisture
that I'm looking to animate so it's a digestible amount of information.

Thanks for reading/advice!

--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/Conversion-of-multiple-rasters-to-PNG-files-tp6263692p6263692.html
Sent from the Grass - Users mailing list archive at Nabble.com.
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

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

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Conversion-of-multiple-rasters-to-PNG-files-tp6263692p6269876.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Hamish,

Thanks for the advice but I'm still having some hangups with your code. Are
these commands meant for a unique script, entry into the terminal itself,
other...? The "my @maps" is confusing, what is the my representing? I
understand that @maps is referring to the map-file locations. The rest of
the code has me lost as well...

Thanks again!

I'm relatively new to GRASS/unix style commands and was
wondering if anyone
had a quick PERL script that could convert LOTS of raster maps to PNG
files without the repetition of going through one by one. I'm not much
of a programmer otherwise I'd write some kind of loop and have a go.
The general form of my rasters is already in a "Name_$Date" style
format so I think this
should be pretty easy? I'm attempting to make video files that illustrate
soil saturation with time. I have about 10 years (daily) of soil moisture
that I'm looking to animate so it's a digestible amount of information.

some shell script loop scripts here:
  http://grass.osgeo.org/wiki/Movies

but none of those really strike me as beginner-friendly. (mea culpa)

the general idea is:

# set up region
g.region rast=

# use g.mlist to list all relevant maps
g.mlist rast pattern=

# eg throw those map names into a loop
my @maps = system(g.mlist rast pat=soils.*);
my @maps = `g.mlist rast pat=soils.*`;

for my $m (@maps) {
  print $m;
  `d.erase`;
  `d.rast $m`;
   ...
  `d.out.file $png_name`
   ...
}

probably it is good to first run through a loop of all the maps with
'r.info -r' and get the overall range, then create color rules covering
that entire range and in a loop apply it to all maps with r.colors.
that way the color scale stats the same.

Hamish

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

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Conversion-of-multiple-rasters-to-PNG-files-tp6263692p6269898.html
Sent from the Grass - Users mailing list archive at Nabble.com.