コード例 #1
0
        public IGeometry EndFeatureEdit(int x, int y)
        {
            if (MyfeedBack == null)
            {
                return(null);
            }

            IGeometry geometry = null;
            IPoint    point    = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            if ((MyfeedBack as IMovePointFeedback) != null)
            {
                IMovePointFeedback pointMove = MyfeedBack as IMovePointFeedback;
                geometry = pointMove.Stop() as IGeometry;
            }
            else if ((MyfeedBack as ILineMovePointFeedback) != null)
            {
                ILineMovePointFeedback lineMove = MyfeedBack as ILineMovePointFeedback;
                geometry = lineMove.Stop() as IGeometry;
            }
            else if ((MyfeedBack as IPolygonMovePointFeedback) != null)
            {
                IPolygonMovePointFeedback polyMove = MyfeedBack as IPolygonMovePointFeedback;
                geometry = polyMove.Stop() as IGeometry;
            }
            MyfeedBack = null;
            MyMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, MyselectedLayer, null);
            return(geometry);
        }
コード例 #2
0
        /// <summary>
        /// 完成地图对象编辑,取得编辑后的对象,并将其更新到图层中
        /// 建议在Map.MouseUp事件中调用本方法
        /// </summary>
        public void EditFeatureEnd()
        {
            IGeometry pGeometry;

            try
            {
                if (m_pFeedback == null)
                {
                    return;
                }

                if (m_pFeedback is IMovePointFeedback)
                {
                    IMovePointFeedback pPointMove = (IMovePointFeedback)m_pFeedback;
                    pGeometry = pPointMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is ILineMovePointFeedback)
                {
                    ILineMovePointFeedback pLineMove = (ILineMovePointFeedback)m_pFeedback;
                    pGeometry = pLineMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is IPolygonMovePointFeedback)
                {
                    IPolygonMovePointFeedback pPolyMove = (IPolygonMovePointFeedback)m_pFeedback;
                    pGeometry = pPolyMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }

                m_pFeedback = null;
//				m_pSelectionTracker = null;
                IActiveView pActiveView = (IActiveView)m_pMap;
                pActiveView.Refresh();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
コード例 #3
0
        public bool EditFeature(int x, int y, IGeometry geometry)
        {
            GetFeatureOnMouseDown(x, y);
            SelectOnMouseDown();
            if (MyselectedFeature.Count < 1)
            {
                return(false);
            }
            if (geometry == null)
            {
                return(false);
            }

            IPoint pHitPoint = null;
            double hitDist = 0, tol = 0;
            int    vertexIndex = 0, vertexOffset = 0, numVertices = 0, partIndex = 0;
            bool   vertex = false;

            IFeature editedFeature = MyselectedFeature[0];
            IPoint   point         = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            tol = ConvertPixelsToMapUnits(4);
            //IGeometry pGeo = editedFeature.Shape;
            //m_EditingFeature = editedFeature;

            try
            {
                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryPoint:
                    MyfeedBack         = new MovePointFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMovePointFeedback pointMove = MyfeedBack as IMovePointFeedback;
                    pointMove.Start(geometry as IPoint, point);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex))
                    {
                        if (!vertex)
                        {
                            IGeometryCollection geometryColl = geometry as IGeometryCollection;
                            IPath            path            = geometryColl.get_Geometry(partIndex) as IPath;
                            IPointCollection pointColl       = path as IPointCollection;
                            numVertices = pointColl.PointCount;
                            object missing = Type.Missing;

                            if (vertexIndex == 0)
                            {
                                object start = 1 as object;
                                pointColl.AddPoint(point, ref start, ref missing);
                            }
                            else
                            {
                                object objVertexIndex = vertexIndex as object;
                                pointColl.AddPoint(point, ref missing, ref objVertexIndex);
                            }
                            TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex);
                        }
                        MyfeedBack         = new LineMovePointFeedbackClass();
                        MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                        ILineMovePointFeedback lineMove = MyfeedBack as ILineMovePointFeedback;
                        lineMove.Start(geometry as IPolyline, vertexIndex, point);
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    if (TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex))
                    {
                        if (!vertex)
                        {
                            IGeometryCollection geometryColl = geometry as IGeometryCollection;
                            IPath            path            = geometryColl.get_Geometry(partIndex) as IPath;
                            IPointCollection pointColl       = path as IPointCollection;
                            numVertices = pointColl.PointCount;
                            object missing = Type.Missing;
                            if (vertexIndex == 0)
                            {
                                object start = 1 as object;
                                pointColl.AddPoint(point, ref start, ref missing);
                            }
                            else
                            {
                                object objVertexIndex = vertexIndex as object;
                                pointColl.AddPoint(point, ref missing, ref objVertexIndex);
                            }
                            TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex);
                        }
                        MyfeedBack         = new PolygonMovePointFeedbackClass();
                        MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                        IPolygonMovePointFeedback polyMove = MyfeedBack as IPolygonMovePointFeedback;
                        polyMove.Start(geometry as IPolygon, vertexIndex + vertexOffset, point);
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }
            }
            catch { return(false); }
            return(true);
        }
