[Qgis-developer] calculate distance from two points along line in pyqgis
gene
martin.laloux at gmail.com
Wed Jan 14 00:05:53 PST 2015
It is a pure problem of analytical geometry or vector calculus (look at
PyQGIS: geometry, vectors, vector algebra or direction cosines...(in French
<http://www.portailsig.org/content/pyqgis-des-geometries-des-vecteurs-de-l-algebre-vectorielle-ou-des-cosinus-directeurs>
))
Is the line is straight the cartesian distance between two points is given
by
def distance(point1,point2):
#Theoretical cartesian Euclidean distance between 2 points (x,y)
return math.sqrt((point2.x()-point1.x())**2 +
(point2.y()-point1.y())**2)
As PyQGIS has the sqrDist function, you can replace by
def distance(point1,point2):
return math.sqrt(point1.sqrDist(point2))
By definition, the point of intersection between two lines lies on the two
lines. It is easy to extract the start point or the end point of the lines
and calculate the distance.
If you want a confirmation, there are many algorithms in Python to verify
that 3 points are collinear
If the line has many segments, work at the straight segments level
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/calculate-distance-from-two-points-along-line-in-pyqgis-tp5181313p5181376.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
More information about the Qgis-developer
mailing list