QGIS Geometry Generator – Drawing Line Arrow from Origin/Destination Coordinates Fields

connectioncoordinatesgeometry-generatorpolyline-creationqgis

From the following table structure with the fields "ORIG_LATITUDE", "ORIG_LONGITUDE", "DEST_LATITUDE", "DEST_LONGITUDE":

enter image description here

I clarify that the field names describe with their prefix the coordinates belonging to the Origin (ORIG) and Destination (DEST).

I would like to draw an arrow with the make_line function that connects the point defined by the fields of each record "ORIG_LATITUDE", "ORIG_LONGITUDE" with the fields "DEST_LATITUDE", "DEST_LONGITUDE", as shown in this image

enter image description here

Best Answer

Use this expression:

make_line(
   make_point("ORIG_LON", "ORIG_LAT"),
   make_point("DEST_LON", "DEST_LAT")
   )

If you have a data-only table, without geometry, there are two options: load the table as a point layer first (as recommended by @J.R) or, if you want to avoid this, create directly a new Virtual Layer, containing the lines.

The query in the virtual layer looks like this:

select make_line(make_point(t.ORIG_LON, t.ORIG_LAT), make_point(t.DEST_LON, t.DEST_LAT))
from your_table_name as t

You can then export/save the virtual layer to make the resulting lines permanent (not depending on the table any more).