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

Dylan Beaudette dylan.beaudette at gmail.com
Wed Oct 11 16:10:52 EDT 2006


On Tuesday 10 October 2006 06:33, Jachym Cepicky wrote:
> hallo,
>
> On Wed, Oct 04, 2006 at 01:38:25PM +0200, Markus Neteler wrote:
> > 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).
>
> i did not found any G_is_null(raster_map_name,x,y) or similar function.
> is there something like this?
>
> thank you
>
> jachym
>
> one cell from mypixel is "surrounded"
>
> > 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
> >

This is an interesting proposition, with a very nice example of using d.graph 
(have to save that one). How hard would it be to implement something like 
what Jachym mentioned G_is_null(raster_map_name,x,y) OR something that 
explicitly tests for a non-null raster value at some x,y coordinate:

r.distance ---------

// test for overlap between inputs
if( G_overlap_raster(input_a, input_b, x, y) == 1 )
{
//feature is overlapping, return zero distance
dist = 0 ;
continue;
}

//normal distance calculation from here...

-------------------------

cheers,


-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341




More information about the grass-dev mailing list