[GRASS-user] affecting cat of closest feature as pixel value

Using r.cost with multiple starting points with my students, the question came up whether it is possible to use the resulting cumulative cost surface to assign each pixel the cat (or other info) of its closest starting point, so something like r.grow.distance, but taking into account the cost, not necessarily the distance.

Any ideas ?

Moritz

On Fri, Jul 10, 2009 at 9:37 AM, Moritz
Lennert<mlennert@club.worldonline.be> wrote:

Using r.cost with multiple starting points with my students, the question
came up whether it is possible to use the resulting cumulative cost surface
to assign each pixel the cat (or other info) of its closest starting point,
so something like r.grow.distance, but taking into account the cost, not
necessarily the distance.

Any ideas ?

(Un)related wish: while you are at it, could you also compare the results
of r.terracost in the Addons repository [1]? If as expected, I would suggest
to replace r.cost with the code of r.terracost in GRASS 7.

thanks
Markus

[1] The new Addons installer might greatly facilitate the installation

On 10/07/09 14:53, Markus Neteler wrote:

On Fri, Jul 10, 2009 at 9:37 AM, Moritz
Lennert<mlennert@club.worldonline.be> wrote:

Using r.cost with multiple starting points with my students, the question
came up whether it is possible to use the resulting cumulative cost surface
to assign each pixel the cat (or other info) of its closest starting point,
so something like r.grow.distance, but taking into account the cost, not
necessarily the distance.

Any ideas ?

(Un)related wish: while you are at it, could you also compare the results
of r.terracost in the Addons repository [1]? If as expected, I would suggest
to replace r.cost with the code of r.terracost in GRASS 7.

Using two different examples I use in current teaching (dataset nc_spm_06):

g.region rast=elev_state_500m
v.to.rast nc_state use=val val=500.0 out=cost
v.to.rast urbanarea use=val val=1 out=urbanarea
r.cost -k in=cost start_rast=urbanarea out=dist_urban
r.terracost in=cost start_rast=urbanarea out=dist_urban_terracost
r.mapcalc diff=dist_urban-dist_urban_terracost

results in

http://geog-pc40.ulb.ac.be/grass/misc/comparison_rcost_rterracost_1.png
with
dist_urban: maximum: 83450.8, mean: 11829.7
dist_urban_terracost: maximum: 85324.1, mean: 11932.2

g.region rast=landclass96
r.reclass landclass96 out=cost_landcover << EOF
1 = 200
2 = 20
3 = 5
4 = 50
5 = 30
6 = 1000
7 = 5
EOF
r.cost -k in=cost_landcover out=dist_rcost coordinate=629980,228527.25
echo "629980|228527.25" | v.in.ascii out=point
#would be nice if r.terracost also accepted a vector map or coordinates as starting points
v.to.rast point use=val val=1 out=point
r.terracost in=cost_landcover out=dist_terracost start_rast=point
r.mapcalc diff2=dist_rcost-dist_terracost

results in

http://geog-pc40.ulb.ac.be/grass/misc/comparison_rcost_rterracost_2.png
with
dist_rcost: maximum: 30320, mean: 10641.8
dist_rterracost: maximum: 30755.4, mean: 10868

So, differences are non-negligeable, but no idea how to interpret them at this stage, i.e. don't know which one is "correct".

Moritz

Moritz wrote:

So, differences are non-negligeable, but no idea how to
interpret them at this stage, i.e. don't know which one is
"correct".

I would suggect to try with some simple geometric cost, like
was done for the Knight's move example graphic in the r.cost
help page. Then you can use your eye to locate differing bias
(e.g. from 8/16 compass points).

Hamish

On 14/07/09 15:00, Hamish wrote:

Moritz wrote:

So, differences are non-negligeable, but no idea how to
interpret them at this stage, i.e. don't know which one is
"correct".

I would suggect to try with some simple geometric cost, like
was done for the Knight's move example graphic in the r.cost
help page. Then you can use your eye to locate differing bias
(e.g. from 8/16 compass points).

Ok, here's a try:

g.region n=10 s=0 w=0 e=10 res=1 -a
r.mapcalc one=1.0
echo "5|5" | v.in.ascii out=start
v.to.rast start use=val val=1 out=start
r.cost -k one start_rast=start out=r_cost
r.terracost one start_rast=start out=terra_cost
d.rast.num r_cost
d.rast.num terra_cost

This gives:

r.cost: http://geog-pc40.ulb.ac.be/grass/misc/r_cost.png
r.terracost: http://geog-pc40.ulb.ac.be/grass/misc/terra_cost.png

It seems as if r.terracost only counts have a distance between the original cell and its neighbors, but then goes on to count complete distances. This seems to be enough to explain the difference between the two results.

Don't know what is generally considered the "right" way, but intuitively I would side with r.cost.

Moritz