コード例 #1
0
        private IPolygon FlatBuffer(IPolyline pLline1, double pBufferDis)
        {
            object o = System.Type.Missing;
            //分别对输入的线平移两次(正方向和负方向)
            IConstructCurve pCurve1 = new PolylineClass();

            pCurve1.ConstructOffset(pLline1, pBufferDis, ref o, ref o);
            IPointCollection pCol    = pCurve1 as IPointCollection;
            IConstructCurve  pCurve2 = new PolylineClass();

            pCurve2.ConstructOffset(pLline1, -1 * pBufferDis, ref o, ref o);
            //把第二次平移的线的所有节点翻转
            IPolyline pline2 = pCurve2 as IPolyline;

            pline2.ReverseOrientation();
            //把第二条的所有节点放到第一条线的IPointCollection里面
            IPointCollection pCol2 = pline2 as IPointCollection;

            pCol.AddPointCollection(pCol2);
            //用面去初始化一个IPointCollection
            IPointCollection pPointCol = new PolygonClass();

            pPointCol.AddPointCollection(pCol);
            //把IPointCollection转换为面
            IPolygon pPolygon = pPointCol as IPolygon;

            //简化节点次序
            pPolygon.SimplifyPreserveFromTo();
            return(pPolygon);
        }
コード例 #2
0
        private static IGeometry GetErrorGeometry([NotNull] IGeometry part)
        {
            IPointCollection result = new PolygonClass();

            result.AddPointCollection((IPointCollection)part);
            ((IPolygon)result).Close();

            ((IPolygon)result).SpatialReference = part.SpatialReference;

            return((IGeometry)result);
        }
コード例 #3
0
        private void UpdateFeature(IFeature selectedFeature, IPointCollection4 polylinePoints)
        {
            IPointCollection4 geometry;
            esriGeometryType  geometryType = selectedFeature.Shape.GeometryType;

            switch (geometryType)
            {
            case esriGeometryType.esriGeometryMultipoint:
                geometry = new MultipointClass();
                break;

            case esriGeometryType.esriGeometryPolyline:
                geometry = new PolylineClass();
                break;

            case esriGeometryType.esriGeometryPolygon:
                geometry = new PolygonClass();
                break;

            default:
                geometry = null;
                break;
            }
            if (geometry == null)
            {
                return;
            }
            geometry.AddPointCollection(polylinePoints);
            IFeatureClass  featureClass  = selectedFeature.Class as IFeatureClass;
            IDataset       dataset       = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }

            try
            {
                workspaceEdit.StartEditOperation();
                selectedFeature.Shape = geometry as IGeometry;
                selectedFeature.Store();
                workspaceEdit.StopEditOperation();
            }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                MessageBox.Show("移动要素顶点失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #4
0
ファイル: MapCtrlMeasure.cs プロジェクト: zhongshuiyuan/WLib
        /// <summary>
        /// 计算多边形面积,结果存贮在Area中
        /// </summary>
        /// <param name="point">计算时的终点</param>
        private void CalculateArea(IPoint point)
        {
            IPointCollection pointCollection = new PolygonClass();

            pointCollection.AddPointCollection(_pointCollection);
            object ep = System.Reflection.Missing.Value;

            pointCollection.AddPoint(point, ref ep, ref ep);

            if (pointCollection.PointCount > 2)
            {
                IArea iArea = (IArea)(IPolygon)pointCollection;
                Area = Math.Abs(iArea.Area);
            }
        }
コード例 #5
0
        public static IPolygon GetPolygon([NotNull] IEnumerable <WKSPointVA> points)
        {
            Assert.ArgumentNotNull(points, nameof(points));

            IPointCollection5 mps = new MultipointClass();

            foreach (WKSPointVA point in points)
            {
                WKSPointVA p = point;
                mps.InsertWKSPointVA(0, 1, ref p);
            }

            IPointCollection poly = new PolygonClass();

            poly.AddPointCollection(mps);
            return((IPolygon)poly);
        }
コード例 #6
0
        public override void OnDblClick()
        {
            ITopologicalOperator pTopoOp;

            if (m_pPointColl != null)
            {
                switch (m_DrawType.ToString())
                {
                case "esriGeometryLine":
                    IPointCollection pPolyLine = new PolylineClass();
                    pPolyLine.AddPointCollection(m_pPointColl);
                    pTopoOp = pPolyLine as ITopologicalOperator;
                    pTopoOp.Simplify();
                    m_Geometry = pPolyLine as IGeometry;
                    //ZQ   20110809
                    m_Geometry.SpatialReference = m_psurface.Domain.SpatialReference;
                    //m_Geometry.SpatialReference = m_hookHelper.FocusMap.SpatialReference;
                    ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName);
                    EndDtrawd(true);    //触发结束事件
                    break;

                case "esriGeometryPolygon":
                    if (m_pPointColl.PointCount < 3)
                    {
                        return;
                    }
                    IPointCollection pPolygon = new PolygonClass();
                    pPolygon.AddPointCollection(m_pPointColl);
                    pTopoOp = pPolygon as ITopologicalOperator;
                    pTopoOp.Simplify();
                    m_Geometry = pPolygon as IGeometry;
                    //ZQ   20110809
                    m_Geometry.SpatialReference = m_psurface.Domain.SpatialReference;
                    //m_Geometry.SpatialReference = m_hookHelper.FocusMap.SpatialReference;
                    ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName);
                    EndDtrawd(true);    //触发结束事件
                    break;
                }
                m_pPointColl = null;
            }
            //Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);

            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
