Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As you know landsat data has separate files for different bands. Creating a subset is a wise option to work on region of our interest. Therefore, I used this method to subset my image -

d.zoom || g.region
g.region -p
r.mapcalc *subset*=original

But with this I can subset one band data at a time. Is it somehow possible to use and region definition to obtain subsets of all bands? Scripting might be an answer but I have no much idea about it!

share|improve this question
up vote 3 down vote accepted

You don't need to create a subset with r.mapcalc.
Since you set a region with g.region any calculations made to the data will use only the portion of the images that fall within the region extents.

share|improve this answer

The above question fits to be a generic automation question, like how to repeat task T over several maps M?.

If you do work on Linux (with a bash-shell beforehand), you can utilise bash shell command line utilities (read also Shell Commands). Among the most frequently used is the for loop(ing construct). A simple example could be (where MAP is a variable which "contains" in each loop one of the requested maps *MAP_A*, *MAP_B*, *MAP_C*):

for MAP in MAP_A MAP_B MAP_C ; do r.mapcalc "${MAP}"_subset = "${MAP}" ; done

The above command will execute r.mapcalc "${MAP}"_subset = "${MAP}" over the 3 maps MAP_A, MAP_B, MAP_C.

Of course one can feed the loop with as many maps -- let them be vector or raster -- as asked! Another example, within GRASS-GIS' environment, could be using the results of a g.list command to feed the $MAP variable (given there are raster maps named with the prefix "landsat_"):

for MAP in `g.list rast=landsat*` ; do r.mapcalc "${MAP}"_subset = "${MAP}" ; done

The above command will repeat the same as above command over all maps whose name begins with the prefix landsat_.

An on-going effort to enrich the respective GRASS-GIS wikipage with simple examples is located at GRASS and Shell

share|improve this answer
Will "enable" hyperlinks when required reputation will be collected. – Nikos Alexandris Mar 11 '12 at 13:14
Hyperlinks enabled--thanks to the voter for this answer! Although it was an "old" question, I consider it as a valid one. – Nikos Alexandris Mar 11 '12 at 13:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.