コード例 #4
0
        private void EditMouseUp(IPoint pPnt)
        {
            IPolygon       pPolyResult;
            IPolyline      pPolylineResult;
            IFeatureCursor pFeatureCursor;
            IFeature       pFeature;
            IFeatureLayer  pFeatLyr = m_EngineEditLayers.TargetLayer;

            //检查编辑的地物
            if (m_editDispFeed != null)
            {
                switch (m_pHitElem.Geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryLine:
                case esriGeometryType.esriGeometryPolyline:
                    pPolylineResult = m_polylineMvPtFeed.Stop();
                    //作有效性检查
                    if ((pPolylineResult != null))
                    {
                        //更新元素
                        m_pHitElem.Geometry = pPolylineResult;

                        //获取选中的地物
                        pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);
                        if (pFeatureCursor == null)
                        {
                            return;
                        }
                        pFeature = pFeatureCursor.NextFeature();
                        m_EngineEditor.StartOperation();
                        //更新要素形状
                        pFeature.Shape = pPolylineResult;
                        pFeature.Store();
                        //停止编辑
                        m_EngineEditor.StopOperation("MoveVertex");
                        EditVertexClass.ShowAllVertex(pFeatLyr);
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                case esriGeometryType.esriGeometryEnvelope:
                    //得到反馈的结果
                    pPolyResult = m_polyMvPtFeed.Stop();
                    //作有效性检查
                    if (pPolyResult != null)
                    {
                        //更新元素
                        m_pHitElem.Geometry = pPolyResult;
                        //获取选中的地物
                        pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);
                        if (pFeatureCursor == null)
                        {
                            return;
                        }
                        pFeature = pFeatureCursor.NextFeature();
                        m_EngineEditor.StartOperation();
                        //更新要素形状
                        pFeature.Shape = pPolyResult;
                        pFeature.Store();
                        //停止编辑
                        m_EngineEditor.StopOperation("MoveVertex");
                        if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon ||
                            pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                        {
                            EditVertexClass.ShowAllVertex(pFeatLyr);
                        }
                    }
                    IFeature pTempParcel;
                    //定义存储多边形要素的局部变量
                    IPoint pDestPoint;
                    //定义节点移动的目标位置
                    pDestPoint = pPnt;
                    IZAware pZAware = pDestPoint as IZAware;
                    pZAware.ZAware = true;
                    pDestPoint.Z   = 0;
                    //所有包含该节点的多边形都进行操作
                    for (int i = 0; i <= EditVertexClass.m_featArray.Count - 1; i++)
                    {
                        pTempParcel = EditVertexClass.m_featArray.get_Element(i) as IFeature;
                        //记录节点序号
                        int pIndex = 0;
                        pIndex = EditVertexClass.GetVertexIndex(m_fromPoint, pTempParcel.Shape);
                        if (!(pIndex == -2))
                        {
                            ITopologicalOperator pTopoOpt         = default(ITopologicalOperator);
                            IPolygon             pPolygon         = default(IPolygon);
                            IPointCollection     pPolygonPointCol = default(IPointCollection);
                            pPolygonPointCol = pTempParcel.ShapeCopy as IPointCollection;
                            pPolygonPointCol.UpdatePoint(pIndex, pDestPoint);
                            pPolygon = pPolygonPointCol as IPolygon;
                            pPolygon.Close();
                            pTopoOpt = pPolygon as ITopologicalOperator;
                            pTopoOpt.Simplify();
                            pTempParcel.Shape = pPolygon;
                            pTempParcel.Store();
                        }
                    }
                    EditVertexClass.m_featArray.RemoveAll();
                    break;
                }

                //释放内存
                m_polyMvPtFeed     = null;
                m_polylineMvPtFeed = null;
                m_editDispFeed     = null;
                m_pHitElem         = null;
                //刷新地图
                m_activeView.Refresh();
            }
        }
