Generate a grid with sequential numbers: Difference between revisions
Jump to navigation
Jump to search
(new) |
⚠️Mlennert (talk | contribs) No edit summary |
||
Line 4: | Line 4: | ||
<source lang="bash"> | <source lang="bash"> | ||
# get rows and cols as environment variables | # In a shell get rows and cols as environment variables | ||
eval `g.region -g` | eval `g.region -g` | ||
# | #(or just note the output of g.region -p and replace either $rows or $cols in the formulas below) | ||
# generate the a vertical grid (see image below) | |||
r.mapcalc "grid_seq = col() * $rows + row() - $rows" | |||
#or generate a horizontal grid | |||
r.mapcalc "grid_seq = row() * $cols + col() - $cols" | |||
#to visualise the category numbers in the grid | |||
d.mon x0 | d.mon x0 | ||
d.rast.num grid_seq | d.rast.num grid_seq | ||
</source> | </source> | ||
The resulting raster map looks like this: | The resulting raster map of a vertical grid looks like this: | ||
[[File:Raster_grid_seq.png|300px|thumb|left|Sequentially numbered raster grid]] | [[File:Raster_grid_seq.png|300px|thumb|left|Sequentially numbered raster grid]] | ||
[[Category: FAQ]] | [[Category: FAQ]] |
Latest revision as of 10:45, 19 September 2012
Q: How to generate a grid where the cell numbers are sequential?
A: You can use g.region and r.mapcalc for this:
# In a shell get rows and cols as environment variables
eval `g.region -g`
#(or just note the output of g.region -p and replace either $rows or $cols in the formulas below)
# generate the a vertical grid (see image below)
r.mapcalc "grid_seq = col() * $rows + row() - $rows"
#or generate a horizontal grid
r.mapcalc "grid_seq = row() * $cols + col() - $cols"
#to visualise the category numbers in the grid
d.mon x0
d.rast.num grid_seq
The resulting raster map of a vertical grid looks like this: