• AE编辑点要素编辑


    来自:http://blog.163.com/liuyang1285@126/blog/static/128913086201212151123418/?latestBlog

    AE编辑-点要素编辑  

    2012-02-21 17:11:23|  分类: 工作 |  标签: |字号 订阅

    点的捕捉

    指定捕捉图层(开发中以电缆沟点图层为捕捉图层),设置捕捉半径和捕捉要素显示的标注信息,在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();

     

                    //Tnodeid|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()保存。

  • 相关阅读:
    客户端请求页面的方式和提交数据的方式
    客户端请求页面的方式
    request session application cookie 保存数据
    jsp session(会话) 的使用 cookies,application 理解
    jsp内置对象
    jsp 实现数据传递
    最近戴着眼镜坐电脑前总是不自觉的眼痛就搜了下怎么保护眼睛无意中看到了这篇文章希望广大爱好编程的朋友多注意保护自己的眼睛!!
    选择排序(使用Python描述)
    归并排序(使用Python描述)
    二分查找的两种方法(使用Python描述)
  • 原文地址:https://www.cnblogs.com/gisoracle/p/2432648.html
Copyright © 2020-2023  润新知