Ejemplo n.º 1
0
        /// <summary>
        /// 计算点C关于AB连线的中垂线的对称点D
        /// </summary>
        /// <param name="pointA"></param>
        /// <param name="pointB"></param>
        /// <param name="pointC"></param>
        /// <returns></returns>
        public static IPoint GetSymmetryPoint(IPoint pointA, IPoint pointB, IPoint pointC)
        {
            string value  = CalculateAzimuth(pointA, pointB, pointC);
            IPoint pointD = new PointClass();
            ILine  AB     = new LineClass {
                FromPoint = pointB, ToPoint = pointA
            };

            if (value == "LEFT")
            {
                AB = new LineClass {
                    FromPoint = pointB, ToPoint = pointA
                };
            }
            else
            {
                AB = new LineClass {
                    FromPoint = pointA, ToPoint = pointB
                };
            }
            IPoint pointS = new PointClass();

            pointS.PutCoords((pointA.X + pointB.X) / 2, (pointA.Y + pointB.Y) / 2);
            ILine normalS = new LineClass();

            AB.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, 100 * AB.Length, normalS);
            IPoint pointZ = new PointClass();

            if (normalS.Angle.Equals(0))//平行x轴
            {
                pointZ.PutCoords(pointC.X, pointS.Y);
            }
            else if (normalS.Angle.Equals(1.0 / 4.0 * Math.PI))//垂直x轴
            {
                pointZ.PutCoords(pointS.X, pointC.Y);
            }
            else
            {
                double d = GetMinDistance(pointA, pointB, pointC);
                normalS.QueryPoint(esriSegmentExtension.esriNoExtension, d, false, pointZ);
            }
            pointD.PutCoords((2.0 * pointZ.X - pointC.X), (2.0 * pointZ.Y - pointC.Y));
            return(pointD);
        }
        private static void CreateToAndTurnPointsDual(ICurve mainCurve, IPoint midPoint, ILine distanceLine, out IPoint toPoint, out IPoint turnPoint, out IPoint joinPoint, out IPoint sqPoint1, out IPoint sqPoint2, double doglegDistance, bool distAsPercent, bool squareDualLines, double tolerenceForDelete)
        {
            sqPoint1 = new PointClass();
            sqPoint2 = new PointClass();
            toPoint = null;
            turnPoint = null;
            joinPoint = null;

            IPoint closestPointOnMain = null;
            IProximityOperator lineProxOp = null;
            ILine tempLine = null;
            ICurve pCur = null;
            IPoint tempPt2 = null;
            IConstructPoint constTempPt2 = null;
            ILine verticalLine = null;
            IConstructPoint conSqPoint1 = null;
            IConstructPoint conSqPoint2 = null;

            try
            {
                closestPointOnMain = new PointClass();
                lineProxOp = mainCurve as IProximityOperator;
                closestPointOnMain = lineProxOp.ReturnNearestPoint(midPoint, esriSegmentExtension.esriNoExtension);

                //Create temp line to main
                tempLine = new LineClass();
                tempLine.FromPoint = closestPointOnMain;
                tempLine.ToPoint = midPoint;
                toPoint = closestPointOnMain;

                double dist;
                if (distAsPercent)
                {
                    pCur = (ICurve)tempLine;

                    dist = pCur.Length * (doglegDistance / 100);
                }
                else
                {
                    if (tempLine.Length < doglegDistance)
                    {
                        dist = 0;
                    }
                    else
                    {//Adjust distance if needed
                        dist = doglegDistance;
                    }

                }

                //Create the "to" point for new line - tap location on main
                //IPoint tempPt1 = new PointClass();
                //IConstructPoint constTempPt1 = (IConstructPoint)tempPt1;
                //constTempPt1.ConstructAlong(tempLine, esriSegmentExtension.esriNoExtension, dist, false);
                //  toPoint = (IPoint)constTempPt1;

                //Create dogleg (turn) point for new line if needed
                if (dist > 0)
                {
                    tempPt2 = new PointClass();
                    constTempPt2 = (IConstructPoint)tempPt2;
                    constTempPt2.ConstructAlong(tempLine, esriSegmentExtension.esriNoExtension, dist, false);
                    turnPoint = (IPoint)constTempPt2;
                }
                else
                    turnPoint = null;

                //Determine Join Point
                joinPoint = new PointClass();
                verticalLine = new LineClass() as ILine;
                verticalLine.FromPoint = midPoint;
                if (turnPoint != null)
                    verticalLine.ToPoint = turnPoint;
                else
                    verticalLine.ToPoint = closestPointOnMain;
                if (verticalLine.Length > distanceLine.Length)
                    dist = distanceLine.Length / 2;
                else if (verticalLine.Length > 10)
                    dist = verticalLine.Length / 2;
                else
                    dist = verticalLine.Length / 2;
                //return;
                verticalLine.QueryPoint(esriSegmentExtension.esriNoExtension, dist, false, joinPoint);

                if (squareDualLines)
                {
                    //Create squared turn points
                    conSqPoint1 = sqPoint1 as IConstructPoint;
                    conSqPoint2 = sqPoint2 as IConstructPoint;

                    conSqPoint1.ConstructAngleIntersection(distanceLine.FromPoint, verticalLine.Angle, joinPoint, verticalLine.Angle + (Math.PI / 2));
                    conSqPoint2.ConstructAngleIntersection(distanceLine.ToPoint, verticalLine.Angle, joinPoint, verticalLine.Angle + (Math.PI / 2));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CreateToAndTurnPointsDual\r\n" + ex.Message);

            }
            finally
            {
                closestPointOnMain = null;
                lineProxOp = null;
                tempLine = null;
                pCur = null;
                tempPt2 = null;
                constTempPt2 = null;
                verticalLine = null;
                conSqPoint1 = null;
                conSqPoint2 = null;

            }
        }
        //to be improved, a vertical cutter may cause unexpected problems
        //
        public void CreateBufferWithoutEnds(IGeometry fBufferGeo, double dblBuffer)
        {
            //StartCutPolyline
            ILine pStartNormal = new LineClass();

            this.pPolyline.QueryNormal(esriSegmentExtension.esriNoExtension, 0, true, dblBuffer, pStartNormal);
            IPoint StartFrPt = new PointClass();

            pStartNormal.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1.5, true, StartFrPt);
            IPoint StartToPt = new PointClass();

            pStartNormal.QueryPoint(esriSegmentExtension.esriExtendAtTo, 1.5, true, StartToPt);

            IPointCollection4 pStartCutterCol = new PolylineClass();

            pStartCutterCol.AddPoint(StartFrPt);
            pStartCutterCol.AddPoint(StartToPt);
            IPolyline5 pStartCutter = pStartCutterCol as IPolyline5;

            //EndCutPolyline
            ILine pEndNormal = new LineClass();

            this.pPolyline.QueryNormal(esriSegmentExtension.esriNoExtension, 1, true, dblBuffer, pEndNormal);
            IPoint EndFrPt = new PointClass();

            pEndNormal.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1.5, true, EndFrPt);
            IPoint EndToPt = new PointClass();

            pEndNormal.QueryPoint(esriSegmentExtension.esriExtendAtTo, 1.5, true, EndToPt);

            IPointCollection4 pEndCutterCol = new PolylineClass();

            pEndCutterCol.AddPoint(EndFrPt);
            pEndCutterCol.AddPoint(EndToPt);
            IPolyline5 pEndCutter = pEndCutterCol as IPolyline5;

            //TopologicalOperators
            ITopologicalOperator pStartPtTop    = this.pPolyline.FromPoint as ITopologicalOperator;
            IGeometry            pStartPtBuffer = pStartPtTop.Buffer(dblBuffer);

            ITopologicalOperator pEndPtTop    = this.pPolyline.ToPoint as ITopologicalOperator;
            IGeometry            pEndPtBuffer = pEndPtTop.Buffer(dblBuffer);

            //Cut
            ITopologicalOperator pStartPtBufferTop = pStartPtBuffer as ITopologicalOperator;
            IGeometry            StartLeftOutGeometry;
            IGeometry            StartRightOutGeometry;

            pStartPtBufferTop.Cut(pStartCutter, out StartLeftOutGeometry, out StartRightOutGeometry);

            ITopologicalOperator pEndPtBufferTop = pEndPtBuffer as ITopologicalOperator;
            IGeometry            EndLeftOutGeometry;
            IGeometry            EndRightOutGeometry;

            pEndPtBufferTop.Cut(pEndCutter, out EndLeftOutGeometry, out EndRightOutGeometry);

            //Difference
            ITopologicalOperator pBufferTop    = fBufferGeo as ITopologicalOperator;
            IGeometry            pDiffStart    = pBufferTop.Difference(StartRightOutGeometry);
            ITopologicalOperator pDiffStartTop = pDiffStart as ITopologicalOperator;
            IGeometry            pDiffEnd      = pDiffStartTop.Difference(EndLeftOutGeometry);

            _pBufferGeoWithoutEnds = pDiffEnd;
        }