示例#1
0
        public void InsertPoint(int partIndex, int pointIndex, IPoint newPoint)
        {
            // TODO:  添加 ModifyMultiPoint.WSGRI.DigitalFactory.DFQuery.IModifyGeometry.InsertPoint 实现
            IPointCollection pColl = (IPointCollection)Feature.Shape;

            if ((partIndex >= -1) && (partIndex <= pColl.PointCount))
            {
                pColl.InsertPoints(partIndex, 1, ref newPoint);
                Feature.Shape = (IGeometry)pColl;
                Feature.Store();
            }
        }
示例#2
0
        public void InsertPoint(int partIndex, int pointIndex, IPoint newPoint)
        {
            // TODO:  添加 ModifyMultiPoint.WSGRI.DigitalFactory.DFQuery.IModifyGeometry.InsertPoint 实现
            IPointCollection pColl = (IPointCollection)m_GeoColl.get_Geometry(partIndex);

            if ((pointIndex >= -1) && (pointIndex <= pColl.PointCount))
            {
                //object none = Type.Missing;
                pColl.InsertPoints(pointIndex, 1, ref newPoint);
                Feature.Store();
            }
        }
示例#3
0
 private void AddVertexNode(IPoint pPnt)
 {
     try
     {
         IFeatureLayer pFeaturelayer = m_EngineEditLayers.TargetLayer;
         IActiveView   pActiveView   = m_activeView;
         IPoint        pPoint        = pPnt;
         if (pFeaturelayer.FeatureClass == null)
         {
             return;
         }
         //如果不是面状地物则退出
         if (pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryEnvelope &&
             pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon &&
             pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryLine &&
             pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
         {
             return;
         }
         IGeometry pGeo        = null;
         IFeature  pSelFeature = null;
         pSelFeature = EditVertexClass.GetSelectedFeature(pFeaturelayer);
         //是否有选中的几何体
         if (pSelFeature == null)
         {
             return;
         }
         //解决不带Z值的要素的编辑和Z值为空的要素的编辑问题
         IZAware pZAware = pPoint as IZAware;
         pZAware.ZAware = true;
         pPoint.Z       = 0;
         bool pInLine = false;
         ITopologicalOperator pTopoOpt      = default(ITopologicalOperator);
         IPolyline            pBoundaryLine = default(IPolyline);
         //最小的距离
         double             pMindis  = 0;
         IProximityOperator pProxOpt = default(IProximityOperator);
         //得到多边形的边界
         if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon ||
             pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryEnvelope)
         {
             //获取边界线
             pBoundaryLine = EditVertexClass.GetBoundary(pFeaturelayer);
         }
         else if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline ||
                  pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryLine)
         {
             pBoundaryLine = pSelFeature.ShapeCopy as IPolyline;
         }
         pTopoOpt = pPoint as ITopologicalOperator;
         IRelationalOperator pRelationalOperator = default(IRelationalOperator);
         pRelationalOperator = pPoint as IRelationalOperator;
         //判断点是否在边界上
         pInLine = pRelationalOperator.Within(pBoundaryLine);
         //如果不在边界上,判断是否小于容忍距离,如果大于容忍距离则退出程序
         if (pInLine == false)
         {
             pProxOpt = pPoint as IProximityOperator;
             pMindis  = pProxOpt.ReturnDistance(pBoundaryLine);
             if (pMindis > THE_POINT_TO_POINT_TOLERANCE)
             {
                 return;
             }
         }
         //判断是否增加的点刚好为节点
         IPointCollection pPolylinePointCol = pBoundaryLine as IPointCollection;
         IHitTest         pHitTest          = default(IHitTest);
         double           pHitDis           = 0;
         int    pSegIndex  = 0;
         int    pVerIndex  = 0;
         IPoint pHitPoint  = null;
         bool   bRightSide = true;
         pHitTest = pBoundaryLine as IHitTest;
         //增加的点为已有的节点则退出程序
         if (pHitTest.HitTest(pPoint, THE_POINT_TO_POINT_TOLERANCE * 10,
                              esriGeometryHitPartType.esriGeometryPartVertex, pHitPoint,
                              ref pHitDis, ref pSegIndex, ref pVerIndex, ref bRightSide) == true)
         {
             if (pHitDis < THE_POINT_TO_POINT_TOLERANCE)
             {
                 return;
             }
         }
         EditVertexClass.pHitPnt = pHitPoint;
         //为多边形增加节点
         ISegmentCollection pSegmentCollection = pBoundaryLine as ISegmentCollection;
         IPolyline          pSegPolyline       = null;
         int    pPointIndex = 0;
         ILine  pLine       = default(ILine);
         double pDis1       = 0;
         double pDis2       = 0;
         IPoint pVerTex     = default(IPoint);
         pMindis  = 100;
         pProxOpt = pPoint as IProximityOperator;
         for (int i = 0; i <= pSegmentCollection.SegmentCount - 1; i++)
         {
             //判断选中点是否在这个Segment上
             pLine = pSegmentCollection.get_Segment(i) as ILine;
             pDis1 = pProxOpt.ReturnDistance(pLine.FromPoint);
             pDis2 = pProxOpt.ReturnDistance(pLine.ToPoint);
             if (Math.Abs(pDis1 + pDis2 - pLine.Length) <= pMindis)
             {
                 pMindis = Math.Abs(pDis1 + pDis2 - pLine.Length);
                 pVerTex = pLine.ToPoint;
             }
         }
         //获取选中的几何特征
         pGeo = pSelFeature.Shape;
         //得到索引
         pPointIndex = EditVertexClass.GetVertexIndex(pVerTex, pGeo);
         //如果是首点,则设置为最后一个点
         if (pPointIndex == 0)
         {
             pPointIndex = pSegmentCollection.SegmentCount;
         }
         IPointCollection pPolygonPointCol = null;
         pPolygonPointCol = pSelFeature.ShapeCopy as IPointCollection;
         pPolygonPointCol.InsertPoints(pPointIndex, 1, ref pPoint);
         m_EngineEditor.StartOperation();
         //拓扑操作
         IPolygon  pPolygon = null;
         IPolyline pPlyline = null;
         if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon ||
             pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryEnvelope)
         {
             pPolygon = pPolygonPointCol as IPolygon;
             pPolygon.Close();
             pTopoOpt = pPolygon as ITopologicalOperator;
             pTopoOpt.Simplify();
             pSelFeature.Shape = pPolygon;
             pSelFeature.Store();
         }
         else if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline ||
                  pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryLine)
         {
             pPlyline = pPolygonPointCol as IPolyline;
             pTopoOpt = pPlyline as ITopologicalOperator;
             pTopoOpt.Simplify();
             pSelFeature.Shape = pPlyline;
             pSelFeature.Store();
         }
         //停止编辑
         m_EngineEditor.StopOperation("AddVertexTool");
         //显示顶点
         EditVertexClass.ShowAllVertex(pFeaturelayer);
     }
     catch (Exception ex)
     {
     }
 }
