Take the 2-minute tour ×
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 have an intermittent error that I'm having a terrible time tracking down so I thought I'd see if anyone has encountered something similar.

I am trying to access the label point of a polygon feature to put a text element there. Using ArcGIS 10.0 SP5, VB.net.

When I attempt to set the element's geometry to IArea.LabelPoint, I alternatively get "There is not enough memory," "Operation attempted on empty geometry," or "The operation could not be performed because the object was geometrically degenerate." So far this is only happening for one feature - other features in the same feature class work fine. The feature class is in an SDE so I can't do a Check Geometry.

The feature geometry is NOT empty (checked with IFeature.IsEmpty). I've checked the IPolygon4.IsEmpty property and it is False...until I try to do something with IArea, at which point sometimes changes to True (but not always)...regardless, when I check for empty geometry, the check passes fine, so doesn't stop the error. I've included the relevant bits of my code below - any ideas? At this point I don't even care about making the element for this particular feature, I'd be happy just to know what condition to check so that I don't get a fatal error when I try to access its LabelPoint.

(pFeature is an IFeature determined ahead of time)

Dim pTextElement As ESRI.ArcGIS.Carto.ITextElement
Dim pElement As ESRI.ArcGIS.Carto.IElement
Dim pPolygon As ESRI.ArcGIS.Geometry.IPolygon4
Dim pArea As ESRI.ArcGIS.Geometry.IArea
 If pFeature IsNot Nothing Then 
     If pFeature.Shape IsNot Nothing AndAlso Not pFeature.Shape.IsEmpty Then
          'get the geometry 
          pPolygon = pFeature.Shape
          'get the pointer to the IArea interface so we can get the labelpoint
          pArea = CType(pPolygon, ESRI.ArcGIS.Geometry.IArea)
          'new TextElement    
          pTextElement = New ESRI.ArcGIS.Carto.TextElement
          'Query Interface (QI) to an IElement pointer and set the geometry    
          pElement = pTextElement
          pElement.Geometry = pArea.LabelPoint
      End If
  End If

The error occurs on the pArea.LabelPoint, and debugging shows that the error is with the LabelPoint; pArea is not Nothing and has 0 area and one of the error messages listed earlier for Centroid and LabelPoint.

Edit: In case it helps, the various properties of the 3 main objects during debugging: DebuggerImage

Edit #2: Because it didn't paste well in the comments, here was my workaround:

        Dim pSafeFeature As ESRI.ArcGIS.Geodatabase.IFeature
        Dim pParcelFC As ESRI.ArcGIS.Geodatabase.IFeatureClass
        If pFeature IsNot Nothing Then 
            pParcelFC = CType(pFeature.Class, ESRI.ArcGIS.Geodatabase.IFeatureClass)
            pSafeFeature = pParcelFC.GetFeature(pFeature.OID)
...

Proceeding with pSafeFeature instead of pFeature, everything works fine.

share|improve this question
    
I'm still confused about WHY this error occurred, so if anyone out there has an idea why one feature out of the dozens of features that this worked for suddenly decided to misbehave, please let me know! –  BeckyZ Dec 19 '12 at 19:29

1 Answer 1

up vote 1 down vote accepted

The code snippet you posted doesn't look bad. Perhaps grabbing the feature's .ShapeCopy instead would make a difference. And remove the implicit conversions:

Dim pPolygon As IPolygon4 = CType(pFeature.ShapeCopy, IPolygon4)
'get the pointer to the IArea interface so we can get the labelpoint
Dim pArea As IArea = CType(pPolygon, ESRI.ArcGIS.Geometry.IArea)
'new TextElement    
Dim pTextElement As ITextElement = New ESRI.ArcGIS.Carto.TextElementClass()
'Query Interface (QI) to an IElement pointer and set the geometry    
Dim pElement As IElement = CType(pTextElement, IElement)
pElement.Geometry = pArea.LabelPoint
share|improve this answer
    
Thanks for your suggestion. I've modified my code as you suggested - an improvement in any case - but unfortunately I still get the same error. –  BeckyZ Dec 19 '12 at 18:57
    
Your probably need to trace the code back further. When do you open the pFeature object? Check that it doesn't go out of scope, etc. –  Rich Wawrzonek Dec 19 '12 at 19:00
    
Somehow you must be right. I don't know why it would only be a problem for this feature and not for the dozens of others that have passed through just fine, but I found a workaround by re-retrieving the feature like so: –  BeckyZ Dec 19 '12 at 19:24
    
Dim pSafeFeature As ESRI.ArcGIS.Geodatabase.IFeature Dim pParcelFC As ESRI.ArcGIS.Geodatabase.IFeatureClass If Not pFeature Is Nothing Then pParcelFC = CType(pFeature.Class, ESRI.ArcGIS.Geodatabase.IFeatureClass) pSafeFeature = pParcelFC.GetFeature(pFeature.OID) and then proceeding with pSafeFeature instead of pFeature. –  BeckyZ Dec 19 '12 at 19:25
    
Glad it worked. Whenever memory errors arise I always make sure I'm handling my feature loops and workspaces correctly. This blog and included link are worth a look: blogs.esri.com/esri/arcgis/2008/12/18/… –  Rich Wawrzonek Dec 19 '12 at 19:34

Your Answer

 
discard

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.