[GRASSLIST:4067] Re: direction to nearest...?
Radim Blazek
blazek at itc.it
Fri Jul 12 04:38:59 EDT 2002
On Thursday 11 July 2002 07:27 pm, Alex Thorn wrote:
> Hi again.
>
> Once again I ask for words of wisdom.
>
> What I'd like to be able to do is to calculate the
> direction from a point to the nearest cell that has a
> given raster value (raster not important here, I just
> assume that it is the best way to implement this).
> I've been looking over the available GRASS commands,
> but haven't been able to find something that will do
> quite what I want. The commands dealing with
> calculating flow seem related, although they call for
> a continuous coverage (e.g. elevation), rather than
> discrete data about a particular feature being present
> or absent in a given cell.
>
> It seems that I ought to be able to get something
> along the lines of the flow/drainage models to work if
> I can generate a coverage in which each cell is
> defined by its distance from a cell with the
> appropriate raster value (I seem to remember reading
> about something like this in one of the tutorials). I
> don't have a clear idea of the steps involved, though,
> and was wondering if someone could give me pointers,
> so that I don't end up pointlessly rediscovering the
> wheel.
>
> Thanks in advance,
> Alex
For this task, a vector is better, I think. One way could be:
for each "from point(s)" do
extract from vector "to points" with required
"given `raster` value" (v.extract)
find nearest and store its id (v.distance)
for pairs of nearest points calculate the direction
(some script in perl or awk or in database)
done
I wanted suggest also to do that all in database like:
select id1, first(id2) from (select id1, id2, (x2-x1)^2 + (y2-y1)^2 as d
from pok1, pok2 where val1 = val2 order by (x2-x1)^2 +
(y2-y1)^2) as xxx group by id1 ;
etc., but I found that there is no first() aggregate function in postgres.
Radim
More information about the grass-user
mailing list