4

I have a map divided in parts using polygons, and I want to measure the length of the boundary between each pair. I am using this script from a tutorial to find the actual neighbors, and then measure the shared boundary with this code:

ring_f = QgsGeometry.fromPolyline(f.geometry().asPolygon()[0])
ring_intersecting = QgsGeometry.fromPolyline(intersecting_f.geometry().asPolygon()[0])
ring_intersection = ring_f.intersection(ring_intersecting)

Where f is the active feature and intersecting_f is iterated in a list of all features intersecting f. However, the script is giving incomplete measurements in some features. For example, below are, whose shared border is near 367m as measured manually using Qgis, but the script returns 224.91. Wierdly enough, what the script returns coincides with measuring between the red crosses encircled in green by me (it would be nice to now what this crosses are, by the way).

sections 2 and 8

Does anyone have any idea of what might be happening?

  • The red crosses are the nodes of the polygons. Check that the bottom left node (cross) of 2 is exactly the same as the top left of 8. If they are not, then the edge will not be counted as 'intersecting' – firefly-orange Nov 7 '17 at 11:54
  • Yes, the node in the lower left of 2 is the same for 8, 2 and the two rightmost polygons. – Jorge Rotter Nov 8 '17 at 20:52
1

Turns out there were gaps between the polygons, which I detected using the topology checker.

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.