Hi all,
does anyone know how to generate a grid where the numbers are sequential?
i have used r.random.cells to create a grid, but grids are numbered, well, randomly.
thanx,
Janet
On 17/09/12 16:05, Janet Choate wrote:
Hi all,
does anyone know how to generate a grid where the numbers are sequential?
i have used r.random.cells to create a grid, but grids are numbered,
well, randomly.
Maybe r.mapcalc with a combination of the row() and col() functions ? Depending on the number of cells you have you can do something like this: row()*10000+col(). This will give you an ordered sequence, but numbers from one line to the next will have a gap. If you need perfectly sequenced numbers, I imagine it's possibly to find a formula that gives you that...
Moritz
On 17/09/12 17:46, Moritz Lennert wrote:
On 17/09/12 16:05, Janet Choate wrote:
Hi all,
does anyone know how to generate a grid where the numbers are sequential?
i have used r.random.cells to create a grid, but grids are numbered,
well, randomly.Maybe r.mapcalc with a combination of the row() and col() functions ?
Depending on the number of cells you have you can do something like
this: row()*10000+col(). This will give you an ordered sequence, but
numbers from one line to the next will have a gap. If you need perfectly
sequenced numbers, I imagine it's possibly to find a formula that gives
you that...
Try
r.mapcalc sequential_grid=(row()*NumberOfColumns+col())-NumberOfColumns
You can get the number of columns in your region with g.region -p ("cols").
Moritz
Here you go - see screenshot:
# get rows and cols as environment variables
eval `g.region -g`
r.mapcalc "grid_seq = col() * $rows + row() + $cols - ($rows + $cols)"
d.mon x0
d.rast.num grid_seq
Markus
(attachments)
On 17/09/12 21:32, Markus Neteler wrote:
Here you go - see screenshot:
# get rows and cols as environment variables
eval `g.region -g`
r.mapcalc "grid_seq = col() * $rows + row() + $cols - ($rows + $cols)"
This can be simplified to
r.mapcalc "grid_seq = col() * $rows + row() - $rows"
and gives you a "vertical" sequence.
My solution
r.mapcalc "grid_seq = row() * $cols + col() - $cols"
gives you a "horizontal" sequence.
I added a FAQ at http://grass.osgeo.org/wiki/Sequential_Grid.
Moritz
On Tue, Sep 18, 2012 at 3:11 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:
...
I added a FAQ at http://grass.osgeo.org/wiki/Sequential_Grid.
Now we have two From yesterday...
http://grass.osgeo.org/wiki/Generate_a_grid_with_sequential_numbers
Markus
On 18/09/12 15:14, Markus Neteler wrote:
On Tue, Sep 18, 2012 at 3:11 PM, Moritz Lennert
<mlennert@club.worldonline.be> wrote:
...I added a FAQ at http://grass.osgeo.org/wiki/Sequential_Grid.
Now we have two
From yesterday...
http://grass.osgeo.org/wiki/Generate_a_grid_with_sequential_numbers
Sorry, overlooked that. I can fusion the two and redirect from one to the other, unless you have already done that
Moritz