6

I have a a dataframe of polygons in GeoPandas/shapely. Most of them are valid, and remaining invalid polygons can be removed with ".is_valid" command. However, some polygons are in theory valid, but in practice useless.

My issue is the case in the image below. The polygon consists of 3 vertices, but one vertex is, all but, on the line with the other points. Is there a way I can mark this polygon as invalid and remove it? I know the QGIS Fix Geometries is able to identify this issue. I can do a quick fix by using the polygon area and removing under a threshold, but I was hoping there is a more elegant solution to detect this.

Polygon is the line, point show vertices for clarity

3
  • 2
    Does the area method detect polygons you want to keep or what is the problem?
    – BERA
    Oct 3, 2022 at 16:59
  • Similarily not sure why area method is not good enough. Another approach would be to check for each point of a 3-point polygon if one of the vertices is very close to the line connecting the two other points (buffer this line and check if the 3rd vertex is inside).
    – Babel
    Oct 4, 2022 at 7:17
  • Another approach: calculate lengths of the 3 sides and see if the largest side is more or less equal (allowing a small threshold) than the sum of the two other sides.
    – Babel
    Oct 4, 2022 at 7:19

1 Answer 1

7

What determines your polygon that is too skinny? You could calculate the isoperimetric quotient for you polygons, then determine an IQ value that meets your criteria. Then select and delete those polygons with an IQ that is too small.

Here is the formula for IQ where a result of 1.0 describes a perfect circle.

IQ = (4 * pi * area) / (perimeter^2)

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.