# [GRASS-user] v.distance anything to anything

Moritz Lennert mlennert at club.worldonline.be
Mon Oct 15 15:52:38 PDT 2012

```On 15/10/12 16:30, Markus Metz wrote:

>> So how does it calculate the distance between two lines (lines or
>> boundaries) ? Between closest vertices ? What about lines that cross several
>> other lines, or lines that cross each other at several points ?
>
> For lines to lines, say line A to line B, it calculates shortest
> distance of each vertex in A with each segment (not vertex) in B. So
> far, this is the same like in the original version, results are
> identical.

The original version did not have line to line...

> Now if line A is a line or boundary, it calculates the
> shortest distance of each vertex in B to each segment in A.
> Additionally, it checks for intersections. In case of intersections,
> the first intersection found is used and the distance set to zero.
>
> For lines to areas, it behaves similar to the original version. If a
> line is inside an area, the distance is set to zero. The first point
> of the line inside the area is used as common point. The distance is
> also set to zero if the line intersects with the outer ring or any of
> the inner rings (isles), in which case the fist intersection is used
> as common point.
>
> For areas to areas, the module checks first for overlap or if one area
> is (partially) inside the other area. This is computationally quite
> intensive. If the outer rings of the two areas do not overlap, the
> distance is calculated as above for lines to lines, treating the outer
> rings as two lines. Again, the first point encountered falling into an
> area is used as common point, or the first intersection point.
>
> For anything else than points to lines, there can be several common
> points with distance = zero, and the closest location could then be
> several points or several lines or several areas (result of overlay).
> For v.distance, I choose to select a single point, and not create an
> overlay like v.overlay.

Thanks. I think this should go into the man page.

>>
>>
>>> In GRASS 6, v.distance can calculate distances only from
>>> point,centroid to point,line,boundary,centroid,area.
>>
>>
>> AFAIK, this was due to the conceptual issue mentioned above. I think that
>> the answer has to be clearly explained in the manual because they are not as
>> straightforward. And a first rapid test shows that these issues seem to be
>>
>> http://164.15.12.207/grass/v_distance_lines.png
>> http://164.15.12.207/grass/v_distance_areas.png
>>
>> red: from features (quickly digitized test data available here:
>> http://164.15.12.207/grass/v_distance_testdata.tgz)
>> black: to features (roadsmajor and urbanarea from nc_spm_08)
>> green: connecting lines between from and to feature
>
> Thanks for testing! These issues should be fixed, at least conforming
> to my explanation above, in r53401.

Much better, thanks ! Just one issue still with the area2area case for
the test polygon with cat=2:

http://164.15.12.207/grass/v_distance_areas2.png

The connection line/point doesn't touch the the polygon in the from map.

Moritz
```