Пример #1
0
        //几何图形坐标转换
        private void GeometryCoordConvert(ref IGeometry pConvertGeometry, double A1, double B1, double C1, double A2, double B2, double C2, double A3, double C3)
        {
            object a      = System.Reflection.Missing.Value;
            object b      = System.Reflection.Missing.Value;
            bool   isRing = false;

            if (pConvertGeometry.GeometryType != esriGeometryType.esriGeometryPoint)//如果为线要素或面要素
            {
                IArray pArrayPoint    = new ArrayClass();
                IArray pGeometryArray = new ArrayClass();
                IGeometryCollection pGeometryCollection = pConvertGeometry as IGeometryCollection;
                for (int i = 0; i < pGeometryCollection.GeometryCount; i++)
                {
                    IGeometry pGeometry = pGeometryCollection.get_Geometry(i);
                    if (pGeometry.GeometryType != esriGeometryType.esriGeometryPoint)//
                    {
                        #region
                        if (pGeometry.GeometryType == esriGeometryType.esriGeometryRing)
                        {
                            isRing = true;
                        }

                        if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)
                        {
                            pGeometry = CommonFunction.GetPolygonBoundary((IPolygon)pGeometry);
                        }

                        ISegmentCollection pSegmentCol    = (ISegmentCollection)pGeometry;
                        ISegmentCollection pNewSegmentCol = new PolylineClass();
                        for (int k = 0; k < pSegmentCol.SegmentCount; k++)//遍历几何形体的每个节(片断)
                        {
                            //该节为直线段
                            if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryLine)
                            {
                                IPointCollection pPointCol1 = new MultipointClass();
                                ILine            pLine      = (ILine)pSegmentCol.get_Segment(k);

                                IPoint pFromPoint = pLine.FromPoint;
                                pPointCol1.AddPoint((IPoint)pFromPoint, ref a, ref b);
                                IPoint pToPoint = pLine.ToPoint;
                                pPointCol1.AddPoint((IPoint)pToPoint, ref a, ref b);

                                PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol1);//对点集做镜像

                                //修改线段的端点坐标
                                pLine.FromPoint = pPointCol1.get_Point(0);
                                pLine.ToPoint   = pPointCol1.get_Point(1);

                                pNewSegmentCol.AddSegment((ISegment)pLine, ref a, ref b);
                            }
                            //该节为圆弧
                            else if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryCircularArc)
                            {
                                IPointCollection pPointCol2 = new MultipointClass();

                                ICircularArc pCircularArc = (ICircularArc)pSegmentCol.get_Segment(k);

                                try
                                {
                                    IPoint pCenterPoint = pCircularArc.CenterPoint;
                                    pPointCol2.AddPoint((IPoint)pCenterPoint, ref a, ref b);
                                    IPoint pFromPoint = pCircularArc.FromPoint;
                                    pPointCol2.AddPoint((IPoint)pFromPoint, ref a, ref b);
                                    IPoint pToPoint = pCircularArc.ToPoint;
                                    pPointCol2.AddPoint((IPoint)pToPoint, ref a, ref b);

                                    PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol2);//对点集做镜像

                                    //构造新的圆弧
                                    ICircularArc pArc = new CircularArcClass();
                                    pArc.PutCoords(pPointCol2.get_Point(0), pPointCol2.get_Point(1), pPointCol2.get_Point(2),
                                                   (pCircularArc.IsCounterClockwise ? esriArcOrientation.esriArcCounterClockwise : esriArcOrientation.esriArcClockwise));

                                    pNewSegmentCol.AddSegment((ISegment)pArc, ref a, ref b);
                                }
                                catch { }
                            }
                            //该节为贝塞尔曲线
                            else if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryBezier3Curve)
                            {
                                IPointCollection pPointCol3   = new MultipointClass();
                                IBezierCurve     pBezierCurve = (IBezierCurve)pSegmentCol.get_Segment(k);

                                //记录该节贝塞尔曲线的4个控制点
                                IPoint pFromPoint = new PointClass();
                                pBezierCurve.QueryCoord(0, pFromPoint);
                                pPointCol3.AddPoint(pFromPoint, ref a, ref b);
                                IPoint pFromTangentPoint = new PointClass();
                                pBezierCurve.QueryCoord(1, pFromTangentPoint);
                                pPointCol3.AddPoint(pFromTangentPoint, ref a, ref b);
                                IPoint pToTangentPoint = new PointClass();
                                pBezierCurve.QueryCoord(2, pToTangentPoint);
                                pPointCol3.AddPoint(pToTangentPoint, ref a, ref b);
                                IPoint pToPoint = new PointClass();
                                pBezierCurve.QueryCoord(3, pToPoint);
                                pPointCol3.AddPoint(pToPoint, ref a, ref b);

                                PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol3);//对点集做镜像

                                //修改该节贝塞尔曲线的4个控制点
                                pBezierCurve.PutCoord(0, pPointCol3.get_Point(0));
                                pBezierCurve.PutCoord(1, pPointCol3.get_Point(1));
                                pBezierCurve.PutCoord(2, pPointCol3.get_Point(2));
                                pBezierCurve.PutCoord(3, pPointCol3.get_Point(3));

                                pNewSegmentCol.AddSegment((ISegment)pBezierCurve, ref a, ref b);
                            }
                        }//end for 遍历几何形体的每个节(片断)

                        CommonFunction.GeometryToArray(pNewSegmentCol as IGeometry, pArrayPoint);

                        IPolycurve2 pPolycurve2 = CommonFunction.BuildPolyLineFromSegmentCollection(pNewSegmentCol);

                        pGeometry = (IGeometry)pPolycurve2;

                        #endregion
                    }
                    if (pConvertGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//由线构成面
                    {
                        pGeometry = CommonFunction.PolylineToPolygon(pGeometry as IPolyline);
                    }
                    pGeometryArray.Add(pGeometry);
                }
                if (pGeometryArray.Count > 1)
                {
                    pConvertGeometry = pGeometryArray.get_Element(0) as IGeometry;
                    if (isRing == true)
                    {
                        for (int i = 1; i < pGeometryArray.Count; i++)
                        {
                            pConvertGeometry = CommonFunction.DiffenceGeometry(pConvertGeometry, pGeometryArray.get_Element(i) as IGeometry);
                        }
                    }
                    else
                    {
                        for (int i = 1; i < pGeometryArray.Count; i++)
                        {
                            pConvertGeometry = CommonFunction.UnionGeometry(pConvertGeometry, pGeometryArray.get_Element(i) as IGeometry);
                        }
                    }
                }
                else
                {
                    pConvertGeometry = pGeometryArray.get_Element(0) as IGeometry;
                }

                CommonFunction.AddZMValueForGeometry(ref pConvertGeometry, pArrayPoint);
            }
            else
            {
                PointCoordConvert(ref pConvertGeometry, A1, B1, C1, A2, B2, C2, A3, C3);
            }
        }