Saturday, February 21, 2009

Expanding the console language - part II

Now the console has some keywords that refer to the active region values, i.e. limits, resolution and rows and columns.

I think an example is more than self explaining about the usage.
The following
  • prints to console the values of the active region
  • uses the GRASS command g.region to change the resolution to 20 meters (as you can see it was 40 before)
  • updates the script's variables region values to the new set (very important)
  • prints out the new active region values



println "n = " + NORTH()
println "s = " + SOUTH()
println "e = " + EAST()
println "w = " + WEST()
println "xres = " + WERES()
println "yres = " + NSRES()
println "rows = " + ROWS()
println "cols = " + COLS()

grass g.region.exe res = 20

updateActiveregion()

println "n = " + NORTH()
println "s = " + SOUTH()
println "e = " + EAST()
println "w = " + WEST()
println "xres = " + WERES()
println "yres = " + NSRES()
println "rows = " + ROWS()
println "cols = " + COLS()



My example result is:
n = 5204514.51713
s = 5141634.51713
e = 686136.82243
w = 601576.82243
xres = 40.0
yres = 40.0
rows = 1572
cols = 2114
Updated active region...
n = 5204514.51713
s = 5141634.51713
e = 686136.82243
w = 601576.82243
xres = 20.0
yres = 20.0
rows = 3144
cols = 4228

No comments: