ArcObjects Library Reference (Geometry)  

IRelationResult Interface

Provides access to members that find the distance between two geometries. Not currently implemented for geometries containing elliptic arcs.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Members

Description
Method Add
Method FlipRelations
Method Intersect
Read-only property RelationElement The ith element of the relation. The indexes refer to elements of the left and right operand geometry bags.
Read-only property RelationElementCount The number of pairs of geometries in the relation.
Method SetRelationElement The ith element of the relation. The indexes refer to elements of the left and right operand geometry bags.
Method SetRelationElements Sets RelationResult with an array of relations.
Method SortLeft
Method SortRight
Method Subtract

CoClasses that implement IRelationResult

CoClasses and Classes Description
RelationResult The indexes of geometrybag elements that are in a specified relation.
[C#]

        void DemoIRelationResult(IFeatureClass featClsPolygon0, IFeatureClass featClsPolyline0)
        {
            try
            {
                object obj = Type.Missing;
                IGeometryCollection geomCollGon = new GeometryBagClass() as IGeometryCollection;
                IFeatureCursor featCur = featClsPolygon0.Search(null, false);
                IFeature feat = featCur.NextFeature();
                while (feat != null)
                {
                    geomCollGon.AddGeometry(feat.ShapeCopy, ref obj, ref obj);
                    feat = featCur.NextFeature();
                }
                IGeometryCollection geomCollLine = new GeometryBagClass() as IGeometryCollection;
                featCur = featClsPolyline0.Search(null, false);
                feat = featCur.NextFeature();
                while (feat != null)
                {
                    geomCollLine.AddGeometry(feat.ShapeCopy, ref obj, ref obj);
                    feat = featCur.NextFeature();
                }
                IRelationalOperatorNxM relOpNxM = geomCollGon as IRelationalOperatorNxM;
                IRelationResult relRes = relOpNxM.Crosses(geomCollLine as IGeometryBag);

                int count = relRes.RelationElementCount;
                int left, right;

                for (int i = 0; i < count; i++)
                {
                    relRes.RelationElement(i, out left, out right);
                    IGeometry geomGon = geomCollGon.get_Geometry(left);
                    IGeometry geomLine = geomCollLine.get_Geometry(right);
                    //geomGon crosses geomLine
                }

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

[Visual Basic .NET]

    Sub Test(ByVal featClsPolygon0 As IFeatureClass, ByVal featClsPolyline0 As IFeatureClass)
        Dim geomCollGon As IGeometryCollection
        geomCollGon = New GeometryBagClass()
        Dim featCur As IFeatureCursor
        featCur = featClsPolygon0.Search(Nothing, False)
        Dim feat As IFeature
        feat = featCur.NextFeature()
        While (Not feat Is Nothing)
            geomCollGon.AddGeometry(feat.ShapeCopy)
            feat = featCur.NextFeature()
        End While

        Dim geomCollLine As IGeometryCollection
        geomCollLine = New GeometryBagClass()
        featCur = featClsPolyline0.Search(Nothing, False)
        feat = featCur.NextFeature()
        While (Not feat Is Nothing)
            geomCollLine.AddGeometry(feat.ShapeCopy)
            feat = featCur.NextFeature()
        End While

        Dim relOpNxM As IRelationalOperatorNxM
        relOpNxM = geomCollGon
        Dim relRes As IRelationResult
        relRes = relOpNxM.Crosses(geomCollLine)

        Dim count As Integer
        count = relRes.RelationElementCount
        Dim left As Integer, right As Integer, i As Integer
        Dim geomGon As IGeometry, geomLine As IGeometry

        For i = 0 To count - 1
            relRes.RelationElement(i, left, right)
            geomGon = geomCollGon.Geometry(left)
            geomLine = geomCollLine.Geometry(right)
            'geomGon crosses geomLine
        Next i
    End Sub