示例#4
0
        private void SnapPoint()
        {
            IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment;
            IEngineEditSketch      sketch       = Editor.UniqueInstance.EngineEditor as IEngineEditSketch;
            IPointCollection       points       = sketch.Geometry as IPointCollection;
            bool flag = false;

            if (sketch.GeometryType == esriGeometryType.esriGeometryPolygon)
            {
                flag = true;
            }
            if ((points.PointCount != 1) && (!flag || (points.PointCount != 2)))
            {
                IEngineFeatureSnapAgent agent2 = engineEditor.get_SnapAgent(0) as IEngineFeatureSnapAgent;
                esriSpatialRelEnum      esriSpatialRelIntersects = esriSpatialRelEnum.esriSpatialRelIntersects;
                if (agent2.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                {
                    esriSpatialRelIntersects = esriSpatialRelEnum.esriSpatialRelTouches;
                }
                IPoint          lastPoint = sketch.LastPoint;
                List <IFeature> pFeatures = new List <IFeature>();
                ISpatialFilter  filter    = new SpatialFilterClass {
                    Geometry      = lastPoint,
                    SpatialRel    = esriSpatialRelIntersects,
                    SubFields     = agent2.FeatureClass.OIDFieldName + "," + agent2.FeatureClass.ShapeFieldName,
                    GeometryField = agent2.FeatureClass.ShapeFieldName
                };
                IFeatureCursor o    = agent2.FeatureClass.Search(filter, false);
                IFeature       item = o.NextFeature();
                while (item != null)
                {
                    if (item.HasOID && !item.Shape.IsEmpty)
                    {
                        pFeatures.Add(item);
                        item = o.NextFeature();
                    }
                }
                Marshal.ReleaseComObject(o);
                if (pFeatures.Count >= 1)
                {
                    IPoint queryPoint = null;
                    if (flag)
                    {
                        queryPoint = points.get_Point(points.PointCount - 3);
                    }
                    else
                    {
                        queryPoint = points.get_Point(points.PointCount - 2);
                    }
                    List <IFeature> list2 = new List <IFeature>();
                    filter = new SpatialFilterClass {
                        Geometry      = queryPoint,
                        SpatialRel    = esriSpatialRelIntersects,
                        SubFields     = agent2.FeatureClass.OIDFieldName + "," + agent2.FeatureClass.ShapeFieldName,
                        GeometryField = agent2.FeatureClass.ShapeFieldName
                    };
                    o    = null;
                    o    = agent2.FeatureClass.Search(filter, false);
                    item = o.NextFeature();
                    while (item != null)
                    {
                        if (item.HasOID && !item.Shape.IsEmpty)
                        {
                            list2.Add(item);
                            item = o.NextFeature();
                        }
                    }
                    Marshal.ReleaseComObject(o);
                    if (list2.Count >= 1)
                    {
                        IList <IFeature> list3 = new List <IFeature>();
                        for (int i = 0; i < list2.Count; i++)
                        {
                            if (this.ContainFeature(pFeatures, list2[i]))
                            {
                                list3.Add(list2[i]);
                            }
                        }
                        IFeature feature2 = null;
                        if (list3.Count == 1)
                        {
                            feature2 = list3[0];
                        }
                        else
                        {
                            if (list3.Count == 0)
                            {
                                return;
                            }
                            if (list3.Count == pFeatures.Count)
                            {
                                IFeatureLayer  pLayer   = Editor.UniqueInstance.SnapLayers[0];
                                SnapExFeatures features = new SnapExFeatures(pFeatures, this._hookHelper, pLayer);
                                features.ShowDialog();
                                if (features.Index == -1)
                                {
                                    return;
                                }
                                feature2 = pFeatures[features.Index];
                                features = null;
                            }
                        }
                        double    hitDistance     = -1.0;
                        int       hitSegmentIndex = -1;
                        int       hitPartIndex    = -1;
                        bool      bRightSide      = false;
                        IGeometry geometry        = this.ProjectGeometry(feature2.Shape);
                        IHitTest  test            = geometry as IHitTest;
                        if (test.HitTest(lastPoint, engineEditor.SnapTolerance, esriGeometryHitPartType.esriGeometryPartVertex, null, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide))
                        {
                            int      num5  = -1;
                            double   num6  = -1.0;
                            int      num7  = -1;
                            int      num8  = -1;
                            bool     flag4 = false;
                            int      part  = sketch.Part;
                            IHitTest test2 = geometry as IHitTest;
                            if (test2.HitTest(queryPoint, engineEditor.SnapTolerance, esriGeometryHitPartType.esriGeometryPartVertex, null, ref num6, ref num8, ref num7, ref flag4))
                            {
                                IPolyline polyline3;
                                if (flag)
                                {
                                    num5 = points.PointCount - 2;
                                }
                                else
                                {
                                    num5 = points.PointCount - 1;
                                }
                                IGeometryCollection geometrys = geometry as IGeometryCollection;
                                IPointCollection    points2   = geometrys.get_Geometry(hitPartIndex) as IPointCollection;
                                IPolyline           polyline  = new PolylineClass();
                                IPolyline           polyline2 = new PolylineClass();
                                IPointCollection    points3   = polyline as IPointCollection;
                                IPointCollection    points4   = polyline2 as IPointCollection;
                                object before  = Missing.Value;
                                object after   = Missing.Value;
                                IPoint inPoint = null;
                                bool   flag6   = false;
                                if (num7 > hitSegmentIndex)
                                {
                                    int num9 = hitSegmentIndex;
                                    hitSegmentIndex = num7;
                                    num7            = num9;
                                    flag6           = true;
                                }
                                int num10 = 0;
                                if (flag)
                                {
                                    for (num10 = num7; num10 <= hitSegmentIndex; num10++)
                                    {
                                        inPoint = points2.get_Point(num10);
                                        points3.AddPoint(inPoint, ref before, ref after);
                                    }
                                    int num11 = points2.PointCount - 1;
                                    for (num10 = hitSegmentIndex; num10 < num11; num10++)
                                    {
                                        inPoint = points2.get_Point(num10);
                                        points4.AddPoint(inPoint, ref before, ref after);
                                    }
                                    for (num10 = 0; num10 <= num7; num10++)
                                    {
                                        inPoint = points2.get_Point(num10);
                                        points4.AddPoint(inPoint, ref before, ref after);
                                    }
                                    if (polyline.Length <= polyline2.Length)
                                    {
                                        polyline3 = polyline;
                                    }
                                    else
                                    {
                                        polyline3 = polyline2;
                                        flag6     = true;
                                    }
                                }
                                else
                                {
                                    num10 = num7;
                                    while (num10 <= hitSegmentIndex)
                                    {
                                        inPoint = points2.get_Point(num10);
                                        points3.AddPoint(inPoint, ref before, ref after);
                                        num10++;
                                    }
                                    polyline3 = polyline;
                                }
                                IPointCollection points5 = polyline3 as IPointCollection;
                                int index = num5;
                                if (flag6)
                                {
                                    for (num10 = points5.PointCount - 2; num10 > 0; num10--)
                                    {
                                        IPoint newPoints = (points5.get_Point(num10) as IClone).Clone() as IPoint;
                                        points.InsertPoints(index, 1, ref newPoints);
                                        index++;
                                    }
                                }
                                else
                                {
                                    for (num10 = 1; num10 < (points5.PointCount - 1); num10++)
                                    {
                                        IPoint point7 = (points5.get_Point(num10) as IClone).Clone() as IPoint;
                                        points.InsertPoints(index, 1, ref point7);
                                        index++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        public void OnMouseDown(int button, int shift, int x, int y)
        {
            this._bMouse = true;
            IPoint point = this._hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            this._tool.OnMouseDown(1, shift, x, y);
            if (this._bFinished)
            {
                this._bFinished = false;
            }
            else
            {
                try
                {
                    if (this._snappingEnv == null)
                    {
                        return;
                    }
                    IPointSnapper     pointSnapper = this._snappingEnv.PointSnapper;
                    ISnappingResult   result       = pointSnapper.Snap(point);
                    IEngineEditSketch engineEditor = Editor.UniqueInstance.EngineEditor as IEngineEditSketch;
                    IPointCollection  points       = engineEditor.Geometry as IPointCollection;
                    if (!this._bStarted)
                    {
                        this.CreateFeed();
                        if (result != null)
                        {
                            this._lineFeedback.Start(result.Location);
                        }
                        this._bStarted = true;
                        return;
                    }
                    IGeometry geometry = engineEditor.Geometry;
                    if (geometry == null)
                    {
                        return;
                    }
                    IPointCollection points2  = geometry as IPointCollection;
                    IPolyline        polyline = this._lineFeedback.Stop();
                    int index = 0;
                    if (engineEditor.GeometryType == esriGeometryType.esriGeometryPolygon)
                    {
                        index = points.PointCount - 2;
                    }
                    else
                    {
                        index = points.PointCount - 1;
                    }
                    if (polyline != null)
                    {
                        IPointCollection points3 = (IPointCollection)polyline;
                        for (int i = 1; i < (points3.PointCount - 1); i++)
                        {
                            IPoint point2    = points3.get_Point(i);
                            IPoint newPoints = (point2 as IClone).Clone() as IPoint;
                            if (pointSnapper.Snap(point2).Type == esriSnappingType.esriSnappingTypeVertex)
                            {
                                points2.InsertPoints(index, 1, ref newPoints);
                                index++;
                            }
                        }
                    }
                    int hDC = this._hookHelper.ActiveView.ScreenDisplay.hDC;
                    this._lineFeedback.Stop();
                    this._lineFeedback.Refresh(hDC);
                    if (result != null)
                    {
                        this._lineFeedback.Start(result.Location);
                    }
                    if (button == 2)
                    {
                        this.OnDblClick();
                    }
                    engineEditor.RefreshSketch();
                }
                catch (Exception exception)
                {
                    this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.SnapEx", "OnMouseUp", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
                }
                this._bMouse = false;
            }
        }