AE编辑-点要素编辑

AE编辑-点要素编辑  

 

 

点的捕捉

指定捕捉图层(开发中以电缆沟点图层为捕捉图层),设置捕捉半径和捕捉要素显示的标注信息,在OnMouseMove事件中处理实现。

pt_Move = m_pScrD.DisplayTransformation.ToMapPoint(X, Y);

 

                    if (m_pLineFeedback == null)

                    {

                        //清?空textelment markelment[IGroupElement]

                        m_pAV.GraphicsContainer.Reset();

                        IElementProperties elementProperties_temp = null;

                        IElement elment = m_pAV.GraphicsContainer.Next();

                        while (elment != null)

                        {

                            elementProperties_temp = elment as IElementProperties;

                            if (elementProperties_temp.Name.StartsWith("SnapLabel"))

                            {

                                m_pAV.GraphicsContainer.DeleteElement(elment);

                            }

                            elment = m_pAV.GraphicsContainer.Next();

                        }

                        m_pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pAV.Extent);

                    }

 

                    featureCache = new FeatureCacheClass();

                    //如果已经拥有缓冲区,而且当前点依然在该缓冲区内部,那么不会填充生成新的缓冲

                    if (!featureCache.Contains(pt_Move))

                    {

                        featureCache.Initialize(pt_Move, Convert.ToDouble(clsHelper.GetConfigValue("SnapRadius")));//10

                        featureCache.AddFeatures(featureLayer.FeatureClass);

                        IFeature feature;

                        IGeometry geometry;

                        int indexFeature, countFeature;

                        countFeature = featureCache.Count;

                        for (indexFeature = 0; indexFeature < countFeature; indexFeature++)

                        {

                            feature = featureCache.get_Feature(indexFeature);

                            if (feature != null)

                            {

                                geometry = feature.Shape;

                                IPoint hitPoint = new PointClass();

                                double hitDist = 0;

                                int hitPartIndex = 0;

                                bool bRightSide = false;

                                int hitSegmentIndex = 0;

                                IHitTest hitTest = geometry as IHitTest;

                                //m_pAV.Extent.Width / 200

                                if (hitTest.HitTest(pt_Move, 2, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref hitDist, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide))

                                {

                                    AddPointElement(m_pAV, hitPoint, feature.get_Value(feature.Fields.FindField("TRENCHID")).ToString());

                                    break;//只高亮显示一个要素

                                }

                            }

                        }

                    }

 

        ///

        /// </summary>

        /// <param name="pActiveView"></param>

        /// <param name="pPoint"></param>

        /// <param name="strLabel"></param>

        private void AddPointElement(IActiveView pActiveView, IPoint pPoint, string strLabel)

        {

            IMarkerElement pMarkerElement = new MarkerElementClass();

            IElement pElement;

            ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol();

            IRgbColor pRgbColor = new RgbColorClass();

            pRgbColor.Red = 0;

            pRgbColor.Green = 255;

            pRgbColor.Blue = 25;

            pMarkerSymbol.Color = pRgbColor;

            pMarkerSymbol.Size = 5; //单位为像素

            pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

            pMarkerElement.Symbol = (IMarkerSymbol)pMarkerSymbol;

            pElement = (IElement)pMarkerElement;

            pElement.Geometry = (IGeometry)pPoint;

 

            IElementProperties elementProperties_Trench = pMarkerElement as IElementProperties;

            elementProperties_Trench.Name = "SnapLabelPoint";

            pActiveView.GraphicsContainer.AddElement(pMarkerElement as IElement, 0);

            //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pAV.Extent);

 

            ITextElement pTextElement = new TextElementClass();

            IElement element_text;

            ISimpleTextSymbol simpleTextSymbol = new TextSymbolClass();

            stdole.StdFont myFont = new stdole.StdFont();

            myFont.Name = "Courier New";

            myFont.Size = 10;

            simpleTextSymbol.Font = myFont as stdole.IFontDisp;

            IRgbColor myColor = new RgbColorClass();

            myColor.Red = 150;

            myColor.Green = 0;

            myColor.Blue = 0;

            simpleTextSymbol.Color = myColor;

            simpleTextSymbol.Angle = 0;

            simpleTextSymbol.RightToLeft = false;

            simpleTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;

            simpleTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;

            simpleTextSymbol.BreakCharacter = 20;

            pTextElement.Symbol = simpleTextSymbol;

            pTextElement.Text = "电缆沟:" + strLabel;

            pTextElement.ScaleText = true;//随地图比例尺变化

            element_text = pTextElement as IElement;

            element_text.Geometry = (IGeometry)pPoint;

 

            IElementProperties elementProperties = pTextElement as IElementProperties;

            elementProperties.Name = "SnapLabelText";

 

            pActiveView.GraphicsContainer.AddElement(pTextElement as IElement, 0);

            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pAV.Extent);

        }

 

