ITopologicalOperator.Buffer Fails - Error 0x80040239

2222
6
05-25-2011 09:14 AM
TonyThatcher
New Contributor
This appears be something that a couple other people have run into going back to 2007 or so.

I am running a simple Buffer on a polygon.  See code below.  This Sub is a simplified version of a much more complex Function, but I've stripped it down to just the basics here to try and figure out what is going on.  This Sub is getting called from another routine that loops through a set of selected polygons, passing the current Feature to the Sub.  On occasion, the "topoOperator.Buffer(iBuffer)" line fails, returning the "0x80040239" Error.  It is ALWAYS on the same polygon, and ONLY when dBufferMiles = 5. If I change the buffer to 4.9 or 5.1, or just about any other number I've tried, the buffer works fine.  If I get rid of the 'convert to miles' text and just enter iBuffer = 8046 (e.g. 5 x 1069.3), it fails.  I've tried numbers slightly above and below 8046 as my buffer and it fails, so it appears to be a range of numbers for the buffer distance that it does not like.

I can select any other polygon and it works fine with a 5 mile buffer.  This is in ArcGIS 10, but it also cropped up occasionally in 9.3.  I'm using a Personal GDB.  I've cleaned the geometry, created a new File GDB, and exported out only that polygon; each with the same results.

I can usually run the Buffer tool from the Geoprocessing menu using a 5 mile buffer dist, but I've even seen that fail the first try, before working on the second try.  If I edit the polygon's vertices, then it will work, though I can't tell you which vertex solved the problem.  And if there was a problem with the geometry, then the Clean Geometry should have taken care of it.

Any thoughts?  This application works flawlessly for tens of thousands of polygons, but for some reason fails with certain polygons at specific buffer distances.  I'm stumped.

-Tony

Public Sub buffTest(ByVal pFeature As IFeature, ByVal pMap As IMap)
        Try
            Dim pLayer As IFeatureLayer
            Dim pCursor As IFeatureCursor = Nothing
            Dim sName As String

            sName = "clonelayer"
            pLayer = FindLayerByName(sName, pMap)

            Dim pFeat4Buff As IFeature
            pFeat4Buff = pFeature
            Dim pGeom As IGeometry = pFeat4Buff.Shape
            Dim topoOperator As ITopologicalOperator = CType(pGeom, ITopologicalOperator)

            Dim iBuffer As Long
            Dim dBufferMiles As Double

            dBufferMiles = 5
            iBuffer = Int(dBufferMiles * 1609.3) 'convert miles to meters.
            'iBuffer = 9000 'convert miles to meters.

            Dim buffer As IGeometry
            buffer = topoOperator.Buffer(iBuffer)
            Dim pArea As IArea
            pArea = buffer
            MsgBox(pArea.Area / 4047, vbNormal, "Buffer Acres")

        Catch ex As Exception
            MsgBox("Buffer Error: " & ex.Message & " - Stack Trace: " & ex.StackTrace, vbInformation, "Buffer Select Error")

        End Try

    End Sub
0 Kudos
6 Replies
KenBuja
MVP Esteemed Contributor
Does this happen with only integer numbers as opposed to decimals or just 5 but not 6? Try forcing the number to a double data type as in


Dim dBufferMiles As Double = 5.0R
or
Dim dBufferMiles# = 5
0 Kudos
JamesCrandall
MVP Frequent Contributor
It is ALWAYS on the same polygon, and ONLY when dBufferMiles = 5. If I change the buffer to 4.9 or 5.1, or just about any other number I've tried, the buffer works fine.


Would this be a problem of Integer values rather than Double/Decimal values being used (ie, fails when the integer 5 is used)?
0 Kudos
JamesCrandall
MVP Frequent Contributor
Does this happen with only integer numbers as opposed to decimals or just 5 but not 6? Try forcing the number to a double data type as in


Dim dBufferMiles As Double = 5.0R
or
Dim dBufferMiles# = 5


Doh -- we were reading the same thing.  You were fast on the answering.

Sorry there, Ken -- didn't mean to barge in!
0 Kudos
TonyThatcher
New Contributor
Dang! Fast fingers, guys!

But, no.  Forcing it to be an integer does not help.  I tried that earlier, with no luck.

That error shows up somewhere in the depths of the ESRI web as an Internal Geometry Error, or something like that.  I played around with some of the vertices and found a single vertex that, if moved, it would run fine.  See attached image.  This is a tiny, 1-meter notch on one edge.  One of many similar vertices.  If I move the vertex and straiten out the edge, it runs fine.  There is no way that this little spot should cause a buffer to fail!  It runs at just about any buffer distance, integer or floating, except for right at or around 5 miles.

And there is no way that the user can or should have to go in and find the one little vertex that is causing problems.  This is the tail end of a long data processing routine, and it works on 99.9999 percent of the polygons.

-T
0 Kudos
JamesCrandall
MVP Frequent Contributor
Dang! Fast fingers, guys!

But, no.  Forcing it to be an integer does not help.  I tried that earlier, with no luck.

That error shows up somewhere in the depths of the ESRI web as an Internal Geometry Error, or something like that.  I played around with some of the vertices and found a single vertex that, if moved, it would run fine.  -T


I cannot seem to replicate the error you are seeing -- switching around the miles value from whole integers (5) to double values.  I even added a little 1-meter notch into the polygon per the image you posted, and still your sub/code ran without error.

0 Kudos
TonyThatcher
New Contributor
I know, it's very strange.  I even went so far as to trace the offending polygon, vertex for vertex and still got the error.  If anyone wants to play, I've attached the file GDB.  There is only the one polygon in it.

-Tony
0 Kudos