Exemplo n.º 1
0
        /// <summary>
        /// 重新填充缓冲区
        /// </summary>
        public bool ReFillCache()
        {
            if (SnapRefrencePoint == null)
            {
                return(false);
            }
            if (CacheMapRadius == 0)
            {
                return(false);
            }
            m_FeatureCache = new FeatureCacheClass();
            m_FeatureCache.Initialize(SnapRefrencePoint, CacheMapRadius);

            if (m_pNewMap == null)
            {
                return(false);
            }
            UID pUID = new UIDClass();

            pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
            if (m_pNewMap.LayerCount > 0)
            {
                IEnumLayer pEnumLayer = m_pNewMap.get_Layers(pUID, true);
                m_FeatureCache.AddLayers(pEnumLayer, GetPointBufferEnvelope(SnapRefrencePoint, CacheMapRadius));
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 对象初始化
        /// </summary>
        private void Init()
        {
            SnapRefrencePoint = null;
            m_SnapResultPoint = null;


            m_LastSnapPoint  = null;
            m_FeatureCache   = new FeatureCacheClass();
            m_LastSnapSymbol = null;
            m_PointType      = PointType.VertexPoint;
        }
Exemplo n.º 3
0
        public static IPoint GetSnapPoint(IPoint pPoint, IFeatureCache2 pFtCache, double Dist)
        {
            IHitTest pHitTest;
            IPoint   pHitPt;
            bool     bHit;
            double   dDist;
            esriGeometryHitPartType hitType;
            int       lPartIndex;
            int       lSegIndex;
            IGeometry pGeom;

            pHitPt = new PointClass();

            bool bRightSide = false;

            bHit = false;
            for (int i = 0; i < pFtCache.Count; i++)
            {
                lPartIndex = 0;
                lSegIndex  = 0;
                dDist      = 0;
                bHit       = false;

                pGeom    = pFtCache.get_Feature(i).ShapeCopy;
                pHitTest = (IHitTest)pGeom;

                if (pGeom.Dimension == esriGeometryDimension.esriGeometry0Dimension)
                {
                    hitType = esriGeometryHitPartType.esriGeometryPartVertex;
                }
                else
                {
                    hitType = esriGeometryHitPartType.esriGeometryPartBoundary;
                }
                bHit = pHitTest.HitTest(pPoint, Dist, hitType, pHitPt, ref dDist, ref lPartIndex, ref lSegIndex, ref bRightSide);
                if (bHit == true)
                {
                    break;
                }
            }
            if (bHit == true)
            {
                return(pHitPt);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        private IPoint SnapMiddlePoint(IPoint ipoint_0, IFeatureCache2 ifeatureCache2_0, double double_0)
        {
            IFeature feature = null;
            double   num     = 0;
            int      num1    = 0;
            int      num2    = 0;
            bool     flag    = true;
            double   num3    = -10;
            IPoint   x       = null;

            for (int i = 0; i < ifeatureCache2_0.Count; i++)
            {
                IFeature feature1 = ifeatureCache2_0.Feature[i];
                if ((feature1.Shape.GeometryType == esriGeometryType.esriGeometryPolyline
                    ? true
                    : feature1.Shape.GeometryType == esriGeometryType.esriGeometryPolygon))
                {
                    IPoint pointClass = new ESRI.ArcGIS.Geometry.Point();
                    if (
                        ((IHitTest)feature1.Shape).HitTest(ipoint_0, double_0,
                                                           esriGeometryHitPartType.esriGeometryPartMidpoint, pointClass, ref num, ref num1, ref num2,
                                                           ref flag) && num <= double_0)
                    {
                        if (num3 < 0)
                        {
                            num3    = num;
                            x       = pointClass;
                            feature = feature1;
                        }
                        else if (num3 > num)
                        {
                            num3    = num;
                            x.X     = pointClass.X;
                            x.Y     = pointClass.Y;
                            x.Z     = pointClass.Z;
                            feature = feature1;
                        }
                    }
                }
            }
            if (feature != null)
            {
                string str = string.Concat(this.method_1(feature), ":中点");
                ApplicationRef.AppContext.SetToolTip(str);
            }
            return(x);
        }
Exemplo n.º 5
0
        public static IPoint MeasureSnapPoint(ref IPoint pPoint)
        {
            IActiveView pActiveView;
            IEnvelope   pEnvlope;
            int         pixel;
            double      dCacheradius;
            double      dRangle;
            IPoint      pSnapPpt;

            pActiveView     = (IActiveView)ClsDeclare.g_pMap;
            pixel           = 5;
            dCacheradius    = ConvertPixelDistanceToMapDistance(pActiveView, pixel);
            pEnvlope        = GetCurrentEnvelope(pPoint, dCacheradius);
            m_pFeatureCache = new FeatureCache() as IFeatureCache2;
            dRangle         = pEnvlope.Width;
            m_pFeatureCache.Initialize(pPoint, dRangle);
            FillCache(pPoint, pEnvlope);
            if (m_pFeatureCache.Count == 0)
            {
                return(null);
            }

            pSnapPpt = GetSnapPoint(pPoint, m_pFeatureCache, dCacheradius);
            if (pSnapPpt != null)
            {
                g_pLastSnapPnt = g_pNowSnapPnt;
                g_pNowSnapPnt  = pSnapPpt;
                DrawRectangle(pActiveView, g_pLastSnapPnt);
                DrawRectangle(pActiveView, g_pNowSnapPnt);
                return(pSnapPpt);
            }
            else
            {
                g_pLastSnapPnt = g_pNowSnapPnt;
                g_pNowSnapPnt  = null;
                DrawRectangle(pActiveView, g_pLastSnapPnt);
                return(null);///可能存在错误!!!!!!!!!!!!
            }
        }
Exemplo n.º 6
0
        private IPoint method_8(IPoint ipoint_0, IFeatureCache2 ifeatureCache2_0, double double_0)
        {
            int              i;
            IGeometry        geometry;
            double           num        = 0;
            int              num1       = 0;
            int              num2       = 0;
            bool             flag       = true;
            IPoint           point      = null;
            List <IGeometry> geometries = new List <IGeometry>();

            for (i = 0; i < ifeatureCache2_0.Count; i++)
            {
                IFeature feature = ifeatureCache2_0.Feature[i];
                if ((feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline
                    ? true
                    : feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon))
                {
                    IPoint   pointClass = new ESRI.ArcGIS.Geometry.Point();
                    IHitTest shape      = (IHitTest)feature.Shape;
                    if (
                        shape.HitTest(ipoint_0, double_0, esriGeometryHitPartType.esriGeometryPartBoundary, pointClass,
                                      ref num, ref num1, ref num2, ref flag) && num <= double_0)
                    {
                        IGeometryCollection geometryCollection = shape as IGeometryCollection;
                        if (geometryCollection != null)
                        {
                            ISegmentCollection segmentCollection =
                                geometryCollection.Geometry[num1] as ISegmentCollection;
                            if (segmentCollection != null)
                            {
                                //segmentCollection.Segment[num2] is ICircularArc;
                            }
                        }
                    }
                }
            }
            IPointCollection multipointClass = new Multipoint();

            for (i = 0; i < geometries.Count; i++)
            {
                ITopologicalOperator2 item = (ITopologicalOperator2)geometries[i];
                for (int j = 0; j < geometries.Count; j++)
                {
                    if (i != j)
                    {
                        if (geometries[i].GeometryType != geometries[j].GeometryType)
                        {
                            geometry = item.IntersectMultidimension(geometries[j]);
                            if (geometry != null)
                            {
                                IGeometryCollection geometryCollection1 = geometry as IGeometryCollection;
                                if (geometryCollection1 != null)
                                {
                                    for (int k = 0; k < geometryCollection1.GeometryCount; k++)
                                    {
                                        geometry = geometryCollection1.Geometry[k];
                                        if (geometry is IPointCollection)
                                        {
                                            multipointClass.AddPointCollection((IPointCollection)geometry);
                                        }
                                        else if (geometry is IPoint)
                                        {
                                            object value = Missing.Value;
                                            object obj   = Missing.Value;
                                            multipointClass.AddPoint((IPoint)geometry, ref value, ref obj);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            geometry = item.Intersect(geometries[j], esriGeometryDimension.esriGeometry0Dimension);
                            if (geometry != null)
                            {
                                if (geometry is IPointCollection)
                                {
                                    multipointClass.AddPointCollection((IPointCollection)geometry);
                                }
                                else if (geometry is IPoint)
                                {
                                    object value1 = Missing.Value;
                                    object obj1   = Missing.Value;
                                    multipointClass.AddPoint((IPoint)geometry, ref value1, ref obj1);
                                }
                            }
                        }
                    }
                }
            }
            IHitTest hitTest     = (IHitTest)multipointClass;
            IPoint   pointClass1 = new ESRI.ArcGIS.Geometry.Point();

            if (
                hitTest.HitTest(ipoint_0, double_0, esriGeometryHitPartType.esriGeometryPartVertex, pointClass1, ref num,
                                ref num1, ref num2, ref flag) && num < double_0)
            {
                point = pointClass1;
            }
            return(point);
        }
Exemplo n.º 7
0
        private IPoint SnapPoint(IPoint ipoint_0, IFeatureCache2 ifeatureCache2_0, double double_0)
        {
            IPoint   shape;
            double   num;
            double   num1      = -10;
            IFeature feature   = null;
            IPoint   shapeCopy = null;

            for (int i = 0; i < ifeatureCache2_0.Count; i++)
            {
                IFeature feature1 = ifeatureCache2_0.Feature[i];
                if (feature1.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                {
                    shape = feature1.Shape as IPoint;
                    num   = CommonHelper.distance(ipoint_0, shape);
                    if (num <= double_0)
                    {
                        if (num1 < 0)
                        {
                            num1      = num;
                            shapeCopy = feature1.ShapeCopy as IPoint;
                            feature   = feature1;
                        }
                        else if (num1 > num)
                        {
                            num1        = num;
                            shapeCopy.X = shape.X;
                            shapeCopy.Y = shape.Y;
                            shapeCopy.Z = shape.Z;
                            feature     = feature1;
                        }
                    }
                }
                else if (feature1.Shape.GeometryType == esriGeometryType.esriGeometryMultipoint)
                {
                    shape = this.method_0(feature1.Shape as IPointCollection, ipoint_0, double_0);
                    num   = CommonHelper.distance(ipoint_0, shape);
                    if (num <= double_0)
                    {
                        if (num1 < 0)
                        {
                            num1      = num;
                            shapeCopy = shape;
                            feature   = feature1;
                        }
                        else if (num1 > num)
                        {
                            num1        = num;
                            shapeCopy.X = shape.X;
                            shapeCopy.Y = shape.Y;
                            shapeCopy.Z = shape.Z;
                            feature     = feature1;
                        }
                    }
                }
            }
            if (feature != null)
            {
                string str = string.Concat(this.method_1(feature), ":点");
                ApplicationRef.AppContext.SetToolTip(str);
            }
            return(shapeCopy);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 对外接口,执行捕捉点的操作
        /// 执行该操作之前,先要对CurrentMap变量赋值
        /// 并且CurrentMap中层的LayerDescription值必须为XML格式
        /// 程序将根据XML中的IsSnap属性确定是否对该层进行捕捉操作
        /// </summary>
        public bool SnapExcute(IPoint _SnapPoint)
        {
            //如果捕捉未开启,那么捕捉点即为参考点
            //b_IsHasSnaped = false;
            if (!IsOpenSnap)
            {
                m_SnapResultPoint = _SnapPoint;
                return(false);
            }

            m_PointType = PointType.VertexPoint;
            /*******临时捕捉设置***********/

            //设置比例尺
            if (m_pMapScale != m_CurrentMap.MapScale)
            {
                m_pMapScale      = m_CurrentMap.MapScale;
                d_SnapMapRadius  = ConvertPixelDistanceToMapDistance(this.d_SnapPixelRadius);
                d_CacheMapRadius = ConvertPixelDistanceToMapDistance(this.d_CachePixelRadius);
            }

            SnapRefrencePoint = _SnapPoint;//当前鼠标点,即参考点
            m_SnapResultPoint = null;
            if (!isCanExcute())
            {
                return(false);
            }


            //重新填充缓冲区
            if (m_FeatureCache == null)
            {
                m_FeatureCache = new FeatureCacheClass();
            }

            if (!m_FeatureCache.Contains(_SnapPoint))
            {
                if (!ReFillCache())
                {
                    return(false);
                }
            }


            HitFeature();

            /*********************画点算法**********************************/
            if (m_LastSnapPoint != null && m_LastSnapSymbol != null)
            {
                DrawPoint(m_LastSnapPoint, m_LastSnapSymbol as ISymbol);
            }
            if (SnapResultPoint != null && SnapResultPoint.IsEmpty == false)
            {
                DrawPoint(SnapResultPoint, SetSnapSymbol() as ISymbol);
            }
            m_LastSnapPoint  = SnapResultPoint;
            m_LastSnapSymbol = SetSnapSymbol() as ISymbol;

            //如果没有捕捉到点,那么把捕捉参考点返回
            if (SnapResultPoint == null || SnapResultPoint.IsEmpty)
            {
                m_SnapResultPoint = SnapRefrencePoint;
            }

            return(true);
        }