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

Ing. Pierluigi De Rosa pierluigi.derosa at gfosservices.it
Wed Jan 14 00:35:28 PST 2015


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 -0800, gene ha scritto:
> 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.
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 

                                    
________________________________________________________________________
Ing. Pierluigi De Rosa (PhD)
Studio Associato GFOSSERVICES
                
Presso CAMPUS Via F.lli Cairoli 25 - 06127 Perugia (PG) 
fax: 075 7823038
cel: 3497558268
web: www.gfosservices.it
skype: pierluigi.derosa 



More information about the Qgis-developer mailing list