Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've searched, but can't find clear explanations how can I simply delete inner rings from existing polygons with python or extract outter rings and overwrite the geometry. Seems GDAL/OGR should be the simplest, but still I need some help...

Simple vision of mine would be:

for i in xrange(layer.GetFeatureCount()):
    feature = layer.GetFeature(i)
    geometry = feature.GetGeometryRef()
    if geometry.GetArea()<200:
    if geometry.GetGeometryCount()>1:
        geometry=geometry.GetGeometryRef(0) #overwrite geom, getting the first ring outer


This doesn't loop through, it's just how I would like to see.

As I know the first ring or the first part of the geometry should be the outer ring, so I assumed I can just ask for it like that.Suppose that's not a problem.

So, probably the question is just about Updating Geometry. I open dataset withouth specific- Reading or Writing, so I assume it should let me write in it not just read. But if I do not want to have a new dataset, can I just update write like that or i should anywhays better create a new dataset?

Or maybe there is even more simple way to solve this with python?

share|improve this question

2 Answers 2

The part about deleting the features. Seems it's often not allowed. Found, there is a possibilty to test it:


and so I get False..

And accessing just the first ring goes well, I've checked with area calculations.

The solution then is just to CREATE a new file with features I need from old file.. Correct me if I am misstaken.

share|improve this answer
You are correct. Updatability of layers varies over formats, but creation of a new dataset always works. –  sgillies Sep 17 '12 at 14:50
Seems I at such point I am comming back to arcgisscripting.. –  najuste Sep 17 '12 at 15:02
up vote 1 down vote accepted

I've found the solution with arcgisscripting, if anyone gona need to automate it.

It's really simple,.. just required some time to catch those holes :)

rows=gp.UpdateCursor(shp) #everything is done with one Cursor, but couple of arrays
    while row:
        if row.shape.area < 200:  #it's just deleting small polygons
        else:                     #part of cleaning from inner rings (donuts)
            newarray = gp.CreateObject("Array") #writing geometry to newArray       
            while pnt:
                if not pnt:                     #this is the HOLE! 
                    break                       #when detect - break the loop!

    del row
    del rows
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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