[GRASS5] Asking about feasibility of an addition to r.recode

I¹m involved in a project to develop a linkage between agent based modeling
platforms and GRASS. One item that seems will be very important is way to
change a group of cell values (i.e., cat values) given their xy coordinates.
I realize that it is possible to use the map calculator to create a new map
with 1 new cell changed. But AFAICT, there is no way to send a set of xy
values, along with new cat values for each xy pair and change cells in an
existing map or create a new map with the changed cells (and old values for
the rest of the cells). Markus suggested that I run this by the developers
list. I can make this a formal Œwish¹ if it helps.

From the perspective of someone who is fairly ignorant of C, it seems to me
that the (conceptually at least) easiest thing to do is to alter r.recode to
accept input (stdin or text file) in the form of

x1,y1,val1
x2,y2,val2

or even better, if we want to keep a similar format to that now used for cat
value recoding

x1:x2:y1:y2 val1
x3:x4:y3:y4 val2

where x1:x2 defines a range of x coordinates and y1:y2 defines a range of y
coordinates. This way single cells or blocks of cells could be referenced
and changed. This mode would probably open up a number of new modeling
possibilities within GRASS too.

This mode could be controlled by a flag. What do you all think? Is this
feasible? Is it fairly easy or fairly difficult? Is there a better way to
change a group of cell values based on their xy coordinates?

Thanks for your input.

Michael
___________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

WWW - http://www.public.asu.edu/~cmbarton
Phone: 480-965-6262
Fax: 480-965-7671

Michael Barton wrote:

I¹m involved in a project to develop a linkage between agent based modeling
platforms and GRASS. One item that seems will be very important is way to
change a group of cell values (i.e., cat values) given their xy coordinates.
I realize that it is possible to use the map calculator to create a new map
with 1 new cell changed. But AFAICT, there is no way to send a set of xy
values, along with new cat values for each xy pair and change cells in an
existing map or create a new map with the changed cells (and old values for
the rest of the cells).

If you can create a raster map containing only the new cells, with
null elsewhere, you can patch it together with the old map to get the
updated map. In 5.3, the first step could be done with s.in.ascii +
s.to.rast; does v.in.ascii + v.to.rast not work with points?

Markus suggested that I run this by the developers
list. I can make this a formal Œwish¹ if it helps.

>From the perspective of someone who is fairly ignorant of C, it seems to me
that the (conceptually at least) easiest thing to do is to alter r.recode to
accept input (stdin or text file) in the form of

x1,y1,val1
x2,y2,val2

r.recode doesn't seem like a significantly better match than any other
raster processing tool. IMHO, this should be a separate tool rather
than a modification to r.recode.

or even better, if we want to keep a similar format to that now used for cat
value recoding

x1:x2:y1:y2 val1
x3:x4:y3:y4 val2

where x1:x2 defines a range of x coordinates and y1:y2 defines a range of y
coordinates. This way single cells or blocks of cells could be referenced
and changed. This mode would probably open up a number of new modeling
possibilities within GRASS too.

This mode could be controlled by a flag. What do you all think? Is this
feasible? Is it fairly easy or fairly difficult? Is there a better way to
change a group of cell values based on their xy coordinates?

The implementation is straightforward enough, at least for individual
pixels. Primarily, the input list needs to be sorted in descending
order of y coordinate (i.e. ascending row numbers), so that the map
can be processed one row at a time.

For rectangles, the process is similar, but you need to maintain a
list of "active" rectangles (those which intersect the current row).
The list would need to be sorted in order of the top edge.

I wouldn't make it read an existing map, just write out nulls for
cells which aren't defined by the input. r.patch can be used to update
an existing map if desired.

The main problems I foresee is feature creep. If you support points
and rectangles, you will end up getting requests to add circles,
lines, polygons, etc. There will always be a point at which the
specific tool is inadequate and you need to import your updates as a
vector map then rasterise it with v.to.rast.

--
Glynn Clements <glynn@gclements.plus.com>

Glynn,

Helena already suggested your first idea, using v.in.ascii, v.to.rast, and
either r.mapcalc or r.patch. We'll try that to get started. However, I'll
probably need to script it to make it easier to do from an external Java
program. I don't know what the performance hit will be to do it this way,
but at least it should work so that we can get started.

Your second suggestion is interesting, that it would be better to do it in a
separate module than alter r.recode. Your points about feature creep is
well-taken, though I'm not sure that it would apply here in the modeling
case. In fact, a simple xy cat list might actually be better for modeling
than defining a geometric area.

However, what you suggest in the 'feature creep' section sounds like a
command-line module to replace r.digit and which could be run from any
generic GUI. That could be useful for dual purposes in this event. :wink:

Michael

On 4/3/06 8:53 PM, "Glynn Clements" <glynn@gclements.plus.com> wrote:

Michael Barton wrote:

