Пример #1
0
        public static IPolyline CreatePolyline(object[] paths)
        {
            IPolyline           result   = null;
            IGeometryCollection pGeomCol = new PolylineClass();
            object objMissing            = Type.Missing;

            foreach (object o in paths)//part
            {
                object[] ringpoints = o as object[];
                if (ringpoints != null)
                {
                    ISegmentCollection pSegCol = new PathClass();
                    ISegment           pSeg    = new LineClass();
                    IPoint             pFromPt = new PointClass();
                    IPoint             pToPt   = new PointClass();
                    IPoint             pEndPt  = new PointClass();

                    List <PointObject> poList = new List <PointObject>();
                    foreach (object po in ringpoints)
                    {
                        PointObject pObj  = new PointObject();
                        object[]    ptxya = po as object[];
                        if (ptxya != null)
                        {
                            if (ptxya.Length == 3)
                            {
                                pObj.X = double.Parse(ptxya[0].ToString());
                                pObj.Y = double.Parse(ptxya[1].ToString());
                                pObj.A = int.Parse(ptxya[2].ToString());
                            }
                            else if (ptxya.Length == 2)
                            {
                                pObj.X = double.Parse(ptxya[0].ToString());
                                pObj.Y = double.Parse(ptxya[1].ToString());
                                pObj.A = 0;
                            }
                            else
                            {
                                throw new Exception("坐标串输入错误!");
                            }
                            poList.Add(pObj);
                        }
                    }

                    if (poList.Count < 2)
                    {
                        throw new Exception("至少保证两个点来确定一条线!");
                    }

                    for (int i = 0; i < poList.Count - 1; i++)
                    {
                        if (poList[i].A.Equals(1))//处理狐段
                        {
                            PointObject poF = null;
                            PointObject poT = null;
                            PointObject poE = null;
                            if (i - 1 < 0)
                            {
                                poF = poList[poList.Count - 2];
                            }
                            else
                            {
                                poF = poList[i - 1];
                            }
                            poT = poList[i];
                            poE = poList[i + 1];

                            pFromPt.PutCoords(poF.X, poF.Y);
                            pToPt.PutCoords(poT.X, poT.Y);
                            pEndPt.PutCoords(poE.X, poE.Y);

                            //圆弧
                            ICircularArc          cirularArc           = new CircularArcClass();
                            IConstructCircularArc constructCircularArc = cirularArc as IConstructCircularArc;
                            constructCircularArc.ConstructThreePoints(pFromPt, pToPt, pEndPt, true);
                            pSeg = cirularArc as ISegment;
                            pSegCol.AddSegment(pSeg, ref objMissing, ref objMissing);
                        }
                        else
                        {
                            if (poList[i + 1].A.Equals(0))//处理直线,否则不处理
                            {
                                pFromPt.PutCoords(poList[i].X, poList[i].Y);
                                pToPt.PutCoords(poList[i + 1].X, poList[i + 1].Y);

                                pSeg           = new LineClass();
                                pSeg.FromPoint = pFromPt;
                                pSeg.ToPoint   = pToPt;
                                //一根线段
                                pSegCol.AddSegment(pSeg, ref objMissing, ref objMissing);
                            }
                        }
                    }

                    //一个part
                    pGeomCol.AddGeometry(pSegCol as IGeometry, ref objMissing, ref objMissing);
                }
            }

            result = pGeomCol as IPolyline;

            return(result);
        }