level 3
匮乏汤
楼主
啥话都不说了,直接上代码,就一个函数,挺简单的,
//剔除悬挂线的方法
private IGeometry RemomveHangeLine1(IGeometry baseGeometry)
{
try
{
ISegmentCollection segCollecion = baseGeometry as ISegmentCollection;
IEnumSegment segEnum = segCollecion.EnumSegments;
ISegment seg;
int partIndex = -1, segIndex = -1;
segEnum.Next(out seg, ref partIndex, ref segIndex);
List<IPoint> fromPoints = new List<IPoint>();
List<IPoint> toPoints = new List<IPoint>();
List<ISegment> segmentStore = new List<ISegment>();
while (seg != null)
{
IPolyline line = new PolylineClass();
ISegmentCollection tempSegCollecion = line as ISegmentCollection;
tempSegCollecion.AddSegment(seg);
IPoint fromPoint = line.FromPoint;
IPoint toPoint = line.ToPoint;
fromPoints.Add(fromPoint);
toPoints.Add(toPoint);
segmentStore.Add(seg);
segEnum.Next(out seg, ref partIndex, ref segIndex);
}
//处理起点
for (int i = 0; i < fromPoints.Count; i++)
{
bool fromSameTo = false;
IPoint from = fromPoints[i];
for (int j = 0; j < toPoints.Count; j++)
{
IPoint to = toPoints[j];
if (from.X == to.X && from.Y == to.Y)
{
fromSameTo = true;
}
}
//如果没有在to中找到值相等的,删除该线
if (!fromSameTo)
{
fromPoints.RemoveAt(i);
toPoints.RemoveAt(i);
segmentStore.RemoveAt(i);
i--;
}
}
//处理终点
for (int i = 0; i < toPoints.Count; i++)
{
bool toSameFrom = false;
IPoint to = toPoints[i];
for (int j = 0; j < fromPoints.Count; j++)
{
IPoint from = fromPoints[j];
if (from.X == to.X && from.Y == to.Y)
{
toSameFrom = true;
}
}
//如果没有在to中找到值相等的,删除该线
if (!toSameFrom)
{
fromPoints.RemoveAt(i);
toPoints.RemoveAt(i);
segmentStore.RemoveAt(i);
i--;
}
}
//重写生成图形
IPolyline newPolyline= new PolylineClass();
ISegmentCollection newSegCollection =newPolyline as ISegmentCollection;
for (int i = 0; i < segmentStore.Count; i++)
{
newSegCollection.AddSegment(segmentStore[i]);
}
IGeometry newGeometry = newPolyline as IGeometry;
return newGeometry;
}
catch (System.Exception ex)
{
throw ex;
}
}
2014年11月02日 10点11分
1
//剔除悬挂线的方法
private IGeometry RemomveHangeLine1(IGeometry baseGeometry)
{
try
{
ISegmentCollection segCollecion = baseGeometry as ISegmentCollection;
IEnumSegment segEnum = segCollecion.EnumSegments;
ISegment seg;
int partIndex = -1, segIndex = -1;
segEnum.Next(out seg, ref partIndex, ref segIndex);
List<IPoint> fromPoints = new List<IPoint>();
List<IPoint> toPoints = new List<IPoint>();
List<ISegment> segmentStore = new List<ISegment>();
while (seg != null)
{
IPolyline line = new PolylineClass();
ISegmentCollection tempSegCollecion = line as ISegmentCollection;
tempSegCollecion.AddSegment(seg);
IPoint fromPoint = line.FromPoint;
IPoint toPoint = line.ToPoint;
fromPoints.Add(fromPoint);
toPoints.Add(toPoint);
segmentStore.Add(seg);
segEnum.Next(out seg, ref partIndex, ref segIndex);
}
//处理起点
for (int i = 0; i < fromPoints.Count; i++)
{
bool fromSameTo = false;
IPoint from = fromPoints[i];
for (int j = 0; j < toPoints.Count; j++)
{
IPoint to = toPoints[j];
if (from.X == to.X && from.Y == to.Y)
{
fromSameTo = true;
}
}
//如果没有在to中找到值相等的,删除该线
if (!fromSameTo)
{
fromPoints.RemoveAt(i);
toPoints.RemoveAt(i);
segmentStore.RemoveAt(i);
i--;
}
}
//处理终点
for (int i = 0; i < toPoints.Count; i++)
{
bool toSameFrom = false;
IPoint to = toPoints[i];
for (int j = 0; j < fromPoints.Count; j++)
{
IPoint from = fromPoints[j];
if (from.X == to.X && from.Y == to.Y)
{
toSameFrom = true;
}
}
//如果没有在to中找到值相等的,删除该线
if (!toSameFrom)
{
fromPoints.RemoveAt(i);
toPoints.RemoveAt(i);
segmentStore.RemoveAt(i);
i--;
}
}
//重写生成图形
IPolyline newPolyline= new PolylineClass();
ISegmentCollection newSegCollection =newPolyline as ISegmentCollection;
for (int i = 0; i < segmentStore.Count; i++)
{
newSegCollection.AddSegment(segmentStore[i]);
}
IGeometry newGeometry = newPolyline as IGeometry;
return newGeometry;
}
catch (System.Exception ex)
{
throw ex;
}
}