代码来源:https://www.cnblogs.com/shizhenkun/p/5556478.html
一条线(Polyline)被另外一条线多次(Polyline)切割,也就是说打断的点有多个,而AE中的IFeatureEdit.Split()只能是一个点一个点的处理
public void LineSplit(IFeature feature, IGeometry other)
{
try
{
ITopologicalOperator shape = feature.Shape as ITopologicalOperator;
IPoint point = new PointClass();
IGeometry geometry2 = shape.Intersect(other, esriGeometryDimension.esriGeometry0Dimension);
if (!geometry2.IsEmpty)
{
IPointCollection points2 = geometry2 as IPointCollection;
for(int i = 0; i < points2.PointCount; i++)
{
point = points2.get_Point(i);
ISet set = (feature as IFeatureEdit).Split(point);
set.Reset();
for (IFeature feature2 = set.Next() as IFeature; feature2 != null; feature2 = set.Next() as IFeature)
{
if (!IsSplitOk(feature2,other))
{
feature = feature2;
}
else
{
ISimpleLineSymbol symbol = new SimpleLineSymbolClass();
IRgbColor color = new RgbColorClass
{
RGB = Color.FromArgb(0xff, 0, 0).ToArgb()
};
symbol.Color = color;
symbol.Width = 2.0;
this.pMapControl.FlashShape(feature2.Shape, 1, 450, symbol as ISymbol);
pMapControl.ActiveView.FocusMap.SelectFeature(pCurrentLayer, feature2);
}
}
}
}
}
catch (Exception)
{
return ;
}
}
public bool IsSplitOk(IFeature feature, IGeometry splitLine)
{
bool ok = false;
try
{
ITopologicalOperator shape = feature.Shape as ITopologicalOperator;
IGeometry geometry = shape.Intersect(splitLine, esriGeometryDimension.esriGeometry0Dimension);
if (!geometry.IsEmpty)
{
IPointCollection points = geometry as IPointCollection;
if(points.PointCount==1)
{
IPoint point = points.get_Point(0);
if (IsLineStartEndPoint(feature,point))
{
ok = true;
}
}
else if (points.PointCount == 2)
{
IPoint point1 = points.get_Point(0);
IPoint point2 = points.get_Point(1);
if (IsLineStartEndPoint(feature, point1) && IsLineStartEndPoint(feature, point2))
{
ok = true;
}
}
}
return ok;
}
catch (Exception)
{
return false;
}
}
public bool IsLineStartEndPoint(IFeature feature,IPoint point)
{
bool yes = false;
try
{
IPolyline line = feature.Shape as IPolyline;
double len = line.Length;
IPoint pStart = line.FromPoint;
if (Math.Abs(pStart.X - point.X) < 0.1 && Math.Abs(pStart.Y - point.Y) < 0.1)
{
yes = true;
}
else
{
IPoint pEnd = line.ToPoint;
if (Math.Abs(pEnd.X - point.X) < 0.1 && Math.Abs(pEnd.Y - point.Y) < 0.1)
{
yes = true;
}
}
return yes;
}
catch (Exception)
{
return false;
}
}