I solved this earlier today. Here is the code. A short pseudocode explanation follows.
ESRI.ArcGIS.Geometry.IGeometryBag pGeometryBag = new GeometryBagClass();
ESRI.ArcGIS.Geometry.IGeometryCollection pGeometryCollection = (IGeometryCollection)pGeometryBag;
ESRI.ArcGIS.Carto.IEnumLayer pEnumLayer; //get all layers in the map
pEnumLayer = pDoc.FocusMap.Layers;
ESRI.ArcGIS.Carto.ILayer pLayer; //create a layer to store looped values of point combobox layers
pLayer = pEnumLayer.Next();
while (pLayer != null)//Get all the features and stick them into the geometry collection
{
ESRI.ArcGIS.Carto.IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
if (pLayer == statusforselectedlayer)
{
ITable pTable = (ITable)pFeatureLayer.FeatureClass;
List<int> OIDList = new List<int>();
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.SubFields = pFeatureLayer.FeatureClass.OIDFieldName;
ICursor pCursor = pTable.Search(queryFilter, false);
IRow pRow = null;
while((pRow = pCursor.NextRow()) != null)
{
OIDList.Add(pRow.OID);
}
IFeatureCursor blocksCursor = pFeatureLayer.FeatureClass.GetFeatures(OIDList.ToArray(), false);
IFeature blockFeature = null;
while ((blockFeature = blocksCursor.NextFeature()) != null)
{
pGeometryCollection.AddGeometry(blockFeature.Shape);
}
}
ISpatialIndex spatialIndex = (ISpatialIndex)pGeometryBag;
spatialIndex.AllowIndexing = true;
spatialIndex.Invalidate();
ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.Geometry = pGeometryBag;
ESRI.ArcGIS.Geometry.IEnumGeometry pEnumGeometry = (IEnumGeometry)pGeometryBag;
pEnumGeometry.Reset();
ESRI.ArcGIS.Geometry.IGeometry pGeometry = pEnumGeometry.Next();
List<double> distances = new List<double>();
while (pGeometry != null)
{
IProximityOperator pProximity = (IProximityOperator)pGeometry;
ESRI.ArcGIS.Geometry.IEnumGeometry pEnumGeomBag = (IEnumGeometry)pGeometryBag;
ESRI.ArcGIS.Geometry.IGeometry pGeomBagIterable = pEnumGeomBag.Next();
while (pGeomBagIterable != null)
{
distances.Add(pProximity.ReturnDistance(pGeomBagIterable));
pGeomBagIterable = pEnumGeomBag.Next();
}
pGeometry = pEnumGeometry.Next();
}
The code loops through all layers in the map, takes all the features in a specified layer if it meets a certain criteria, and stores those features into an IGeometryBag. The code then loops through every IGeometry in the created IGeometryBag and compares each IGeometry to all other IGeometry in the IGeometryBag, getting the distance each time using IProximityOperator. These distances are stored in a list of type double named distances.