Updating polygon geometry: deleting inner rings with python
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
row=rows.Next()
try:
while row:
if row.shape.area < 200: #it's just deleting small polygons
rows.DeleteRow(row)
else: #part of cleaning from inner rings (donuts)
geom=row.shape
array=geom.GetPart(0)
pnt=array.Next()
newarray = gp.CreateObject("Array") #writing geometry to newArray
while pnt:
newarray.add(pnt)
pnt=array.Next()
newpnt=newarray.Next()
if not pnt: #this is the HOLE!
break #when detect - break the loop!
row.shape=newarray
rows.UpdateRow(row)
row=rows.Next()
del row
del rows
except:
gp.GetMessages()
The part about deleting the features. Seems it's often not allowed. Found, there is a possibilty to test it: http://www.gdal.org/ogr/classOGRLayer.html#aeedbda1a62f9b89b8e5f24332cf22286
layer.TestCapability("DeleteField")
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.