//获取要素

private IElement getElement(IPoint pPt, esriGeometryType geometryType)

        {

            IEnumElement pEnumElement;

            IElement pEle;

            pEnumElement = pGraphicContainer.LocateElements(pPt, pActiveView.Extent.Width / 100);

            if (pEnumElement != null)

            {

                pEnumElement.Reset();

                pEle = pEnumElement.Next();

                while (pEle != null)

                {

                    if (pEle.Geometry.GeometryType == geometryType)

                    {

                        return pEle;

                    }

                    pEle = pEnumElement.Next();

                }

            }

            return null;

        }

 

点的移动

点的移动,实现步骤,首先MouseDown选中某点,MouseMove移动该点,MouseUp更新点的空间位置(与点拓扑关联的要素也要同时更新)。

选择点要素,用到接口类IDisplayFeedback,移动点用到类 IMovePointFeedback

IPoint pPoint;

OnMouseDown事件中选择点要素后,并支持鼠标拖拽移动

                    IHitTest pHitTest_Point;

                    bool BoolHitTest_Point;

                    IPoint pPtHit_Point = null;

                    hitElement = getElement(pPt, esriGeometryType.esriGeometryPoint);

                    if (hitElement != null)//捕捉到点要素

                    {

                        pPoint = hitElement.Geometry as IPoint;

                        pDisplayFeedback = new MovePointFeedbackClass();

                        pDisplayFeedback.Display = pScreenDisplay;

                        ((IMovePointFeedback)pDisplayFeedback).Start(pPoint, pPt);

                    }

 

鼠标移动:public override void OnMouseMove(int Button, int Shift, int X, int Y)

        {

            IPoint pPt = new PointClass();

            pPt = pScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            if (pDisplayFeedback != null)

            {

                pDisplayFeedback.MoveTo(pPt);

            }

        }

 

鼠标MouseUp,保存新的要素空间位置以及相关属性信息:

private bool StoreFeatureGeometry(IFeature pFeature, IGeometry pIGeometry)

        {

            try

            {

                var pFeatureClass = pFeature.Class as IFeatureClass;

 

                var pDataset = pFeatureClass as IDataset;

                IWorkspace pWorkspace = pDataset.Workspace;

                var pWorkspaceEdit = pWorkspace as IWorkspaceEdit;

 

                pWorkspaceEdit.StartEditing(false);

                pWorkspaceEdit.StartEditOperation();

 

                //修T改nodeid|s_nodeid,e_nodeid

                if (pIGeometry.GeometryType == esriGeometryType.esriGeometryPoint)

                {

                    string strNodeId = (pIGeometry as IPoint).X.ToString("0.000")+

                        "-" + (pIGeometry as IPoint).Y.ToString("0.000");

                    pFeature.set_Value(pFeature.Fields.FindField("NODEID"), strNodeId);

                }

                else if (pIGeometry.GeometryType == esriGeometryType.esriGeometryPolyline)

                {

                    IPolyline polyline = pIGeometry as IPolyline;

                    string strSNodeId = polyline.FromPoint.X.ToString("0.000")+

                        "-" + polyline.FromPoint.Y.ToString("0.000");

                    string strENodeId = polyline.ToPoint.X.ToString("0.000") +

                        "-" + polyline.ToPoint.Y.ToString("0.000");

                    pFeature.set_Value(pFeature.Fields.FindField("S_NODEID"), strSNodeId);

                    pFeature.set_Value(pFeature.Fields.FindField("E_NODEID"), strENodeId);

                }

 

                pFeature.Shape = pIGeometry;

                pFeature.Store();

 

                pWorkspaceEdit.StopEditOperation();

                pWorkspaceEdit.StopEditing(true);

                return true;

            }

            catch (Exception ex)

            {

                return false;

            }

        }

 

点要素属性的修改

首先获取要编辑的IFeatureSet_Value(index,value)对字段赋值,最后Store()保存。

posted @ 2012-03-19 09:42  晴天有时下鱼  阅读(431)  评论(0编辑  收藏  举报