Polyline的封闭与打断

来源:互联网 发布:python matplotlib版本 编辑:程序博客网 时间:2024/04/30 09:23

/// <summary>
/// 利用面生成闭合的曲线
/// </summary>
/// <param name="pPolygon">传入的面图形</param>
/// <returns></returns>
private IPolyline PolygonToLine(IPolygon pPolygon)
{
IGeometryCollection pGeometryCollectionPolygon;
IClone pClone;
ISegmentCollection pSegmentCollectionPath;
object o = Type.Missing;
IGeometryCollection pGeoCol = new PolylineClass();
pClone = (IClone)pPolygon;
pGeometryCollectionPolygon = pClone.Clone() as IGeometryCollection;
for (int i = 0; i < pGeometryCollectionPolygon.GeometryCount; i++)
{
pSegmentCollectionPath = new PathClass();
pSegmentCollectionPath.AddSegmentCollection(pGeometryCollectionPolygon.get_Geometry(i) as ISegmentCollection);
pGeoCol.AddGeometry(pSegmentCollectionPath as IGeometry, ref o, ref o);
}
return pGeoCol as IPolyline;
}

/// <summary>
/// 线上距离FromPoint的DisOnLine距离上的一点,在这点处把线打断为两段
/// </summary>
  /// <param name="myPolyline">传入的线图形</param>
/// <param name="DisOnLine">离FromPoint的距离</param>
/// <returns></returns>
private IPolyline[] BreakLineToTwoPart(IPolyline myPolyline,double DisOnLine)
{
if (DisOnLine < myPolyline.Length) //如果传入的长度大于线的长度,不与操作
{
return null;
}
IPolyline[] Lines = new IPolyline[2];
bool isSplit;
int splitIndex, segIndex;
object o = Type.Missing;
myPolyline.SplitAtDistance(DisOnLine, false, false, out isSplit, out splitIndex, out segIndex);
IPolyline newLine = new PolylineClass();
ISegmentCollection lineSegCol = (ISegmentCollection)myPolyline;
ISegmentCollection newSegCol = (ISegmentCollection)newLine;
for (int j = segIndex; j < lineSegCol.SegmentCount; j++)
{
newSegCol.AddSegment(lineSegCol.get_Segment(j), ref o, ref o);
}
//重新构建两条线
lineSegCol.RemoveSegments(segIndex, lineSegCol.SegmentCount - segIndex, true);
lineSegCol.SegmentsChanged();
newSegCol.SegmentsChanged();
IPolyline oldLine = lineSegCol as IPolyline;
newLine = newSegCol as IPolyline;
Lines[0] = oldLine;
Lines[1] = newLine;
return Lines;
}

/// <summary>
/// 在SplitePoint处打断线要素的图形,并去除新的线
/// </summary>
/// <param name="LineCurve">传入的线</param>
/// <param name="SplitePoint">线上的一点</param>
/// <returns></returns>
   
private IPolyline[] SpliteLineAtPoint(IPolyline LineCurve, IPoint SplitePoint)
{
IPolyline[] Lines = new IPolyline[2];
bool isSplit;
int splitIndex, segIndex;
LineCurve.SplitAtPoint(SplitePoint, true, false, out isSplit, out splitIndex, out segIndex);
if (isSplit)
{
IPolyline newLine = new PolylineClass();
ISegmentCollection lineSegCol = (ISegmentCollection)LineCurve;
ISegmentCollection newSegCol = (ISegmentCollection)newLine;
object o = Type.Missing;
for (int j = segIndex; j < lineSegCol.SegmentCount; j++)
{
newSegCol.AddSegment(lineSegCol.get_Segment(j), ref o, ref o);
}
lineSegCol.RemoveSegments(segIndex, lineSegCol.SegmentCount - segIndex, true);
lineSegCol.SegmentsChanged();
newSegCol.SegmentsChanged();
IPolyline oldLine = lineSegCol as IPolyline;
newLine = newSegCol as IPolyline;
Lines[0] = newLine;
Lines[1] = oldLine;
}
return Lines;
}

/// <summary>
/// 用一个面图形把一个面要素切割为两部分
/// </summary>
/// <param name="polyClass">面要素集</param>
/// <param name="polyFeat">面要素</param>
/// <param name="CutPolygon">用于切割的图形</param>
   
private void BreakPolygonToTwoPart(IFeatureClass polyClass, IFeature polyFeat, IPolygon CutPolygon)
{
IGeometry featGeo = polyFeat.Shape;
ITopologicalOperator topo = featGeo as ITopologicalOperator;
IGeometry pOutGeometry = topo.Difference(CutPolygon); //去除相交的部分
if (pOutGeometry is IGeometryCollection)
{
IGeometryCollection pGeometryCollection = pOutGeometry as IGeometryCollection;
for (int i = 0; i < pGeometryCollection.GeometryCount; i++)
{
IGeometry pGeometry = pGeometryCollection.get_Geometry(i);
if (pGeometry != null && !pGeometry.IsEmpty && pGeometry.GeometryType == esriGeometryType.esriGeometryRing)
{
IClone pClone = pGeometry as IClone;
IPolygon pPolygon = ConvertGeometryToPolygon(pClone.Clone() as IGeometry);
if (pPolygon != null && !pPolygon.IsEmpty)
{
IFeature pNewFeature = polyClass.CreateFeature();
pNewFeature.Shape = pPolygon;
pNewFeature.Store();
}
}
}
polyFeat.Delete();
}
}

private IPolygon ConvertGeometryToPolygon(IGeometry pGeometry)
{
IPointCollection pPointCollection = pGeometry as IPointCollection;
IPointCollection pNewPointCollection = new PolygonClass();
pNewPointCollection.AddPointCollection(pPointCollection);
IPolygon pPolygon = pNewPointCollection as IPolygon;
return pPolygon;
}

原创粉丝点击