Hope This Helps
In This example onle road layer and 2 polygon layers are on map.
user selecting road on map.
loop through selected roads.
using spatial filter find intersected polygons with road
loop through all intersected polygon.
using topological operator to get intersected road in each polygon and its lenght
display result
{
IEnumFeature penum;
IFeature Polyfeat;
IPolyline ppoly;
ISpatialFilter psp;
int linelen;
int polygon1len;
int polygon2len;
penum = mxd.FocusMap.FeatureSelection as IEnumFeature;
Polyfeat = penum.Next();
while (Polyfeat != null)
{
if (Polyfeat.Class.AliasName == "ROAD")
{
ppoly = Polyfeat.Shape as IPolyline;
MessageBox.Show("Road = " + ppoly.Length);
psp = new SpatialFilter();
psp.Geometry = ppoly;
psp.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
for (int i = 0; i <= mxd.FocusMap.LayerCount - 1; i++)
{
IFeatureLayer polylayer = mxd.FocusMap.get_Layer(i) as
ESRI.ArcGIS.Carto.FeatureLayer;
IFeatureClass polyclass = polylayer.FeatureClass;
if (polyclass.ShapeType == esriGeometryType.esriGeometryPolygon)
{
IFeatureCursor polycur = polyclass.Search(psp, false);
IFeature polyfeat = polycur.NextFeature();
while (polyfeat != null)
{
//ITopologicalOperator polytopoop = polyfeat.Shape;
ITopologicalOperator lineoperat = ppoly as ITopologicalOperator;
IGeometry linegeom = lineoperat.Intersect(polyfeat.Shape, esriGeometryDimension.esriGeometry1Dimension);
IPolyline newpoly = linegeom as IPolyline;
if (polyfeat.Class.AliasName == "Polygon1")
{
polygon1len += newpoly.Length;
}
else
{
polygon2len += newpoly.Length;
}
linelen += newpoly.Length;
//MessageBox.Show("" + newpoly.Length);
polyfeat = polycur.NextFeature();
}
}
}
MessageBox.Show("Road name = " + ppoly.Length + ", INTERSECTION LEN = " + linelen + ", Polygon1 " + polygon1len + "(" + (polygon1len * 100) / linelen + "%) , Polygon2 len " + polygon2len + "(" + (polygon2len * 100) / linelen + "%)");
}
Polyfeat = penum.Next();
linelen = 0;
polygon1len = 0;
polygon2len = 0;
}
}
Thanks & Regards
Jassi...