I was trying to make a function that modifies polygons removing narrow spaces inside (setting a minimum distance between a vertex and a segment that is not adjacent) and at the same time remove sharp edges (angles < 90). It is important that the resulting polygon doesn't have round edges. Something like this, the original shape is grey, while what I want is in red:
The use of the function
buffer
seems to be the answer.
Given a polygon Shape
, I need to do something like
Shape.buffer(-h).buffer(h)
to remove narrow spaces inside, and by using the variables cap_style
, join_style
and mitre_limit
, it should be able to deal with the sharp edges.
The problem is that I have no clue of what these variables mean, the documentation is very confusing regarding this function, the descriptions and examples are ambiguous. For instance it is not clear to me the difference between cap_style
and join_style
, from experience, the last seems to be overriding the former. Changing cap_style
while maintaining fixed join_style
doesn't change the shape at all.
From experience too, mitre_ratio
doesn't work while using join_style = 3
.
In the end, I found out that
shape2 = shape.buffer(-0.2, join_style = 2, mitre_limit=2., cap_style=2)
shape3 = shape2.buffer(0.2, join_style = 2, mitre_limit=2., cap_style=1)
Almost works, if it wasn't for a very small difference between the original polygon and the modified one. Even though the distance
parameter is exactly the same, the curves deviate somehow:
What is wrong with this solution? and what exactly are those parameters, and how are explicitly defined these methods?