[Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-13 Thread Ing. Pierluigi De Rosa
Hi all, I have a line geometry (ALine) and a point(Apoint) belonging to the ALine. Apoint have been evaluated from a second line geometry Bline that cross the Aline using the QgsGeometry intersection function as: Apoint =Bline.intersection(Aline) I need to calculate distance along Aline from the

Re: [Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-13 Thread G. Allegri
Hi Pierluigi, I don't know of such a function available from Python. I've translated a function from GEOS (C++) to Python some time ago. If you wish I can share it. giovanni 2015-01-13 18:16 GMT+01:00 Ing. Pierluigi De Rosa < pierluigi.der...@gfosservices.it>: > Hi all, > > I have a line geometr

Re: [Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-14 Thread gene
It is a pure problem of analytical geometry or vector calculus (look at PyQGIS: geometry, vectors, vector algebra or direction cosines...(in French )) Is the line is straigh

Re: [Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-14 Thread Ing. Pierluigi De Rosa
Dear Gene, Maybe my have not been well explained but I don't need the straight cartesian distance but the distance following the line (as a path). I think the code posted by Giovanni should be fine for my case. I will test it right now. Thanks Pierluigi Il giorno mer, 14/01/2015 alle 00.05 -080

Re: [Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-14 Thread gene
I don't have the code posted by Giovanni but this is very easy to do with Shapely (a Python wrapper of GEOS). With PyQGIS, I do it in this way: 1) by definition a polyline is composed of straight segments between points (nodes) 2) after computing th

Re: [Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-14 Thread G. Allegri
https://gist.github.com/giohappy/f2abde1549aa2775b5aa 2015-01-14 10:40 GMT+01:00 gene : > I don't have the code posted by Giovanni but this is very easy to do with > Shapely (a Python wrapper of > GEOS). > > With PyQGIS, I do it in this way: > > 1) by

Re: [Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-14 Thread gene
= sum of segments length before the one where the intersecting point lies + the length between the first point of this segment and the intersection point -- View this message in context: http://osgeo-org.1560.x6.nabble.com/calculate-distance-from-two-points-along-line-in-pyqgis-tp5181313p518141

Re: [Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-14 Thread G. Allegri
Yes gene. Plus, this script considers a point not intersecting the line. 2015-01-14 10:49 GMT+01:00 gene : > = sum of segments length before the one where the intersecting point lies + > the length between the first point of this segment and the intersection > point > > > > -- > View this message

Re: [Qgis-developer] calculate distance from two points along line in pyqgis

2015-01-14 Thread gene
Therefore there is a quicker solution iterating through the segments of the line until a segment contains the point The Spatial predicate is *point.within(line)* but as there are floating point precision errors when finding a point on a line, I use the distance with an appropriate threshold. def