3

I have two point layers each with a single point in them. I want to draw a line joining the points to use to measure the distance apart.

I have found various plug-ins which allow this, but is there a way I can actually link the point coordinates to the line layer so that if I move one of the points the line will update automatically?

2 Answers 2

1

Install the plugin Points2One pluginand follow the dialog to create a line from your points. Save as geojson, this should provide you with lines between the two points, the part about moving the points coordinates and the layer updates automatically that would be possible, as far as I'm aware.

enter image description here

1
  • Thanks for your reply. I wasn't able to use this plugin because my two input points are in different layers. Apologies that my original post didn't meet the message board requirements.
    – simonc8
    Commented Oct 13, 2017 at 10:54
1

Just about your "the line will update automatically" part, a virtual layer may help.

In this example I have prepared two point layers

  • my_From.shp layer with a field from_id
  • my_To.shp layer with a field to_id

And the actual workflow to create a line (virtual) layer is:

  1. Layer | Add Layer | Add Virtual Layer
  2. Embedded layers - [Import] above two layers
  3. In the Query field, give a query (as below).
  4. Click on [OK], and a virtual layer with connected lines will be created.
  5. NB. when you add a point in a layer, please make sure you have identical ids in from_id and to_id.

Query:

SELECT 
    my_From.from_id,
    my_To.to_id,
    make_line(my_From.geometry, my_To.geometry) geometry
FROM my_From CROSS JOIN my_To
WHERE my_From.from_id = my_To.to_id

[EDIT] To include a field line_length, please use a query below. Labeling with this field is also possible.

SELECT 
    my_From.from_id,
    my_To.to_id,
    make_line(my_From.geometry, my_To.geometry) geometry,
    st_distance(my_From.geometry, my_To.geometry) AS line_length
FROM my_From CROSS JOIN my_To
WHERE my_From.from_id = my_To.to_id

Lastly, when you add a new point please open the layer properties of the virtual layer and click on [Apply] to refresh the layer. (so it is semi-automatic..., not 100% automatic... sorry).

3
  • Thank you very much for this. I had never used Virtual Layers before. The line was created exactly as hoped, but I am unable to edit it to calculate its length, presumably because it's in a virtual layer. Do you have to put the length calculation into the Query in some way? How could I do this?
    – simonc8
    Commented Oct 13, 2017 at 10:51
  • Update on previous comment: I have been able to use Field Calculator to calculate a virtual Length field, and the correct value appeared at the bottom of the Field Calculator, but when I clicked OK and looked at the Attribute Table the Length field showed as NULL, and when I tried to use this field as a label when plotting the line nothing appeared. Is there something else I need to do with the virtual length field?
    – simonc8
    Commented Oct 13, 2017 at 11:03
  • @simonc8 My apologies for not responding earlier. For some reason I missed your messages yesterday. Please add a st_distance() in the query (as in my updated answer).
    – Kazuhito
    Commented Oct 14, 2017 at 0:54

Your Answer

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

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