public static void ShowAllVertex(IFeatureLayer pFeatLyr)
        {
            m_vertexGeoBag = null;
            if (pFeatLyr == null)
            {
                return;
            }
            IFeatureCursor pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);

            if (pFeatureCursor == null)
            {
                return;
            }
            IFeature pTFeature = null;

            //得到要显示节点的地物
            pTFeature = pFeatureCursor.NextFeature();
            if (pTFeature == null)
            {
                return;
            }
            //只选中一个地物进行节点移动
            m_Map.ClearSelection();
            m_Map.SelectFeature(pFeatLyr as ILayer, pTFeature);
            m_activeView.Refresh();
            //如果为点状地物,不显示节点
            if (pTFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                return;
            }
            IArray pFeatureArray = null;

            pFeatureArray = new ESRI.ArcGIS.esriSystem.Array();
            pFeatureArray.Add(pTFeature);
            //绘图符号初始化
            SymbolInit();
            IFeature         pFeature = default(IFeature);
            IPointCollection pPointCol = default(IPointCollection);
            IPoint           pPoint = default(IPoint);
            int i = 0; int j = 0;

            m_vertexGeoBag = new GeometryBagClass();
            for (i = 0; i <= pFeatureArray.Count - 1; i++)
            {
                pFeature = pFeatureArray.get_Element(i) as IFeature;
                //获取图形边界的点集
                pPointCol = pFeature.ShapeCopy as IPointCollection;
                for (j = 0; j <= pPointCol.PointCount - 1; j++)
                {
                    pPoint = pPointCol.get_Point(j);
                    if (j == 0 | j == pPointCol.PointCount - 1)
                    {
                        //两个端点的ID设为10
                        pPoint.ID = 10;
                    }
                    else
                    {
                        //中间点的ID设为100
                        pPoint.ID = 100;
                    }
                    IColor pColor = null;
                    object obj    = Type.Missing;
                    //显示节点
                    if (pPoint == pHitPnt)
                    {
                        DisplayGraphic(pPoint, pColor, m_selPointSym as ISymbol);
                    }
                    if (j == 0 || j == pPointCol.PointCount - 1)
                    {
                        DisplayGraphic(pPoint, pColor, m_endPointSym as ISymbol);
                    }
                    else
                    {
                        DisplayGraphic(pPoint, pColor, m_vertexSym as ISymbol);
                    }

                    m_vertexGeoBag.AddGeometry(pPoint, ref obj, ref obj);
                }
            }
            Marshal.ReleaseComObject(pFeatureCursor);
        }
Exemplo n.º 2
0
        public void OnMouseUp(int button, int shift, int x, int y)
        {
            if (shift == 0)
            {
                //清除所有选择的内容
                m_Map.ClearSelection();
                m_activeView.Refresh();
            }
            if (button != 1)
            {
                return;
            }
            try
            {
                if (m_EngineEditor == null)
                {
                    return;
                }
                if (m_EngineEditor.EditState != esriEngineEditState.esriEngineStateEditing)
                {
                    return;
                }
                if (m_EngineEditLayers == null)
                {
                    return;
                }
                //获取目标图层
                IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer;
                IFeatureClass pFeatCls = pFeatLyr.FeatureClass;

                //MapControl axMapControl1 = Control.FromHandle(new IntPtr(this.m_hookHelper.ActiveView.ScreenDisplay.hWnd)) as MapControl;
                IMapControl4 axMapControl1 = GlobalVars.instance.MapControl;
                IEnvelope    pEnvelope     = axMapControl1.TrackRectangle();
                IGeometry    pGeometry     = null;
                //当点选的情况时,Envelope为空,此时建立缓冲区
                if (pEnvelope.IsEmpty == true)
                {
                    IPoint point = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
                    //定义缓冲区
                    double db = MapManager.ConvertPixelsToMapUnits(m_activeView, 4);
                    ITopologicalOperator pTop;
                    pTop      = point as ITopologicalOperator;
                    pGeometry = pTop.Buffer(db);
                }
                else
                {
                    pGeometry = pEnvelope as IGeometry;
                }
                //设置选择过滤条件
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                //不同的图层类型设置不同的过滤条件
                switch (pFeatCls.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    //将像素距离转换为地图单位距离
                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    break;
                }
                pSpatialFilter.Geometry      = pGeometry;
                pSpatialFilter.GeometryField = pFeatCls.ShapeFieldName;
                IQueryFilter pQueryFilter = pSpatialFilter as IQueryFilter;
                //根据过滤条件进行查询
                IFeatureCursor    pFeatCursor = pFeatCls.Search(pQueryFilter, false);
                IFeature          pFeature    = pFeatCursor.NextFeature();
                IFeatureSelection pFeatureSelection;
                pFeatureSelection = pFeatLyr as IFeatureSelection;

                IEnumFeature pEnumFeature2 = m_Map.FeatureSelection as IEnumFeature;//已经选择的选择集
                int          a             = pFeatureSelection.SelectionSet.Count;
                pEnumFeature2.Reset();
                IFeature pFeature2 = pEnumFeature2.Next();

                //遍历整个要素类中符合条件的要素
                while (pFeature != null)
                {
                    if (pFeature2 == null)
                    {
                        pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);
                        break;
                    }
                    //遍历当前选择的要素
                    while (pFeature2 != null)
                    {
                        IRelationalOperator re = (IRelationalOperator)pFeature.Shape;
                        if (re.Equals(pFeature2.Shape))
                        {
                            pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultSubtract, false);
                            break;
                        }
                        else
                        {
                            m_Map.SelectFeature(pFeatLyr as ILayer, pFeature);
                        }
                        pFeature2 = pEnumFeature2.Next();
                    }
                    pFeature = pFeatCursor.NextFeature();
                }
                m_activeView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatCursor);
            }
            catch (Exception ex)
            {
                //SysLogHelper.WriteOperationLog("选择要素错误", ex.Source, "数据编辑");
            }
        }