コード例 #7
0
        /// <summary>
        /// 双击表示绘制对象结束
        /// </summary>
        public override void OnDblClick()
        {
            ITopologicalOperator pTopoOp;

            if (m_pPointColl != null)
            {
                switch (m_DrawType.ToString())
                {
                case "esriGeometryLine":
                    IPointCollection pPolyLine = new PolylineClass();
                    pPolyLine.AddPointCollection(m_pPointColl);
                    pTopoOp = pPolyLine as ITopologicalOperator;
                    pTopoOp.Simplify();
                    m_Geometry = pPolyLine as IGeometry;
                    m_Geometry.SpatialReference = m_sceneHookHelper.Scene.SpatialReference;
                    Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);
                    EndDtrawd(true);    //触发结束事件
                    break;

                case "esriGeometryPolygon":
                    if (m_pPointColl.PointCount < 3)
                    {
                        return;
                    }
                    IPointCollection pPolygon = new PolygonClass();
                    pPolygon.AddPointCollection(m_pPointColl);
                    pTopoOp = pPolygon as ITopologicalOperator;
                    pTopoOp.Simplify();
                    m_Geometry = pPolygon as IGeometry;
                    m_Geometry.SpatialReference = m_sceneHookHelper.Scene.SpatialReference;
                    Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);
                    EndDtrawd(true);  //触发结束事件
                    break;
                }
                m_pPointColl = null;
            }
            //Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);
            m_sceneHookHelper.SceneGraph.RefreshViewers();
        }
