Select by location

Discussion created by ginomellino on Oct 5, 2011
Latest reply on Oct 7, 2011 by jamesfreddyc

Not sure if this is posted in the correct area so if not then please let me know.

I am trying to select polygon features from one layer which share some of their interior area with polygon features from another layer (if their boundaries only touch I do not want them to be selected, only if their boundaries cross each other). The overall goal is to make the layers mutually exclusive from each other similar to topological checks.

At present I am trying to (unsuccessfully) do this using a spatialfilter and select as in the code below. It doesn't return any features.

I am wondering if this is the best way to perform this task and if so why my code below isn???t working (it works fine for an esriSpatialRelIntersects).

Thanks in advance for your help,

Public Sub GetAffectedMUIDs()

        Dim pTargetLayer As IFeatureLayer
        If g_sMUIDType = "Supply Zone" Then
            pTargetLayer = GetLayerInTOC("QUARRY_RESOURCEMUID_DRAFT")
        ElseIf g_sMUIDType = "Resource" Then
            pTargetLayer = GetLayerInTOC("QUARRY_SUPPLYZONEMUID_DRAFT")
        End If

        Dim pQueryLayer As IFeatureLayer
        pQueryLayer = g_pEditFeatureLayer

        Dim pSI As ISpatialIndex
        pSI = MakeBag(pQueryLayer)
        If pSI Is Nothing Then Exit Sub
        pSI.AllowIndexing = True

        Dim pSF As ISpatialFilter
        pSF = New SpatialFilter
        pSF.Geometry = pSI

        pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelRelation
        pSF.SpatialRelDescription = "T**T*****"

        Dim pFSel As IFeatureSelection
        pFSel = pTargetLayer
        pFSel.SelectFeatures(pSF, esriSelectionResultEnum.esriSelectionResultNew, False)


    End Sub

    Function MakeBag(ByVal pFSel As IFeatureSelection) As IGeometryCollection
        ' make a geometrybag of all feature geometries within the edit MUID layers
        Dim pFCur As IFeatureCursor
        pFCur = g_pEditFeatureLayer.Search(Nothing, False)

        Dim pFeat As IFeature
        pFeat = pFCur.NextFeature
        Do Until pFeat Is Nothing
            If MakeBag Is Nothing Then
                MakeBag = New GeometryBag
            End If
            pFeat = pFCur.NextFeature

    End Function