private List <CPoint> BezierDetectPoint(List <CPoint> cptlt, double dblSmallDis, double dblErrorDis) { List <CPoint> crtptlt = new List <CPoint>(); //crtptlt:characteristicptlt crtptlt.Add(cptlt[0]); //List<CPoint> beziercptlt = new List<CPoint>(); IPointCollection4 pOriginalCol = new PolylineClass(); object Missing = Type.Missing; bool blnNew = true; for (int i = 1; i < cptlt.Count - 1; i++) { if (blnNew == true) { pOriginalCol = new PolylineClass(); blnNew = false; pOriginalCol.AddPoint((IPoint)cptlt[i - 1], ref Missing, ref Missing); pOriginalCol.AddPoint((IPoint)cptlt[i], ref Missing, ref Missing); pOriginalCol.AddPoint((IPoint)cptlt[i + 1], ref Missing, ref Missing); //beziercptlt.Add(cptlt[i - 1]); //beziercptlt.Add(cptlt[i ]); //beziercptlt.Add(cptlt[i + 1]); i = i + 1; } else { pOriginalCol.AddPoint((IPoint)cptlt[i], ref Missing, ref Missing); //beziercptlt.Add(cptlt[i]); } IPolyline5 pOriginalpl = pOriginalCol as IPolyline5; double dblBuBeLength = pOriginalpl.Length / 3; //dblBuBeLength: dblBuildBezierLength int intPointCount = pOriginalCol.PointCount; //确定始端控制点2 IPointCollection4 pfrCol = new PolylineClass(); pfrCol.AddPoint(pOriginalCol.get_Point(0), ref Missing, ref Missing); pfrCol.AddPoint(pOriginalCol.get_Point(1), ref Missing, ref Missing); IPolyline5 pfrpl = pfrCol as IPolyline5; IPoint froutpt = new PointClass(); //始端控制点2 pfrpl.QueryPoint(esriSegmentExtension.esriExtendAtTo, dblBuBeLength, false, froutpt); //确定终端控制点2 IPointCollection4 ptoCol = new PolylineClass(); ptoCol.AddPoint(pOriginalCol.get_Point(intPointCount - 1), ref Missing, ref Missing); ptoCol.AddPoint(pOriginalCol.get_Point(intPointCount - 2), ref Missing, ref Missing); IPolyline5 ptopl = ptoCol as IPolyline5; IPoint tooutpt = new PointClass(); //终端控制点2 ptopl.QueryPoint(esriSegmentExtension.esriExtendAtTo, dblBuBeLength, false, tooutpt); //创建BezierCurve IBezierCurve pBezierCurve = new BezierCurveClass(); pBezierCurve.PutCoord(0, pOriginalCol.get_Point(0)); pBezierCurve.PutCoord(1, froutpt); pBezierCurve.PutCoord(2, tooutpt); pBezierCurve.PutCoord(3, pOriginalCol.get_Point(intPointCount - 1)); double dblMaxDis = 0; int intMaxIndex = 0; for (int j = 1; j < pOriginalCol.PointCount - 1; j++) { IPoint Originalpt = pOriginalCol.get_Point(j); IPoint outpt = new PointClass(); double dblAlongDis = new double(); double dblFromDis = new double(); bool blnRight = new bool(); IPoint bezierpt = new PointClass(); pBezierCurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, Originalpt, false, outpt, ref dblAlongDis, ref dblFromDis, ref blnRight); if (dblFromDis > dblMaxDis) { dblMaxDis = dblFromDis; intMaxIndex = i + j + 1 - pOriginalCol.PointCount; //i为原始线段上的点号,j为当前顾及线段的点号,pOriginalCol.PointCount为当前顾及线段的点数 } } if (dblMaxDis > dblErrorDis) { blnNew = true; crtptlt.Add(cptlt[intMaxIndex]); i = intMaxIndex + 1; } } crtptlt.Add(cptlt[cptlt.Count - 1]); return(crtptlt); }
private List <CPoint> SettleRailwayNetwork(List <CPoint> cptlt, double dblSmallDis, double dblErrorDis) { List <CPoint> crtptlt = new List <CPoint>(); //crtptlt:characteristicptlt crtptlt.Add(cptlt[0]); //List<CPoint> beziercptlt = new List<CPoint>(); IPointCollection4 pOriginalCol = new PolylineClass(); object Missing = Type.Missing; bool blnNew = true; for (int i = 1; i < cptlt.Count - 1; i++) { if (blnNew == true) { pOriginalCol = new PolylineClass(); blnNew = false; pOriginalCol.AddPoint((IPoint)cptlt[i - 1], ref Missing, ref Missing); pOriginalCol.AddPoint((IPoint)cptlt[i], ref Missing, ref Missing); pOriginalCol.AddPoint((IPoint)cptlt[i + 1], ref Missing, ref Missing); //beziercptlt.Add(cptlt[i - 1]); //beziercptlt.Add(cptlt[i ]); //beziercptlt.Add(cptlt[i + 1]); i = i + 1; } else { pOriginalCol.AddPoint((IPoint)cptlt[i], ref Missing, ref Missing); //beziercptlt.Add(cptlt[i]); } IPolyline5 pOriginalpl = pOriginalCol as IPolyline5; double dblBuBeLength = pOriginalpl.Length / 3; //dblBuBeLength: dblBuildBezierLength int intPointCount = pOriginalCol.PointCount; IPointCollection4 pfrCol = new PolylineClass(); pfrCol.AddPoint(pOriginalCol.get_Point(0), ref Missing, ref Missing); pfrCol.AddPoint(pOriginalCol.get_Point(1), ref Missing, ref Missing); IPolyline5 pfrpl = pfrCol as IPolyline5; IPoint froutpt = new PointClass(); pfrpl.QueryPoint(esriSegmentExtension.esriExtendAtTo, dblBuBeLength, false, froutpt); IPointCollection4 ptoCol = new PolylineClass(); ptoCol.AddPoint(pOriginalCol.get_Point(intPointCount - 1), ref Missing, ref Missing); ptoCol.AddPoint(pOriginalCol.get_Point(intPointCount - 2), ref Missing, ref Missing); IPolyline5 ptopl = ptoCol as IPolyline5; IPoint tooutpt = new PointClass(); ptopl.QueryPoint(esriSegmentExtension.esriExtendAtTo, dblBuBeLength, false, tooutpt); //创建BezierCurve IBezierCurve pBezierCurve = new BezierCurveClass(); pBezierCurve.PutCoord(0, pOriginalCol.get_Point(0)); pBezierCurve.PutCoord(1, froutpt); pBezierCurve.PutCoord(2, tooutpt); pBezierCurve.PutCoord(3, pOriginalCol.get_Point(intPointCount - 1)); double dblQueryNum = pOriginalpl.Length / dblSmallDis; double dblMaxDis = 0; for (int j = 0; j < dblQueryNum - 1; j++) { IPoint originalpt = new PointClass(); pOriginalpl.QueryPoint(esriSegmentExtension.esriNoExtension, j / dblQueryNum, true, originalpt); IPoint bezierpt = new PointClass(); pBezierCurve.QueryPoint(esriSegmentExtension.esriNoExtension, j / dblQueryNum, true, bezierpt); double dblDis = CGeoFunc.CalDis(originalpt, bezierpt); if (dblDis > dblMaxDis) { dblMaxDis = dblDis; } } if (dblMaxDis > dblErrorDis) { blnNew = true; crtptlt.Add(cptlt[i]); } } crtptlt.Add(cptlt[cptlt.Count - 1]); return(crtptlt); }