I�m involved in a project to develop a linkage between agent based modeling
platforms and GRASS. One item that seems will be very important is way to
change a group of cell values (i.e., cat values) given their xy coordinates.
I realize that it is possible to use the map calculator to create a new map
with 1 new cell changed. But AFAICT, there is no way to send a set of xy
values, along with new cat values for each xy pair and change cells in an
existing map or create a new map with the changed cells (and old values for
the rest of the cells).

If you can create a raster map containing only the new cells, with
null elsewhere, you can patch it together with the old map to get the
updated map. In 5.3, the first step could be done with s.in.ascii +
s.to.rast; does v.in.ascii + v.to.rast not work with points?

Markus suggested that I run this by the developers
list. I can make this a formal �wish� if it helps.

From the perspective of someone who is fairly ignorant of C, it seems to me

that the (conceptually at least) easiest thing to do is to alter r.recode to
accept input (stdin or text file) in the form of

x1,y1,val1
x2,y2,val2

r.recode doesn't seem like a significantly better match than any other
raster processing tool. IMHO, this should be a separate tool rather
than a modification to r.recode.

or even better, if we want to keep a similar format to that now used for cat
value recoding

x1:x2:y1:y2 val1
x3:x4:y3:y4 val2

where x1:x2 defines a range of x coordinates and y1:y2 defines a range of y
coordinates. This way single cells or blocks of cells could be referenced
and changed. This mode would probably open up a number of new modeling
possibilities within GRASS too.

This mode could be controlled by a flag. What do you all think? Is this
feasible? Is it fairly easy or fairly difficult? Is there a better way to
change a group of cell values based on their xy coordinates?

The implementation is straightforward enough, at least for individual
pixels. Primarily, the input list needs to be sorted in descending
order of y coordinate (i.e. ascending row numbers), so that the map
can be processed one row at a time.

For rectangles, the process is similar, but you need to maintain a
list of "active" rectangles (those which intersect the current row).
The list would need to be sorted in order of the top edge.

I wouldn't make it read an existing map, just write out nulls for
cells which aren't defined by the input. r.patch can be used to update
an existing map if desired.

The main problems I foresee is feature creep. If you support points
and rectangles, you will end up getting requests to add circles,
lines, polygons, etc. There will always be a point at which the
specific tool is inadequate and you need to import your updates as a
vector map then rasterise it with v.to.rast.

___________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

WWW - http://www.public.asu.edu/~cmbarton
Phone: 480-965-6262
Fax: 480-965-7671

>> I'm involved in a project to develop a linkage between agent
>based modeling > platforms and GRASS. One item that seems will be
>very important is way to > change a group of cell values (i.e., cat
>values) given their xy coordinates. > I realize that it is possible
>to use the map calculator to create a new map > with 1 new cell
>changed. But AFAICT, there is no way to send a set of xy > values,
>along with new cat values for each xy pair and change cells in an >
>existing map or create a new map with the changed cells (and old
>values for > the rest of the cells).

easy enough in C, check out D_u_to_a_row() and friends in
lib/display/cnversions.c and cannibalize d.rast.edit.

> If you can create a raster map containing only the new cells, with
> null elsewhere, you can patch it together with the old map to get
> the updated map. In 5.3, the first step could be done with
> s.in.ascii + s.to.rast; does v.in.ascii + v.to.rast not work with
> points?

probably the cleanest and easiest solution here.
v.in.ascii + v.to.rast works fine with points.

However, what you suggest in the 'feature creep' section sounds like a
command-line module to replace r.digit and which could be run from any
generic GUI. That could be useful for dual purposes in this event. :wink:

For a r.digit replacement I think a GUI that builds up an input file
which is fed into r.in.poly is the simplest route.

Hamish

I see what you mean with r.in.poly.

Can r.in.poly take single xy pairs? That is, can you do this...

A
10,20
= 1 type1
A
30,50
= 1 type1
A
100,60
= 1 type1
A
20,20
= 2 type2
A
20,21
= 2 type2
A
20,22
= 2 type2

If so, this is another way to do what I'm wanting an ABM controlling GRASS
to be able to do.

Michael

On 4/3/06 10:38 PM, "Hamish" <hamish_nospam@yahoo.com> wrote:

However, what you suggest in the 'feature creep' section sounds like a
command-line module to replace r.digit and which could be run from any
generic GUI. That could be useful for dual purposes in this event. :wink:

For a r.digit replacement I think a GUI that builds up an input file
which is fed into r.in.poly is the simplest route.

___________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

WWW - http://www.public.asu.edu/~cmbarton
Phone: 480-965-6262
Fax: 480-965-7671

I see what you mean with r.in.poly.

Can r.in.poly take single xy pairs? That is, can you do this...

A
10,20
= 1 type1

probably better to make short lines:

L
10,20
10,20
= 1 type1
L
15,23
15,23
= 2 type2

?
don't know if that works. (or if 1 point area works [doubt it])
try it and see what happens.

Hamish