4

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 i.group and region definition to obtain subsets of all bands? Scripting might be an answer but I have no much idea about it!

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Chethan S.
  • 4,849
  • 2
  • 23
  • 39

2 Answers2

3

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.

Pablo
  • 9,827
  • 6
  • 43
  • 73
2

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

Nikos Alexandris
  • 1,350
  • 16
  • 31