[GIS] Retrieve common paths of polylines ArcObjects

arcobjectsintersectionlinepolygon

I have a polygon featureClass and a polyline featureClass. I now want to handle all geometries within the latter that are contained in the boundaries of polygon features, that means they shell simply touch the polygons boundary. This accords to the simple "select features from that share a line segment from " -operator within the "select by location"-tool.
But how to achieve this with ArcObjects? I already tried the following:

IPolyline reshaper = ...;  
ITopologicalOperator topo = (ITopologicalOperator) singlePolygon;  
IGeometry boundary = topo.Boundary;  
IRelationalOperator relOp1 = (IRelationalOperator) boundary;  
if (relOp1.Contains(reshaper)) {...}

I also worked with the horrible Relation-Method which is intended to use on more complex queries. I tried it with relOp1.Relation(reshaper, "g1 contains g2") but simply received a meaningless HRESULT-Error of kind ARCWEB_E_INVALID_RING_CALCULATION_TYPE if I looked up the errorlist from ArcoBjects correctly (which I cannot ensure…).

So what now?

Best Answer

Welcome to the GIS stack exchange.

The topological operator is typically used to construct new geometries. It sounds to me like you just want to iterate through some features that share a boundary. In that case I would start a loop that iterates through each polygon feature. Within the polygon feature loop you can call a method something like this:

private IFeatureCursor ReturnSpatialQuery(IFeatureClass inFeatureClass, IGeometry searchGeometry, esriSpatialRelEnum enumSpatialRel, string sWhere)
    {
        //SET UP SPATIAL FILTER
        ISpatialFilter spatialFilter = new SpatialFilterClass();
        spatialFilter.Geometry = searchGeometry;
        spatialFilter.GeometryField = inFeatureClass.ShapeFieldName;
        spatialFilter.SpatialRel = enumSpatialRel;
        if (!string.IsNullOrEmpty(sWhere)) spatialFilter.WhereClause = sWhere;

        //PERFORM THE QUERY
        return inFeatureClass.Search(spatialFilter, false);
    }

The inFeatureClass would be your polyline class, the searchGeometry is the polygon shape, and you can also add a where clause for filtering attributes. Pass the type of spatial relationship you want from the esri constants. This method will return a feature cursor that you can then iterate through in your main loop and do something with each polyline.

Related Question