コード例 #8
0
ファイル: MeasureTools.cs プロジェクト: zhongshuiyuan/WLib
        /// <summary>
        /// 计算多边形面积,结果存贮在Area中
        /// </summary>
        /// <param name="point">计算时的终点</param>
        private void CalculateArea(IPoint point)
        {
            try
            {
                IPointCollection pointCollection = new PolygonClass();
                pointCollection.AddPointCollection(_pointCollection);
                object ep = System.Reflection.Missing.Value;
                pointCollection.AddPoint(point, ref ep, ref ep);

                if (pointCollection.PointCount > 2)
                {
                    IPolygon pPolygon = (IPolygon)pointCollection;
                    IArea    pArea    = (IArea)pPolygon;
                    Area = pArea.Area;
                    Area = Math.Abs(Area);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #9
0
 private IPolygon FlatBuffer(IPolyline pLline1, double pBufferDis)
 {
     object o = System.Type.Missing;
      //分别对输入的线平移两次(正方向和负方向)
      IConstructCurve pCurve1 = new PolylineClass();
      pCurve1.ConstructOffset(pLline1, pBufferDis, ref o, ref o);
      IPointCollection pCol = pCurve1 as IPointCollection;
      IConstructCurve pCurve2 = new PolylineClass();
      pCurve2.ConstructOffset(pLline1, -1 * pBufferDis, ref o, ref o);
      //把第二次平移的线的所有节点翻转
      IPolyline pline2 = pCurve2 as IPolyline;
      pline2.ReverseOrientation();
      //把第二条的所有节点放到第一条线的IPointCollection里面
      IPointCollection pCol2 = pline2 as IPointCollection;
      pCol.AddPointCollection(pCol2);
      //用面去初始化一个IPointCollection
      IPointCollection pPointCol = new PolygonClass();
      pPointCol.AddPointCollection(pCol);
      //把IPointCollection转换为面
      IPolygon pPolygon = pPointCol as IPolygon;
      //简化节点次序
      pPolygon.SimplifyPreserveFromTo();
      return pPolygon;
 }
コード例 #10
0
        private IPolygon GetMGRSPolygon(IPoint point)
        {
            CoordinateMGRS mgrs;

            IPointCollection pc = new RingClass();

            // bottom left
            CoordinateMGRS.TryParse(InputCoordinate, out mgrs);

            // don't create a polygon for 1m resolution
            if (mgrs.Easting.ToString().Length > 4 && mgrs.Northing.ToString().Length > 4)
                return null;

            var tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            var anotherMGRSstring = mgrs.ToString("", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);
            
            // top left
            var tempMGRS = new CoordinateMGRS(mgrs.GZD, mgrs.GS, mgrs.Easting, mgrs.Northing);
            var tempEasting = mgrs.Easting.ToString().PadRight(5,'0');
            tempMGRS.Easting = Convert.ToInt32(tempEasting);
            var tempNorthing = mgrs.Northing.ToString().PadRight(5,'9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0','9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            anotherMGRSstring = tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top right
            tempEasting = mgrs.Easting.ToString().PadRight(5,'9');
            tempMGRS.Easting = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing = mgrs.Northing.ToString().PadRight(5,'9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // bottom right
            tempEasting = mgrs.Easting.ToString().PadRight(5,'9');
            tempMGRS.Easting = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing = mgrs.Northing.ToString().PadRight(5,'0');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing);

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // create polygon
            var poly = new PolygonClass();
            poly.SpatialReference = GetSR();
            poly.AddPointCollection(pc);
            poly.Close();

            return poly;
        }
コード例 #11
0
        private IPolygon GetMGRSPolygon(IPoint point)
        {
            CoordinateMGRS mgrs;

            IPointCollection pc = new RingClass();

            // bottom left
            CoordinateMGRS.TryParse(InputCoordinate, out mgrs);

            // don't create a polygon for 1m resolution
            if (mgrs.Easting.ToString().Length > 4 && mgrs.Northing.ToString().Length > 4)
            {
                return(null);
            }

            var tempPoint = new PointClass() as IConversionNotation;

            (tempPoint as IPoint).SpatialReference = GetSR();
            var anotherMGRSstring = mgrs.ToString("", new CoordinateMGRSFormatter());

            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top left
            var tempMGRS    = new CoordinateMGRS(mgrs.GZD, mgrs.GS, mgrs.Easting, mgrs.Northing);
            var tempEasting = mgrs.Easting.ToString().PadRight(5, '0');

            tempMGRS.Easting = Convert.ToInt32(tempEasting);
            var tempNorthing = mgrs.Northing.ToString().PadRight(5, '9');

            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            anotherMGRSstring = tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top right
            tempEasting       = mgrs.Easting.ToString().PadRight(5, '9');
            tempMGRS.Easting  = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing      = mgrs.Northing.ToString().PadRight(5, '9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // bottom right
            tempEasting       = mgrs.Easting.ToString().PadRight(5, '9');
            tempMGRS.Easting  = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing      = mgrs.Northing.ToString().PadRight(5, '0');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing);

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // create polygon
            var poly = new PolygonClass();

            poly.SpatialReference = GetSR();
            poly.AddPointCollection(pc);
            poly.Close();

            return(poly);
        }
コード例 #12
0
        private bool HitFeature()
        {
            int    segmentIndex = 0;
            double hitDist      = 0;
            int    part         = 0;
            bool   rightSide    = false;

            IPointCollection pPointColl_Intersect = new PolygonClass();

            IProximityOperator pProximityOp = SnapRefrencePoint as IProximityOperator;

            //距离捕捉参考点最近的点(除交点外)
            IPoint pClosedPoint = new PointClass();

            //获得捕捉参考点缓冲矩形
            IEnvelope pEnvelope = GetPointBufferEnvelope(SnapRefrencePoint, SnapMapRadius);

            //判断pClosedPoint是否已经被赋了值
            bool isSet = false;

            //用于计算交点的列表
            List <IFeature> list_AllFeatures = new List <IFeature> ();

            for (int i = 0; i < m_FeatureCache.Count; i++)
            {
                IFeature pFeature = m_FeatureCache.get_Feature(i);

                //判断IFeature的类型
                if (pFeature.Shape.GeometryType != esriGeometryType.esriGeometryPoint &&
                    pFeature.Shape.GeometryType != esriGeometryType.esriGeometryPolyline &&
                    pFeature.Shape.GeometryType != esriGeometryType.esriGeometryPolygon)
                {
                    continue;
                }

                //判断IFeature是否与捕捉点的缓冲区相交
                if (pFeature.Shape.Envelope.XMax < pEnvelope.XMin || pFeature.Shape.Envelope.XMin > pEnvelope.XMax ||
                    pFeature.Shape.Envelope.YMax < pEnvelope.YMin || pFeature.Shape.Envelope.YMin > pEnvelope.YMax)
                {
                    continue;
                }

                //判断IFeature和捕捉参考点的距离,此处是否应该大于捕捉半径,而不是捕捉半径的平方
                if (pProximityOp.ReturnDistance(pFeature.Shape) > SnapMapRadius /** SnapMapRadius */)
                {
                    continue;
                }

                IHitTest pHitTest = m_FeatureCache.get_Feature(i).Shape as IHitTest;

                IPoint[] pResPoint = new IPoint[5];
                for (int j = 0; j < 5; j++)
                {
                    pResPoint[j] = new PointClass();
                }

                #region HitTest捕捉

                //捕捉端点
                if (IsSnapPortPoint)
                {
                    pHitTest.HitTest(SnapRefrencePoint, SnapMapRadius, esriGeometryHitPartType.esriGeometryPartEndpoint, pResPoint[0], ref hitDist, ref part, ref segmentIndex, ref rightSide);
                }
                else
                {
                    pResPoint[0] = null;
                }

                //捕捉中点
                if (IsSnapMidPoint)
                {
                    pHitTest.HitTest(SnapRefrencePoint, SnapMapRadius, esriGeometryHitPartType.esriGeometryPartMidpoint, pResPoint[1], ref hitDist, ref part, ref segmentIndex, ref rightSide);
                }
                else
                {
                    pResPoint[1] = null;
                }

                //捕捉节点
                if (IsSnapNodePoint)
                {
                    pHitTest.HitTest(SnapRefrencePoint, SnapMapRadius, esriGeometryHitPartType.esriGeometryPartVertex, pResPoint[2], ref hitDist, ref part, ref segmentIndex, ref rightSide);
                }
                else
                {
                    pResPoint[2] = null;
                }

                //捕捉边上点
                if (IsSnapBoundryPoint)
                {
                    pHitTest.HitTest(SnapRefrencePoint, SnapMapRadius, esriGeometryHitPartType.esriGeometryPartBoundary, pResPoint[3], ref hitDist, ref part, ref segmentIndex, ref rightSide);
                }
                else
                {
                    pResPoint[3] = null;
                }

                //捕捉中心点
                if (IsSnapCenterPoint)
                {
                    pHitTest.HitTest(SnapRefrencePoint, SnapMapRadius, esriGeometryHitPartType.esriGeometryPartCentroid, pResPoint[4], ref hitDist, ref part, ref segmentIndex, ref rightSide);
                }
                else
                {
                    pResPoint[4] = null;
                }

                #endregion

                //捕捉交点
                if (IsSnapIntersectPoint)
                {
                    list_AllFeatures.Add(pFeature);
                }

                #region 捕捉端点
                if (pResPoint[0] != null && pResPoint[0].IsEmpty == false)
                {
                    if (isSet)
                    {
                        if (GetDistance(pClosedPoint, SnapRefrencePoint) > GetDistance(SnapRefrencePoint, pResPoint[0]))
                        {
                            pClosedPoint = pResPoint[0];

                            //在允许误差范围内
                            //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                            //{
                            //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                            //    {
                            //        m_SnapResultPoint = pClosedPoint;
                            //        m_PointType = PointType.PortPoint;
                            //        return true;
                            //    }
                            //}
                            m_PointType = PointType.PortPoint;
                        }
                    }
                    else
                    {
                        pClosedPoint = pResPoint[0];

                        //在允许误差范围内
                        //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                        //{
                        //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                        //    {
                        //        m_SnapResultPoint = pClosedPoint;
                        //        m_PointType = PointType.PortPoint;
                        //        return true;
                        //    }
                        //}
                        isSet       = true;
                        m_PointType = PointType.PortPoint;
                    }
                }
                #endregion

                #region 捕捉中点
                if (pResPoint[1] != null && pResPoint[1].IsEmpty == false)
                {
                    if (isSet)
                    {
                        if (GetDistance(pClosedPoint, SnapRefrencePoint) > GetDistance(SnapRefrencePoint, pResPoint[1]))
                        {
                            pClosedPoint = pResPoint[1];

                            //在允许误差范围内
                            //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                            //{
                            //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                            //    {
                            //        m_SnapResultPoint = pClosedPoint;
                            //        m_PointType = PointType.MidPoint;
                            //        return true;
                            //    }
                            //}
                            m_PointType = PointType.MidPoint;
                        }
                    }
                    else
                    {
                        pClosedPoint = pResPoint[1];

                        //在允许误差范围内
                        //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                        //{
                        //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                        //    {
                        //        m_SnapResultPoint = pClosedPoint;
                        //        m_PointType = PointType.MidPoint;
                        //        return true;
                        //    }
                        //}
                        isSet       = true;
                        m_PointType = PointType.MidPoint;
                    }
                }
                #endregion

                #region 捕捉节点
                if (pResPoint[2] != null && pResPoint[2].IsEmpty == false)
                {
                    if (isSet)
                    {
                        if (GetDistance(pClosedPoint, SnapRefrencePoint) > GetDistance(SnapRefrencePoint, pResPoint[2]))
                        {
                            pClosedPoint = pResPoint[2];
                            //在允许误差范围内
                            //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                            //{
                            //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                            //    {
                            //        m_SnapResultPoint = pClosedPoint;
                            //        m_PointType = PointType.VertexPoint;
                            //        return true;
                            //    }
                            //}
                            m_PointType = PointType.VertexPoint;
                        }
                    }
                    else
                    {
                        pClosedPoint = pResPoint[2];
                        //在允许误差范围内
                        //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                        //{
                        //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                        //    {
                        //        m_SnapResultPoint = pClosedPoint;
                        //        m_PointType = PointType.VertexPoint;
                        //        return true;
                        //    }
                        //}
                        isSet       = true;
                        m_PointType = PointType.VertexPoint;
                    }
                }
                #endregion

                #region 捕捉边上点
                if (pResPoint[3] != null && pResPoint[3].IsEmpty == false)
                {
                    if (isSet)
                    {
                        if (GetDistance(pClosedPoint, SnapRefrencePoint) > GetDistance(SnapRefrencePoint, pResPoint[3]))
                        {
                            pClosedPoint = pResPoint[3];
                            //在允许误差范围内
                            //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                            //{
                            //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                            //    {
                            //        m_SnapResultPoint = pClosedPoint;
                            //        m_PointType = PointType.BoundryPoint;
                            //        return true;
                            //    }
                            //}
                            m_PointType = PointType.BoundryPoint;
                        }
                    }
                    else
                    {
                        pClosedPoint = pResPoint[3];
                        //在允许误差范围内
                        //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                        //{
                        //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                        //    {
                        //        m_SnapResultPoint = pClosedPoint;
                        //        m_PointType = PointType.BoundryPoint;
                        //        return true;
                        //    }
                        //}
                        isSet       = true;
                        m_PointType = PointType.BoundryPoint;
                    }
                }
                #endregion

                #region 捕捉中心点
                if (pResPoint[4] != null && pResPoint[4].IsEmpty == false)
                {
                    if (isSet)
                    {
                        if (GetDistance(pClosedPoint, SnapRefrencePoint) > GetDistance(SnapRefrencePoint, pResPoint[4]))
                        {
                            pClosedPoint = pResPoint[4];
                            //在允许误差范围内
                            //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                            //{
                            //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                            //    {
                            //        m_SnapResultPoint = pClosedPoint;
                            //        m_PointType = PointType.CenterPoint;
                            //        return true;
                            //    }
                            //}
                            m_PointType = PointType.CenterPoint;
                        }
                    }
                    else
                    {
                        pClosedPoint = pResPoint[4];
                        //在允许误差范围内
                        //if ( pClosedPoint != null && pClosedPoint.IsEmpty == false )
                        //{
                        //    if ( GetDistance ( pClosedPoint , SnapRefrencePoint ) < m_IgnoreDistance )
                        //    {
                        //        m_SnapResultPoint = pClosedPoint;
                        //        m_PointType = PointType.CenterPoint;
                        //        return true;
                        //    }
                        //}
                        isSet       = true;
                        m_PointType = PointType.CenterPoint;
                    }
                }
                #endregion
            }

            //计算交点集合
            if (IsSnapIntersectPoint)
            {
                while (list_AllFeatures.Count > 0)
                {
                    pPointColl_Intersect.AddPointCollection(GetAllIntersect(list_AllFeatures[0], list_AllFeatures));
                    list_AllFeatures.RemoveAt(0);
                }
            }

            //得到最近的交点
            IPoint pIntersectPoint = GetClosedPoint(pPointColl_Intersect, SnapRefrencePoint);

            //比较最近的交点和其他类型点中最近点到参考点的距离
            if (pIntersectPoint != null && pIntersectPoint.IsEmpty == false)
            {
                if (pClosedPoint != null && pClosedPoint.IsEmpty == false)
                {
                    if (GetDistance(pIntersectPoint, SnapRefrencePoint) < GetDistance(pClosedPoint, SnapRefrencePoint))
                    {
                        m_SnapResultPoint = pIntersectPoint;
                        //b_IsHasSnaped = true;
                        m_PointType = PointType.IntersectPoint;
                    }
                    else
                    {
                        m_SnapResultPoint = pClosedPoint;
                        //b_IsHasSnaped = true;
                    }
                }
                else
                {
                    m_SnapResultPoint = null;
                    //b_IsHasSnaped = false;
                }
            }
            else if (pClosedPoint != null && pClosedPoint.IsEmpty == false)
            {
                m_SnapResultPoint = pClosedPoint;
                //b_IsHasSnaped = true;
            }
            else
            {
                m_SnapResultPoint = null;
                //b_IsHasSnaped = false;
            }

            return(true);
        }
コード例 #13
0
        private IPolygon FlatBuffer(IPolyline _pLine, double _pBufferDis)
        {
            object o = System.Type.Missing;

               //分别对输入的线平移两次(正方向和负方向)

               IConstructCurve pConCurve = new PolylineClass();

               pConCurve.ConstructOffset(_pLine, _pBufferDis, ref o, ref o);

               IPointCollection pCol = pConCurve as IPointCollection;

               IConstructCurve pCurve = new PolylineClass();

               pCurve.ConstructOffset(_pLine, -1 * _pBufferDis, ref o, ref o);
               //把第二次平移的线的所有节点翻转
               IPolyline addline = pCurve as IPolyline;

               addline.ReverseOrientation();
               //把第二条的所有节点放到第一条线的IPointCollection里面
               IPointCollection pCol2 = addline as IPointCollection;

               pCol.AddPointCollection(pCol2);
               //用面去初始化一个IPointCollection
               IPointCollection myPCol = new PolygonClass();

               myPCol.AddPointCollection(pCol);
               //把IPointCollection转换为面
               IPolygon pPolygon = myPCol as IPolygon;
               //简化节点次序
               pPolygon.SimplifyPreserveFromTo();

               return pPolygon;
        }