3

In QGIS 3.10 I have two layers, first one is point layer and the second one is polygon layer.

Every two points (with same "ID") in my point layer overlay with a single polygon in polygon layer.

How do I get the minimum distance between 2 points in each polygon?

Illustration

3
  • What kind of output do you need, simply a number or a line with it's length or something different?
    – Taras
    Jun 24, 2021 at 8:04
  • Just to get the distance (number in meter) between 2 points inside the polygon
    – Arief
    Jun 25, 2021 at 6:57
  • Please, do not forget about "What should I do when someone answers my question?"
    – Taras
    Oct 7, 2021 at 5:41

1 Answer 1

6

If your two points have a common "ID" field, use this expression to create a new field with field calculator:

length (
    make_line (
        $geometry,
        geometry (
            get_feature (
                @layer,
                'ID',
                ID
))))

If you first have to create the "ID", use array_first(overlay_within('polygon', $id)) (available since QGIS 3.16).

Points with same "ID" (labeled), connected with a line created on the basis of the above expression. With the expression above, you get the length of these lines:

enter image description here

1
  • Thank you sir...your answer works! and I don't need the polygon layer because every two point already in same ID
    – Arief
    Jun 26, 2021 at 4:12

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.