项目里用到的一些基本的AE开发功能:
//返回指定距离打断线之后的打断点
public static IPoint BreakPoint(IPolyline iPolyline, double interv)
{
if (iPolyline.Length <= interv)
{
return null;
}
IPoint p = new PointClass();
bool isSplit;
int splitIndex, segIndex;
object o = Type.Missing;
ESRI.ArcGIS.esriSystem.IClone pl = (iPolyline as ESRI.ArcGIS.esriSystem.IClone).Clone();
(pl as IPolyline).SplitAtDistance(interv, false, false, out isSplit, out splitIndex, out segIndex);
if (isSplit)
{
IPolyline frontLine = new PolylineClass();
ISegmentCollection lineSegCol = (ISegmentCollection)pl;
lineSegCol.RemoveSegments(segIndex, lineSegCol.SegmentCount - segIndex, true);
lineSegCol.SegmentsChanged();
frontLine = lineSegCol as IPolyline;
p = frontLine.ToPoint;
}
return p;
}
//将一条线以间隔距离interv分割为N等分
<span style="font-family: Arial, Helvetica, sans-serif;">public static List<IPolyline> DivideLine2NParts(IPolyline iPolyline, double interv)</span>
{
if (iPolyline.Length < interv)
{
return null;
}
ISegmentCollection tmpLineSegCol = (ISegmentCollection)iPolyline;
int num = (int)Math.Ceiling(iPolyline.Length / interv);
List<IPolyline> list = new List<IPolyline>();
for (int i = 0; i < num - 1; i++)
{
bool isSplit;
int splitIndex, segIndex;
object o = Type.Missing;
iPolyline.SplitAtDistance(interv, false, false, out isSplit, out splitIndex, out segIndex);
if (isSplit)
{
IPolyline frontLine = new PolylineClass();
IPolyline backLine = new PolylineClass();
ISegmentCollection lineSegCol = (ISegmentCollection)iPolyline;
ISegmentCollection backSegCol = (ISegmentCollection)backLine;
for (int j = segIndex; j < lineSegCol.SegmentCount; j++)
{
backSegCol.AddSegment(lineSegCol.get_Segment(j), ref o, ref o);
}
backSegCol.SegmentsChanged();
lineSegCol.RemoveSegments(segIndex, lineSegCol.SegmentCount - segIndex, true);
lineSegCol.SegmentsChanged();
frontLine = lineSegCol as IPolyline;
backLine = backSegCol as IPolyline;
list.Add(frontLine);
iPolyline = backLine;
}
}
list.Add(iPolyline);
iPolyline = tmpLineSegCol as IPolyline;
return list;
}
//计算指定点到线之间的最小距离
public static double MinDistance(IPolyline iPolyline, IPoint iPoint)
{
double minDist = 0;
if (iPoint!=null && !iPoint.IsEmpty)
{
IPoint outPoint = new PointClass();
double distAlongCurveFrom = 0;
double distFromCurve = 0;
bool isRightSide = false;
iPolyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, iPoint,
false, outPoint, ref distAlongCurveFrom, ref distFromCurve, ref isRightSide);
minDist = distFromCurve;
}
return minDist;
}
//获取两条线要素交点
public static IPointCollection GetIntersectPoint(IPolyline iPolyline1, IPolyline iPolyline2)
{
IPointCollection pPC = null;
ITopologicalOperator topoOperator = iPolyline1 as ITopologicalOperator;
IGeometry geo = topoOperator.Intersect(iPolyline2, esriGeometryDimension.esriGeometry0Dimension);
if (!geo.IsEmpty)
{
IPointCollection pc = geo as IPointCollection;
pPC = pc;
}
return pPC;
}