4

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

0

1 Answer 1

6

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).

5
  • I understand the idea of this expression, but I understand that it works for a layer with point geometry. In the case of my project, the difficulty I find is that the data source is a table. How can I apply this expression to a table? Do I have to transform the table into a point layer and then apply the expression? Jun 1 at 12:58
  • 2
    Yes to use the geometry generator you need to have vector data, a single table wont work. As you have coordinate you may load the table as a point layer first then use @Babel expression
    – J.R
    Jun 1 at 13:06
  • 1
    Indeed, thanks @J.R, it's exactly as you say. Another option is to create a virtual layer to avoid loading the initial table as points layer, see updated answer.
    – Babel
    Jun 1 at 14:09
  • 2
    @Babel doesn't the make_point use (x, y) or (Lon, Lat) rather than (Lat, Lon) ?
    – J.R
    Jun 1 at 14:45
  • 1
    @J.R indeed, you're completely right. I was using dummy coordinates and was so focused on the syntax that this indeed very basic mistake skipped my attention. Good you drew our attention to this, I corrected the answer.
    – Babel
    Jun 1 at 14:58

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.