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 '21 at 8:04
  • Just to get the distance (number in meter) between 2 points inside the polygon
    – Arief
    Jun 25 '21 at 6:57
  • Please, do not forget about "What should I do when someone answers my question?"
    – Taras
    Oct 7 '21 at 5:41
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

2
  • 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 '21 at 4:12
  • 2
    As a new user, please be aware that this site tries to avoid thank you messages. If an answer was helpful and solved your problem, you should instead accept it: hit the checkmark icon.
    – Babel
    Jun 26 '21 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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