[GRASS-dev] About v.distance, v.what.vect (wrt "count points within...").

Moritz Lennert mlennert at club.worldonline.be
Tue Aug 10 09:17:19 EDT 2010


On 10/08/10 13:49, Nikos Alexandris wrote:
> Markus M:
>
>> If a point is inside an area (the polygon composed of the area's
>> boundaries), the distance is 0 (zero):
>
> This sentence makes me think that it is a priori known (based on something
> else - related to topology?) when a point is inside an area. Why all the need
> to measure distances then in order to count how many points are inside?

As you can see in the code referenced by Markus, there is a 
Vect_point_in_area(), so yes, it is possible to more directly check if 
points are in areas. It all depends on which modules were written using 
this function. At this stage all point-in-polygon attempts in GRASS are 
scripts using workarounds...

>> A centroid is always inside the area it belongs to, therefore the
>> distance of a point outside an area to the area's centroid is always
>> larger than the distance of that point to the area's boundaries.
>
> What happens when the centroid (gravity center) falls outside of the
> boundaries?

In GRASS, by definition a centroid is within the boundaries, and so does 
not necessarily represent center of gravity.

>>> Point to boundary? Specifically, point to all-lines that compose a
>>> boundary? Many distances? And then, keep the maximum?
>
>> If a point is outside an area, v.distance determines the shortest
>> distance to the area's boundaries (point to all-lines that compose a
>> boundary), IOW, keep the minimum not the maximum because v.distance
>> searches for the nearest feature.
>
> All right. But, (repeating the same question): why is distance measuring
> required at all? To compare it with what?

Well, v.distance was not meant as a point-in-polygon measurement tool, 
but as a distance measurement tool. v.what.vect just "abuses" it as 
such, using dmax=0.0. But currently, there is not dedicated 
point-in-polygon counting module...

> Why are (supposedly) other tools faster in counting points within polygons?

see above...

So, maybe, if you have a dedicated programmer at hand, you could imagine 
a module with point-in-polygon algorithm, maybe giving the option of 
counting the points, aggregating some attribute values of the points, 
etc, using the Vect_point_in_area() function...

Should just be a matter of:

- opening a polygon and a point layer
- for each polygon
	- loop through all points and if Vect_point_in_area() is true, 
aggregate the values of those that fall into the polygon
- put results into table of polygon map, new table or stdout

I imagine that here the use of bounding boxes and the spatial index 
might here, but that's Markus' specialty ;-)

Moritz




More information about the grass-dev mailing list