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;
}