1

I'd like to calculate length of some paths with defined vertexes and each route is characterized by some records.

For example, I need the length of all combinations of lines (AB, BC, CD, AD, AC, BD).

Is there a Geoprocessing tool or QGIS Plug-in to do this, avoiding merging the records of the single path manually?

example

  • Are your lines a one(single) feature or they are already split on vertices, e.g. many features in a shapefile? – Taras Apr 20 at 6:58
  • There is a single shapefile splitted on vertices and characterized by many records (without relation field). The output should be a shapefile with 6 features with the field "length", and these will be obviously overlapped. – Mark Apr 20 at 17:54
1

In QGIS I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer....

Let's assume we have two layers "vertices" and "paths" with its corresponding attribute tables, see image below.

input

With the following query, it is possible to calculate length of some paths with defined vertexes and each route is characterized by some records.

SELECT p.geometry AS geom,
       v1.Name AS "from_point",
       v2.Name AS "to_point",
       round(st_length(p.geometry),4) AS "path_length"
FROM "paths" AS p
LEFT JOIN "vertices" AS v1 ON st_touches(p.geometry, v1.geometry)
LEFT JOIN "vertices" AS v2 ON st_touches(p.geometry, v2.geometry)
WHERE v1.id <> v2.id

The output Virtual Layer with its Attribute table will look as following

output

Notes:

  • The output layer will contain some geometry twice, i.e. path 1->2 is the same as 2->1
  • This approach will only work when paths are broken at vertices and vertices are snapped to paths
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.