2

All, I have 2 layers as shown below enter image description here

What I want to do is go through each feature (in pink) and do a spatial filter against the green layer. My current code is

        inMemFeatCur = inMemFeatClass.Search(null, true);
        inMemFeature = inMemFeatCur.NextFeature();
        while (inMemFeature != null)
        {
            //set the spatial filter
            ISpatialFilter spaFil = new SpatialFilterClass();
            spaFil.Geometry = inMemFeature.Shape;
            spaFil.GeometryField = validationLayer.ShapeFieldName;
            spaFil.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            spaFil.SpatialRelDescription = "";

            //query the results from the spatial filter

            IFeatureCursor geomCursor = inMemFeatClass.Search(spaFil, true);

The problem is the when I go through the geomCursor, it will not find the polygon that is completely outside.

The check i want to do is each polygon (pink) completely within (common boundaries allowed) the green layer. If it is not, a warning will to appear.

I know that IRelationalOperator returns a bool, but i have to go through each green feature which I don't want to do, as I'll be looping many times for each pink feature.

Has anyone got any ideas on how to do this.

1

I would use the IFeatureSelection interface to obtain the selection set from an existing selection (so all pink polygons intersecting green polygons) and invert it.

Below is some VBA code to show you how to use ArcObjects and invert a selection.

Public Sub InvertSelection()
     ' Get map document
    Dim pMXDoc As IMxDocument
    Set pMXDoc = ThisDocument

    ' Get Map
    Dim pMap As IMap
    Set pMap = pMXDoc.FocusMap

    ' Get first layer and cast into FeatureLayer
    Dim pLayer As ILayer
    Set pLayer = pMap.Layer(0)
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pLayer

    ' Get selection on this layer
    Dim pFeatureSelection As IFeatureSelection
    Set pFeatureSelection = pFeatureLayer
    Dim pSelectionSet_Selected As ISelectionSet2
    Set pSelectionSet_Selected = pFeatureSelection.SelectionSet

    ' Create a "selectionset" of all rows in the layer
    Dim pSelectionSet_All  As ISelectionSet2
    Set pSelectionSet_All = pFeatureLayer.FeatureClass.Select(Nothing, esriSelectionTypeIDSet, esriSelectionOptionNormal, Nothing)

    ' Create the inverted selection
    Dim pSelectionSet_Inverted As ISelectionSet2
    pSelectionSet_All.Combine pSelectionSet_Selected, esriSetDifference, pSelectionSet_Inverted

    ' Referesh layer with inverted selection and update map
    Set pFeatureSelection.SelectionSet = pSelectionSet_Inverted
    pMXDoc.ActivatedView.Refresh
End Sub
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.