PolyLine 多次打断操作
代码来源: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;
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?