Question

So I have some code that performs a spatial selection on a featurelayer using a spatial filter. This works fine for normal featureclass layers, but fails when run on an SDE featureclass. I'm wondering if anyone could shed some light onto what the problem might be? The error i'm getting is an HRESULT 0x80041515 which gives me an error code that I can find any information on anywhere. My function takes a polyline and a layer string, and selects a polygon in the layer based on the centerpoint of the line. Here's a sample of the code:

        ' Creates centerpoint of line envelope
        Dim pCenterPoint As IPoint = New Point
        pCenterPoint.SpatialReference = pPolyline.SpatialReference
        pCenterPoint.PutCoords((pPolyline.Envelope.XMin + pPolyline.Envelope.XMax) / 2, (pPolyline.Envelope.YMin + pPolyline.Envelope.YMax) / 2)

        ' Expands envelope
        Dim eCenterEnvelope As IEnvelope
        eCenterEnvelope = pCenterPoint.Envelope
        eCenterEnvelope.Expand(pMxDoc.SearchTolerance, pMxDoc.SearchTolerance, False)

        ' Get layer of interest
        Dim pLayer As IFeatureLayer = FindLayerByName(strSelect, layerType.FeatureLayer, False, False)
        pLayer.Selectable = True

        ' Create spatial filter
        Dim spatialFilter As ISpatialFilter = New SpatialFilterClass()
        spatialFilter.Geometry = eCenterEnvelope
        spatialFilter.GeometryField = pLayer.Name
        spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
        Dim queryFilter As IQueryFilter = New QueryFilterClass()
        queryFilter = CType(spatialFilter, IQueryFilter)

        ' Select features
        Dim pFeatureSelection As IFeatureSelection = pLayer
        pFeatureSelection.Clear() 'clear any current selections in the layer first
        pFeatureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultAdd, True)
        If pFeatureSelection.SelectionSet.Count = 0 Then
            Return False
        Else
            Return True
        End If

The code fails when I call pFeatureSelection.SelectFeatures(), but only when the featurelayer belongs to an SDE featureclass. Any ideas?

Thanks,

Luke

Was it helpful?

Solution

So I finally resolved this issue by adjusting the input geometry field to the spatial filter that I created.

I changed this: spatialFilter.GeometryField = pLayer.Name

to this: spatialFilter.GeometryField = pLayer.FeatureClass.ShapeFieldName

Success!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top