# [GRASS-dev] r.distance problem: in our out?

Markus Neteler neteler at itc.it
Wed Oct 4 07:38:25 EDT 2006

```Hi,

for an application I have to calculate the distance between
raster "objects". While this generally works, I have found
that r.distance happily calculates the distance even if
one object is within the other (say, raster pixel over
raster polygon in second map). I would need an indication
somehow that we are *in* (to ignore the distance in this
case).

Spearfish example:

g.region -dp

# extract field #25:
r.mapcalc "myarea=if(fields == 25, 1,null())"

# this archsite falls into field 25:
v.extract archsites out=mypixel list=9
v.to.rast mypixel out=mypixel use=val val=1
r.distance mypixel,myarea
# -> reports two distant points

# zoom:
g.region n=4926990 s=4925856 w=599850 e=601376 align=myarea
d.mon x0
d.rast myarea
d.vect mypixel col=blue
# visualize distance (d.graph give sometimes random output!):
r.distance mypixel,myarea | awk -F: '{print "move",\$4,\$5,"\ndraw",\$6,\$7}' | d.graph -m

# generate points from distance for easier verification:
r.distance mypixel,myarea | awk -F: '{print \$4,"|",\$5,"\n",\$6,"|",\$7}' | sed  's+ ++g' | v.in.ascii out=distance
d.vect distance col=yellow

# cleanup:
g.remove rast=myarea,mypixel
g.remove vect=mypixel,distance

###
Problem: There is no indication that we are *within* the area. Maybe a flag is
needed to optionally suppress the result in this case?
Better ideas?

Second problem: The result seems to be underestimated by half a cell
since not the cell edge is taken from the raster polygon boundary
but the cell center.

Appreciating help,
Markus

```