1

I'm having an issue with trying to complete the loop of adding the selected geometry to my geometry collection. The goal is finding streets that intersect the given street name (then locating the intersection, which is handled later in code).

Here is how I'm currently handling it and maybe someone can suggest an easier alternative or provide some help with the issues I'm having in my 'TODO:' statements.

// get the "Street" featureclass
IFeatureLayer pFeatureLayer = new ESRI.ArcGIS.Carto.FeatureLayer();
pFeatureLayer.FeatureClass = m_fcToQuery;

// query and get a feature cursor of selected streets
QueryFilter pQueryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilter();
pQueryFilter.WhereClause = "TownCode = " + townCodeVal + " AND StreetName = '" + streetNameVal + "'";

// merge selected street segs into geometry collection 1                       
IGeometryCollection pGeomColl1 = new PolylineClass();
IGeometry pGeometry1 = new ESRI.ArcGIS.Geometry.IGeometry();
pGeometry1 = pGeomColl1 as IGeometry;

IGeoDataset pGeodataset = new ESRI.ArcGIS.Geodatabase.IGeoDataset();
pGeodataset = pFeatureLayer.FeatureClass as IGeoDataset;
pGeometry1.SpatialReference = pGeodataset.SpatialReference;
IFeature pFeature = new ESRI.ArcGIS.Geodatabase.IFeature();
IFeatureCursor pFeatureCursor = new ESRI.ArcGIS.Geodatabase.IFeatureCursor();
pFeature = pFeatureCursor.NextFeature();
if (pFeature == null) {
    return null;
}
while (!(pFeature == null)) {
    // TODO: Fix this
    pGeomColl1.AddGeometryCollection(pFeature.ShapeCopy); <--error
    pFeature = pFeatureCursor.NextFeature();
}

// get a feature cursor of the int streets (3rd dropdownlist)
pQueryFilter.WhereClause = "TownCode = " + townCodeVal + " AND StreetName = '" + streetsInt + "'";
pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);

//Merge the selected streets into the Second Geometry Collection
IGeometryCollection pGeomColl2 = new ESRI.ArcGIS.Geometry.PolylineClass();
IGeometry pGeometry2 = pGeomColl2 as IGeometry;
pGeometry2.SpatialReference = pGeodataset.SpatialReference;
pFeature = pFeatureCursor.NextFeature();
if (pFeature == null) {
    return null;
}
while (!(pFeature == null)) {
    // TODO: fix this
    pGeomColl2.AddGeometryCollection(pFeature.ShapeCopy); <-- error
    pFeature = pFeatureCursor.NextFeature();
}

//Find the Intersection of the Two Streets
ITopologicalOperator2 pTopoOp = pGeometry1 as ITopologicalOperator2;
Polygon pBuffer1 = pTopoOp.Buffer(0.1) as Polygon;
pTopoOp = pGeometry2 as ITopologicalOperator2;
Polygon pBuffer2 = pTopoOp.Buffer(0.1) as Polygon;
pTopoOp = pBuffer2 as ITopologicalOperator2;

// TODO: fix this
IGeometry pintersection = pTopoOp.Intersect(pBuffer1, 4) as IGeometry; <-- error

if (pintersection.IsEmpty) {
    return null;
}
1
  • 2
    What kind of error do you get? Also it is more efficient to use IRelationalOperator.Disjoint than calculate the intersection. Also seems creation of feature layer is redundant here. – 0kcats Dec 10 '13 at 12:00
1

I figured out my issue. Neglected to use IArea...

//Find the Intersection of the Two Streets
        ITopologicalOperator  pTopoOp = pGeometry1 as ITopologicalOperator;
        IPolygon pBuffer1 = pTopoOp.Buffer(0.1) as IPolygon;
        pTopoOp = pGeometry2 as ITopologicalOperator;
        IPolygon pBuffer2 = pTopoOp.Buffer(0.1) as IPolygon;
        pTopoOp = pBuffer2 as ITopologicalOperator;
        IArea pIntersection = pTopoOp.Intersect(pBuffer1, esriGeometryDimension.esriGeometry2Dimension) as IArea;

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.