# QGIS Calculate distance between polygon vertices / find vertices that are within distance

I have polygon layer and i need to find (select, so i can export selected to new layer) all the vertices that are in provided distance to each other (like 2 meters).

1. Export polygon to point (Extract Node)
2. Run delete duplicates (as the extract node creates duplicates).
3. Create distance matrix (this one is problematic as it shows distance in datasource units which is dd and i want it to be meters)
4. Join tables and then filter them using distance < value

Is there a better way to achieve this, like a tool?

Might I suggest:

Right click on the layer and select Save As.. then specify a projected coordinate system to do your calculations in.

Convert polygon/line vertices to points instead of Extract Nodes. The first field (ID) is a backslash delimited field with sourceID/part/vertex to allow you to track back.

Add coordinates to points on the vertices to allow for easier calculation. I opened the dbf in Excel and used the distance formula:

``````=SQRT(( G3-G2)*(G3-G2) + (H3-H2)*(H3-H2))
``````

Which is simple Pythagorean maths.

Expanded to new polygons:

``````=IF(LEFT(A2,FIND("/",A2))=LEFT(A3,FIND("/",A3)),SQRT((G3-G2)*(G3-G2)+(H3-H2)*(H3-H2)),"New")
``````

Which puts in 'New' when the next vertex isn't the same polygon otherwise the difference. Then using:

``````=IF(I2 <> 0, IF(I2<2,LEFT(A2,FIND("/",A2)-1),"-1"),-2)
``````

I can find the ID of the polygon that contains short segments, in this case if the distance is 0 (same) then the value is -2, if it's a new polygon or the distance is greater it's -1 and for short segments it's the ID of the polygon.

Then save that to a CSV file (do not save the DBF) and you can reference all the polygons and locations where you have a short segment.

You could achieve similar results using the field calculator in QGIS but I used Excel because it's easier to get to the next row.

• It seems complicated. How do you calculate distance between last point of polygon with first? I think to make this work we cannot delete duplicates. – gisit Dec 5 '14 at 23:03
• Something similar can be achievied with 1. Polygon to line, 2. Explode lines, 3.filter query --> select all the lines with length < param – gisit Dec 5 '14 at 23:14
• @gisit Your point 2. Explode Lines, is there a way you know of to convert polylines into two-point lines? The question is in regard to segments (section between two consecutive vertices) not short parts, unless I completely misunderstood the question. – Michael Stimson Dec 7 '14 at 22:20
• Explode lines does convert line segments into separate lines (2-point lines), doesnt it? If yes exploding and calculating length of the lines will be similar to your answer. The question was not in regard to line segments but distance between vertices (not necessary consecutive). – gisit Dec 7 '14 at 23:51
• Doh! Perhaps a picture showing good & bad examples would help. – Michael Stimson Dec 7 '14 at 23:52