コード例 #5
0
        private void EditMouseDown(IPoint pPnt)
        {
            try
            {
                IPolygon  pGeompoly;
                IPolyline pGeomPolyline;
                IHitTest  pHtTest;
                IPoint    pPtHit;
                double    pDblHitDis   = 0;
                int       pLngPrtIdx   = 0;
                int       pLngSegIdx   = 0;
                Boolean   pBoolHitRt   = false;
                Boolean   pBoolHitTest = false;
                double    pDblSrchDis  = 0;
                pPnt.Z      = 0;
                pPtHit      = new PointClass();
                pDblSrchDis = m_activeView.Extent.Width / 200;
                //获取编辑目标图层
                IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer;
                if (pFeatLyr == null)
                {
                    return;
                }
                IFeatureCursor pFeatCur  = MapManager.GetSelectedFeatures(pFeatLyr);
                IFeature       pTFeature = pFeatCur.NextFeature();
                switch (pTFeature.Shape.GeometryType)
                {
                //当为单点、点集时直接返回
                case esriGeometryType.esriGeometryPoint:
                case esriGeometryType.esriGeometryMultipoint:
                    return;

                //线要素
                case esriGeometryType.esriGeometryLine:
                case esriGeometryType.esriGeometryPolyline:
                    m_pHitElem = new LineElementClass();
                    break;

                //面要素
                case esriGeometryType.esriGeometryPolygon:
                case esriGeometryType.esriGeometryEnvelope:
                    m_pHitElem = new PolygonElementClass();
                    break;
                }
                //获取选中要素的几何对象
                m_pHitElem.Geometry = pTFeature.Shape;
                if (m_pHitElem != null)
                {
                    switch (pTFeature.Shape.GeometryType)
                    {
                    case esriGeometryType.esriGeometryLine:
                    case esriGeometryType.esriGeometryPolyline:
                        pGeomPolyline = m_pHitElem.Geometry as IPolyline;
                        pHtTest       = pGeomPolyline as IHitTest;
                        pBoolHitTest  = pHtTest.HitTest(pPnt, pDblSrchDis,
                                                        esriGeometryHitPartType.esriGeometryPartVertex, pPtHit,
                                                        ref pDblHitDis, ref pLngPrtIdx, ref pLngSegIdx, ref pBoolHitRt);
                        if (pBoolHitTest)
                        {
                            EditVertexClass.pHitPnt = pPtHit;
                            m_editDispFeed          = new LineMovePointFeedbackClass();
                            m_editDispFeed.Display  = m_activeView.ScreenDisplay;
                            m_polylineMvPtFeed      = m_editDispFeed as ILineMovePointFeedback;
                            m_polylineMvPtFeed.Start(pGeomPolyline, pLngSegIdx, pPnt);
                        }

                        break;

                    case esriGeometryType.esriGeometryPolygon:
                    case esriGeometryType.esriGeometryEnvelope:
                        pGeompoly    = m_pHitElem.Geometry as IPolygon;
                        pHtTest      = pGeompoly as IHitTest;
                        pBoolHitTest = pHtTest.HitTest(pPnt, pDblSrchDis,
                                                       esriGeometryHitPartType.esriGeometryPartVertex,
                                                       pPtHit, ref pDblHitDis, ref pLngPrtIdx, ref pLngSegIdx, ref pBoolHitRt);
                        EditVertexClass.pHitPnt = pPtHit;
                        if (pBoolHitTest)
                        {
                            //定义获取到的与传入点的最近所选地物
                            IFeature pFeature;
                            //定义测量距离用于捕获离点最近的地物
                            double pTestDist = 0;
                            //用于求点与地物的距离
                            IProximityOperator pProximity;
                            IGeometry          pGeoM;
                            IFeature           pTestFeature;
                            //用于最短距离的比较
                            double               pTempDist = 0;
                            IFeatureCursor       pSelected;
                            ITopologicalOperator pTopoOpt;
                            //捕捉到的要移动的节点
                            IPoint pSnapVertex = default(IPoint);
                            //从所选地物中获得离点最近的那个地物
                            pFeature = null;
                            //用鼠标点进行运算
                            pTopoOpt = pPnt as ITopologicalOperator;
                            pTopoOpt.Simplify();
                            pProximity   = pPnt as IProximityOperator;
                            pSelected    = MapManager.GetSelectedFeatures(pFeatLyr);
                            pTestFeature = pSelected.NextFeature();
                            pGeoM        = pTestFeature.Shape;
                            pTestDist    = pProximity.ReturnDistance(pGeoM);
                            pFeature     = pTestFeature;
                            //从所选地物中获得离点最近的那个地物
                            while (pTestFeature != null)
                            {
                                pTestFeature = pSelected.NextFeature();
                                if (pTestFeature != null)
                                {
                                    pGeoM     = pTestFeature.Shape;
                                    pTempDist = pProximity.ReturnDistance(pGeoM);
                                    if (pTempDist < pTestDist)
                                    {
                                        pTestDist = pTempDist;
                                        pFeature  = pTestFeature;
                                    }
                                }
                            }

                            //检查pSnapPoint是否是所选地物中的某个图斑的一个节点
                            double pDblHDis      = 0;
                            int    pLngVertexIdx = 0;
                            int    pLngSIdx      = 0;
                            bool   pBoolHRt      = false;
                            bool   pBlnGet       = false;
                            double pDblDistMin   = 0;
                            pDblDistMin = pTempDist;
                            if (pDblDistMin == 0)
                            {
                                pDblDistMin = 3;
                            }
                            //两倍可以保证一般一次找的到
                            double   pDblSearchRadius = pDblDistMin * 2;
                            IHitTest pHT = default(IHitTest);
                            pHT = pFeature.Shape as IHitTest;
                            //如果pSnapPoint不是pTempParcel的节点
                            if (EditVertexClass.GetVertexIndex(pPnt, pFeature.Shape) == -2)
                            {
                                pSnapVertex = new Point();
                                while (!pBlnGet)
                                {
                                    pBlnGet = pHT.HitTest(pPnt, pDblSearchRadius,
                                                          esriGeometryHitPartType.esriGeometryPartVertex,
                                                          pSnapVertex, ref pDblHDis, ref pLngVertexIdx, ref pLngSIdx, ref pBoolHRt);
                                    pDblSearchRadius = pDblSearchRadius + pDblDistMin;
                                }
                                EditVertexClass.pHitPnt = pSnapVertex;
                                //如果pSnapVertex仍然不是pTempParcel的节点
                                if (EditVertexClass.GetVertexIndex(pSnapVertex, pFeature.Shape) == -2)
                                {
                                    MessageBox.Show("所想移动的起点不是所选面的节点", "提示",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                                m_fromPoint = pSnapVertex;
                            }
                            else
                            {
                                pSnapVertex = pPnt;
                                m_fromPoint = pSnapVertex;
                            }
                            //找到包含所要移动的节点的图形,在该过程里面对m_FeatArray进行了赋值
                            EditVertexClass.SelectByShapeTop(pFeatLyr, pSnapVertex, esriSpatialRelEnum.esriSpatialRelTouches,
                                                             false, esriSelectionResultEnum.esriSelectionResultNew);
                            m_editDispFeed         = new PolygonMovePointFeedbackClass();
                            m_editDispFeed.Display = m_activeView.ScreenDisplay;
                            m_polyMvPtFeed         = m_editDispFeed as IPolygonMovePointFeedback;
                            m_polyMvPtFeed.Start(pGeompoly, pLngSegIdx, pPnt);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                //SysLogHelper.WriteOperationLog("节点移动错误", ex.Source, "数据编辑");
            }
        }
コード例 #6
0
        /// <summary>
        /// 编辑当前图层中鼠标击中的地图对象(开始编辑),
        /// 如果为点对象,可进行位置移动,如果为线对象或面对象,可进行节点编辑
        /// 建议在Map.MouseDown事件中调用本方法
        /// </summary>
        /// <param name="x">鼠标X坐标,屏幕坐标</param>
        /// <param name="y">鼠标Y坐标,屏幕坐标</param>
        /// <returns></returns>
        public void  EditFeatureMouseDown(int x, int y)
        {
            IGeometryCollection pGeomColn;
            IPointCollection    pPointColn;
            IObjectClass        pObjectClass;
            IFeature            pFeature;
            IGeometry           pGeom;

            IPath  pPath;
            IPoint pHitPoint = null;
            IPoint pPoint    = null;
            Double hitDist   = 0.0;
            double tol;
            int    vertexIndex = 0;
            int    numVertices;
            int    partIndex = 0;
            bool   vertex    = false;

            try
            {
                m_pMap.ClearSelection();

                // 取得鼠标击中的第一个对象
                SelectMouseDown(x, y);
                IEnumFeature pSelected = (IEnumFeature)m_pMap.FeatureSelection;
                pFeature = pSelected.Next();
                if (pFeature == null)
                {
                    return;
                }

                IActiveView pActiveView = (IActiveView)m_pMap;
                pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

                // 节点空间查询容差
                tol = ConvertPixelsToMapUnits(pActiveView, 4.0);

                pGeom          = pFeature.Shape;
                pObjectClass   = pFeature.Class;
                m_pEditFeature = pFeature;
                object objNull = Missing.Value;
                object objBefore, objAfter;

                switch (pGeom.GeometryType)
                {
                case esriGeometryType.esriGeometryPoint:
                    m_pFeedback         = new MovePointFeedbackClass();
                    m_pFeedback.Display = pActiveView.ScreenDisplay;
                    IMovePointFeedback pPointMove = (IMovePointFeedback)m_pFeedback;
                    pPointMove.Start((IPoint)pGeom, pPoint);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex))
                    {
                        if (!vertex)
                        {
                            pGeomColn   = (IGeometryCollection)pGeom;
                            pPath       = (IPath)pGeomColn.get_Geometry(partIndex);
                            pPointColn  = (IPointCollection)pPath;
                            numVertices = pPointColn.PointCount;

                            if (vertexIndex == 0)
                            {
                                objBefore = (object)(vertexIndex + 1);
                                pPointColn.AddPoint(pPoint, ref objBefore, ref objNull);
                            }
                            else
                            {
                                objAfter = (object)vertexIndex;
                                pPointColn.AddPoint(pPoint, ref objNull, ref objAfter);
                            }

                            TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex);
                        }
                        m_pFeedback         = new LineMovePointFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        ILineMovePointFeedback pLineMove = (ILineMovePointFeedback)m_pFeedback;
                        pLineMove.Start((IPolyline)pGeom, vertexIndex, pPoint);

//							m_pSelectionTracker = new LineTrackerClass();
//							m_pSelectionTracker.Display = pActiveView.ScreenDisplay ;
//							m_pSelectionTracker.Geometry = pGeom;
//							m_pSelectionTracker.ShowHandles = true;
//							m_pSelectionTracker.QueryResizeFeedback(ref m_pFeedback);
//							m_pSelectionTracker.OnMouseDown(1,0,x,y);
                    }
                    else
                    {
                        return;
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    if (TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex))
                    {
                        if (!vertex)
                        {
                            pGeomColn   = (IGeometryCollection)pGeom;
                            pPath       = (IPath)pGeomColn.get_Geometry(partIndex);
                            pPointColn  = (IPointCollection)pPath;
                            numVertices = pPointColn.PointCount;

                            if (vertexIndex == 0)
                            {
                                objBefore = (object)(vertexIndex + 1);
                                pPointColn.AddPoint(pPoint, ref objBefore, ref objNull);
                            }
                            else
                            {
                                objAfter = (object)vertexIndex;
                                pPointColn.AddPoint(pPoint, ref objNull, ref objAfter);
                            }

                            TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex);
                        }

                        m_pFeedback         = new PolygonMovePointFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        IPolygonMovePointFeedback pPolyMove = (IPolygonMovePointFeedback)m_pFeedback;
                        pPolyMove.Start((IPolygon)pGeom, vertexIndex, pPoint);
                    }
                    else
                    {
                        return;
                    }
                    break;
                }
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                return;
            }
        }