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:
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.