I have a CSV file that contains attributes for a start node and end node of a pipe in a single record. This is data collected in the field, so the inspector captures the lat/long at each end of the pipe, and then I load the CSV into QGIS to use other attribute data. I would like to find a way to automate/repeat creating a line layer that draws a feature from each start node attribute to the end node attribute for each record.

Here is an example of the data captured in the field. I would like to automate creating a single line from "Location of inlet" to "Location of outlet" for each record in the CSV.

Example of start/end node attributes

  • 3
    Providing this sample data not as a screenshot, but as actual data would help using it for testing.
    – Babel
    Aug 18, 2021 at 15:57

4 Answers 4

  1. Load the CSV-file twice as a point-layer - see: Importing a delimited text file:
  • The first time, set the coordinates for inlet (lat/lon 1) as coordinate values,

  • the second time those for outlet (lat/lon 2).

    You get two point-layers, one for inlet, one for outlet. Be sure to define the Geometry-CRS as EPSG:4326 (cf. screenshot).

  1. On the inlet layer, now create a line using "Geometry generator" or "Geometry by expression" (see here for details). Use this expression, it will create the lines:
make_line (
        get_feature_by_id('outlet', $id)

Loading the outlet-layer at the bottom left, creating the line geometry using Geometry generator at the upper right:

enter image description here


The "PointsToPaths" plugin (note the plural "Paths") will output a separate line feature for each sequential pair of input points.

Additionally, the tool will add two new fields to the output attribute table that contain the beginning and ending point values, which in your example would be "Location of inlet" and "Location of outlet". Make sure that you check on the Line per vertex option.

enter image description here


This is not straight-forward, but I don't know any alternative in QGIS:

You can use the Points to Path Vector creation tool (search in the Processing Toolbox). To use it, you need to restructure your data (most convenient if you're familiar with Python or R): Each point needs to be in a seperate row, not one row for both start and end points. Create an attribute that is 0 for start points and 1 for end points (for parameter Order field). Furthermore, start and end point need to have one similar attribute/id (for parameter Group field) - then you're ready to use the tool.


You could edit your csv file to create a new field containing the WKT for a linestring. This could be accomplished using a spreadsheet program, a text editor, or any other method. Then load the CSV file into Qgis and declare that new field to be the geometry for that record.

Admittedly a bit hacky, but it's a fallback when you have data you can't coerce otherwise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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