Skip to main content
1 of 4
michael
  • 1.8k
  • 3
  • 21
  • 43

QGIS/Pyqgis/PostGis: Snap points to route and calculate relative length from start

Input:

  1. Points layer points spread around some route
  2. Route layer route where each route link is feature of type Multi Linestring. However it's possible to merge it to single feature layer of type Multi Linestring using Qgis GUI Merge Lines tool (I haven't succeed to merge to single feature of type Linestring-this is important later on)

What I want to calculate:

Snap each point to the route with a length field indicating length distance along the route from the beginning of the route (and not beginning of the nearest route link etc.).

What I tried:

  1. Using PostGis I tried

    ST_Line_Locate_Point(ST_MakeLine(route.geom), points.geom)

I need ST_MakeLine to form single LineString (as I told it's Multi Linestring), The problem is that still ST_Line_Locate_Point returns error "first argument isn't Line", so I don't know whats going on here.

  1. Searched in all Qgis tool box for appropriate methods - haven't found one.
  2. Tried LRS plugin - seems not relevant for this use case.
michael
  • 1.8k
  • 3
  • 21
  • 43