[Gdal-dev] How to measure a distance betwen two points on a line

Mateusz Loskot mateusz at loskot.net
Thu Nov 15 12:44:18 EST 2007


Jose Luis Gomez Dans wrote:
> Hi,
> 
> I had written a reply, but I think I closed the window prior to
> sending the message. D'ooh!!!
> 
>> You can use linestring to one of rectangular system, projecting
>> your data to ie. UTM. Then you can use provided Distance function 
>> based on the Pythagorean Th.
> 
> Imagine that the data is already in projected coordinates (UTM, say).
> I have a points layer with pairs of points, and I have another layer
> with a number of LINES. The POINTS are coincident with vertices on
> the lines layer. What I think Gus wants to know is how to measure the
> distance ALONG the line between those two points. So I guess that you
> first need to cut the line to go from point A to point B (using some
> sort of buffer, intersection operation). Then, on that line, you can
> just use the length() (can't quite remember what the method's exactly
> called) to work out that length.

I'm not sure if I understand the problem correctly, but I'll try to give
another 5 cents. If both layers are projected to a rectangular system,
then you can calculate distance between two geometries, of different or
same type.

If you have line (L) and points (P) you can calculate shortest distance
between p1 and p2 using OGRGeometry::Distance():

    v1    v2
L --*-----*--
P   p1    p2  (coincident with L vertices)


If you have a polyline like this:

    v1    v2    v3    v4
L --*-----*-----*-----*--
P   p1    p2    p3    p4

you need to calculate a sum of distance between all subsequent points p1
to p4 corresponding to L vertices (v1..v4).

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the gdal-dev mailing list