I use OGR & Python to develop a geodesic polygon buffer. The buffered polygon is generated from a polyline ring. The polyline ring is generated from point coordinates. As the polyline ring is often self-intersecting, this leads to holes in the buffered polygon geometry. For the outer boundary of a self-intersecting line / polygon, applying a Buffer of 0 to the buffered polygon geometry is a widely used workaround to fill holes from self-intersections and to generate a correctly displayed polygon. However, I have difficulties buffering polygons with holes.

A (buffered) polygon with a hole consists of two lines: An outer line from which I want to determine the most outer boundary (using a Buffer of 0) and an inner line, from which i want to determine the most inner boundary. The workaround using a Buffer of 0 only determines the most outer boundary of a self-intersecting polygon. I am thereby looking for a workaround in order to determine the most inner boundary of a self-intersecting polygon (for applying the buffer to the hole).

The polygon I want to buffer:

enter image description here

I applied several buffer widths. The polyline rings and buffer vertices for the respective buffer polygons are displayed here. In order to create a buffered polygon with a hole inside, I need to determine the most outer boundary of the outer line and the most inner boundary of the inner line:

enter image description here

The polylines are self-intersecting and lead to Polygons with small holes (hole in the top right corner of the polygon):

enter image description here

As for the outer boundary, I use a Buffer of 0 in order to determine the most outer boundary of the outer Polyline. At this point, the hole in the top right corner is closed:

enter image description here

However, this approach can not be used for the inner ring of the polygon. I need to determine the most inner boundary of the self-intersecting inner polyline (Lines inside the hole in Image 2). From both, outer line with outer boundary (which I already have) and inner line with inner boundary I want to generate a buffered polygon with a hole inside.

Is there a workaround for this?

  • can you just treat each ring as a separate polygon for the purposes of fixing them and then combine the holes into the final polygon when done?
    – Ian Turton
    Commented Sep 8, 2016 at 12:15
  • Actually, this is what I'm currently trying. I extract and process the outer ring and the inner ring separately and combine them to a polygon (outer ring) with hole (inner ring) in the end. I fill the holes of the outer ring by applying a buffer of 0 (to get the 'outer extent'). What I don't know is how to process the inner ring in order to get the 'inner extent' of the inner ring.
    – C.Riedel
    Commented Sep 8, 2016 at 12:22
  • buffer(-0.01) ?
    – Ian Turton
    Commented Sep 8, 2016 at 12:46
  • Buffer(-0.01) has similar results as buffer(0) (they are slightly closer to the polygon boundaries). I get triangle-shaped features inside the hole. The triangles are the self-intersection areas of the inner polyline.
    – C.Riedel
    Commented Sep 8, 2016 at 13:01
  • 2
    Buffering a polygon to remove self-intersection is a super hacky way to do it. You can't expect it to work all of the time because of the nuances involved in geometries. If you really want to remove all self intersects you need to first break the polygon into individual geometries (inner, outer etc.), intersect the geometry with itself to determine the vertex where the self intersect is happening, cut out all vertices within the self intersection, and stitch the polygon closed with the self intersect removed.
    – onakua
    Commented Dec 17, 2017 at 23:29

1 Answer 1


In PostGIS: This statement breaks up the buffered inner ring into 5 separate polygons and returns the one with more than 4 points (4 points define a closed triangle).

WITH p AS (SELECT (ST_Dump(ST_Polygonize(ST_Node(ST_ExteriorRing(ST_GeomFromText('POLYGON ((0 10,90 40,90 20,50 60,60 60,10 30,20 50,30 0,0 10))')))))).geom AS ring)

WHERE ST_Npoints(ring) > 4
  • Sorry for the late answer. I didn't get to work on this issue for the last two weeks. Your suggestion is worth testing. However, I'm using OGR & Python and not PostGIS. Is there a simlar function in Python available? So far, I haven't found any.
    – C.Riedel
    Commented Sep 21, 2016 at 9:00
  • neat trick with the st_npoints > 4... I have ran into this problem many times havent thought about this one
    – ziggy
    Commented Mar 2, 2018 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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