//删除节点事件
        void btnRemovePoint_Click(object sender, EventArgs e)
        {
            try
            {
                object misobj = Type.Missing;
                m_Editor.StartOperation();

                IGeometry        ring = (cbxRings.SelectedItem as CommonComboBoxItem).Tag as IGeometry;
                IPointCollection pc   = ring as IPointCollection;
                pc.RemovePoints((int)listPointCollection.SelectedItems[0].Tag, 1);

                IFeature            feature = (treeFeatures.SelectedNode.Tag as IFeature);
                IGeometryCollection geoCol  = cbxRings.Tag as IGeometryCollection;
                geoCol.AddGeometry(ring, ref misobj, ref misobj);
                geoCol.RemoveGeometries(cbxRings.SelectedIndex, 1);
                feature.Shape = geoCol as IGeometry;
                feature.Store();

                int removePointIndex = listPointCollection.SelectedItems[0].Index;
                listPointCollection.SelectedItems[0].Remove();

                m_Editor.StopOperation("RemovePoint");
                this.cbxRings_SelectedIndexChanged(sender, e);
                if (listPointCollection.Items.Count > removePointIndex)
                {
                    listPointCollection.Items[removePointIndex].Selected = true;
                    listPointCollection.TopItem = listPointCollection.SelectedItems[0];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private static void MergeLastWithFirstPart(IGeometryCollection paths)
        {
            int lastIndex = paths.GeometryCount - 1;

            var lastPart  = (ISegmentCollection)paths.get_Geometry(lastIndex);
            var firstPart = (ISegmentCollection)paths.get_Geometry(0);

            lastPart.AddSegmentCollection(firstPart);

            paths.RemoveGeometries(0, 1);
        }
Exemplo n.º 3
0
 public void RemovePart(int partIndex)
 {
     // TODO:  添加 ModifyMultiPoint.WSGRI.DigitalFactory.DFQuery.IModifyGeometry.RemovePart 实现
     if (m_GeoColl.GeometryCount < 2)
     {
         return;
     }
     if (partIndex < m_GeoColl.GeometryCount)
     {
         m_GeoColl.RemoveGeometries(partIndex, 1);
         Feature.Shape = (IGeometry)m_GeoColl;
         Feature.Store();
     }
 }
Exemplo n.º 4
0
 public void SaveEdit()
 {
     try
     {
         Editor.UniqueInstance.StartEditOperation();
         object before  = new object();
         object missing = Type.Missing;
         foreach (LinkArgs args in this._las)
         {
             if (args.PartIndex >= 0)
             {
                 IFeature            feature   = args.feature;
                 IGeometryCollection shapeCopy = feature.ShapeCopy as IGeometryCollection;
                 IPointCollection    points    = shapeCopy.get_Geometry(args.PartIndex) as IPointCollection;
                 for (int i = 0; i < this._editInfoList.Count; i++)
                 {
                     EditInfo info  = this._editInfoList[i] as EditInfo;
                     int      index = args.VertexIndex[i];
                     IPoint   p     = (info.NewPoint as IClone).Clone() as IPoint;
                     if (p.SpatialReference != (EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference)
                     {
                         p.Project((EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference);
                         p.SpatialReference = (EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference;
                     }
                     if (index == 0)
                     {
                         points.UpdatePoint(0, p);
                     }
                     else
                     {
                         points.ReplacePoints(index, 1, 1, ref p);
                     }
                 }
                 shapeCopy.RemoveGeometries(args.PartIndex, 1);
                 before = args.PartIndex;
                 shapeCopy.AddGeometry(points as IGeometry, ref before, ref missing);
                 IGeometry geometry = (IGeometry)shapeCopy;
                 feature.Shape = geometry;
                 feature.Store();
             }
         }
         Editor.UniqueInstance.StopEditOperation("Linkage Edit");
     }
     catch (Exception exception)
     {
         Editor.UniqueInstance.AbortEditOperation();
         this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.LinkageEdit", "SaveEdit", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
     }
 }
Exemplo n.º 5
0
        private void btnSaveClass_Click(object sender, EventArgs e)
        {
            if (cbClassName.Text == "")
            {
                MessageBox.Show("请输入类别名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (txtSampleCount.Text == "")
            {
                MessageBox.Show("没有需要保存的样本!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (bNewClassOrNot)
            {
                ListViewItem pListViewItem = new ListViewItem(this.txtClassID.Text);
                pListViewItem.SubItems.Add(this.cbClassName.Text);
                pListViewItem.SubItems.Add(this.txtSampleCount.Text);
                pListViewItem.SubItems.Add(SetColorByIndex(this.listView1.Items.Count + 1).Name);
                for (int i = 0; i < pGeometryCollection.GeometryCount; i++)
                {
                    pointCollection = pGeometryCollection.get_Geometry(i) as IPointCollection;
                    for (int j = 0; j < pointCollection.PointCount; j++)
                    {
                        xCoordinate += pointCollection.get_Point(j).X.ToString() + ",";
                        yCoordinate += pointCollection.get_Point(j).Y.ToString() + ",";
                    }
                    xCoordinate = xCoordinate.Substring(0, xCoordinate.Length - 1);
                    yCoordinate = yCoordinate.Substring(0, yCoordinate.Length - 1);
                    xCoordinate = xCoordinate + "*";
                    yCoordinate = yCoordinate + "*";
                }
                xCoordinate = xCoordinate.Substring(0, xCoordinate.Length - 1);
                yCoordinate = yCoordinate.Substring(0, yCoordinate.Length - 1);

                pListViewItem.SubItems.Add(xCoordinate + ":" + yCoordinate);
                pListViewItem.BackColor = SetColorByIndex(this.listView1.Items.Count + 1);
                this.listView1.Items.Add(pListViewItem);

                pointCollection.RemovePoints(0, pointCollection.PointCount);
                pGeometryCollection.RemoveGeometries(0, pGeometryCollection.GeometryCount);
                xCoordinate = "";
                yCoordinate = "";
            }
            this.bNewClassOrNot       = false;
            this.tsbEndCreate.Enabled = false;
            this.bCreateOrNot         = false;
            this.btnSaveClass.Enabled = false;
        }
Exemplo n.º 6
0
 public void OnMouseUp(int button, int shift, int x, int y)
 {
     if (button != 2)
     {
         try
         {
             IGeometry editShape       = Editor.UniqueInstance.EditShape;
             IPoint    queryPoint      = this._hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
             IHitTest  test            = editShape as IHitTest;
             IPoint    hitPoint        = new PointClass();
             double    hitDistance     = 0.0;
             int       hitPartIndex    = 0;
             int       hitSegmentIndex = 0;
             bool      bRightSide      = false;
             double    searchRadius    = 1.0 * this._hookHelper.ActiveView.FocusMap.MapScale;
             esriGeometryHitPartType esriGeometryPartBoundary = esriGeometryHitPartType.esriGeometryPartBoundary;
             test.HitTest(queryPoint, searchRadius, esriGeometryPartBoundary, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
             if (!hitPoint.IsEmpty)
             {
                 IEngineSketchOperation operation = new EngineSketchOperationClass();
                 operation.Start(Editor.UniqueInstance.EngineEditor);
                 IGeometryCollection geometrys = editShape as IGeometryCollection;
                 IPointCollection    points    = geometrys.get_Geometry(hitPartIndex) as IPointCollection;
                 object missing = Type.Missing;
                 object after   = new object();
                 after = hitSegmentIndex;
                 object before = new object();
                 before = hitPartIndex;
                 points.AddPoint(queryPoint, ref missing, ref after);
                 operation.SetMenuString("Insert Vertex");
                 esriEngineSketchOperationType esriEngineSketchOperationVertexAdded = esriEngineSketchOperationType.esriEngineSketchOperationVertexAdded;
                 geometrys.RemoveGeometries(hitPartIndex, 1);
                 geometrys.AddGeometry(points as IGeometry, ref before, ref missing);
                 operation.Finish(null, esriEngineSketchOperationVertexAdded, queryPoint);
                 Editor.UniqueInstance.FinishSketch();
                 this.OnClick();
             }
         }
         catch (Exception exception)
         {
             Editor.UniqueInstance.AbortEditOperation();
             this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.InsertVertex", "OnMouseUp", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         }
     }
 }
Exemplo n.º 7
0
 private void DeletePoint()
 {
     try
     {
         DataRow focusedDataRow = this.gridView1.GetFocusedDataRow();
         if (focusedDataRow != null)
         {
             int i             = Convert.ToInt32(focusedDataRow[0]);
             int selectedIndex = this.listPart.SelectedIndex;
             if (selectedIndex >= 0)
             {
                 IGeometryCollection geometry = this.m_Geometry as IGeometryCollection;
                 IPointCollection    points   = geometry.get_Geometry(selectedIndex) as IPointCollection;
                 IPoint data = points.get_Point(i);
                 points.RemovePoints(i, 1);
                 IEngineSketchOperation operation = new EngineSketchOperationClass();
                 operation.Start(Editor.UniqueInstance.EngineEditor);
                 operation.SetMenuString("Delete Vertex");
                 esriEngineSketchOperationType esriEngineSketchOperationVertexDeleted = esriEngineSketchOperationType.esriEngineSketchOperationVertexDeleted;
                 object missing = System.Type.Missing;
                 object before  = new object();
                 before = selectedIndex;
                 geometry.RemoveGeometries(selectedIndex, 1);
                 geometry.AddGeometry(points as IGeometry, ref before, ref missing);
                 operation.Finish(null, esriEngineSketchOperationVertexDeleted, data);
                 Editor.UniqueInstance.FinishSketch();
                 IEngineEditTask taskByUniqueName = Editor.UniqueInstance.EngineEditor.GetTaskByUniqueName("ControlToolsEditing_ModifyFeatureTask");
                 Editor.UniqueInstance.EngineEditor.CurrentTask = taskByUniqueName;
                 int index = this.listPart.SelectedIndex;
                 if (index >= 0)
                 {
                     this.ShowPointList(index);
                 }
             }
         }
     }
     catch
     {
     }
 }
Exemplo n.º 8
0
        private void StartAnalysis(IFeature feature)
        {
            if (feature.FeatureType != esriFeatureType.esriFTSimpleJunction)
            {
                MessageService.Current.Warn("请选择管线点");
                return;
            }
            if (!_pipelineConfig.IsPipelineLayer(feature.Class.AliasName, enumPipelineDataType.Point))
            {
                MessageService.Current.Warn("请选择管线点");
                return;
            }
            double snapDist = CommonUtils.ConvertPixelsToMapUnits(_context.ActiveView,
                                                                  _context.Config.SnapTolerance);
            IBasicLayerInfo lineConfig =
                _plugin.PipeConfig.GetBasicLayerInfo(feature.Class as IFeatureClass) as IBasicLayerInfo;

            if (this._startPoint == null && _startEid == 0)
            {
                //开始记录起始点
                IPipelineLayer oldLayer = _pipelineConfig.GetPipelineLayer(feature.Class.AliasName,
                                                                           enumPipelineDataType.Point);
                if (oldLayer == null)
                {
                    MessageService.Current.Warn("你选择的图层不是合法的管线图层!");
                    return;
                }
                List <IBasicLayerInfo> basicInfos = oldLayer.GetLayers(enumPipelineDataType.Junction);

                IFeatureClass featureClass = basicInfos.Count > 0 ? basicInfos[0].FeatureClass : null;
                if (featureClass == null)
                {
                    MessageService.Current.Warn("管线图层没有构建网络图层!");
                    return;
                }
                INetworkClass networkClass = featureClass as INetworkClass;
                _geometricNetwork = networkClass.GeometricNetwork;
                IPointToEID pnToEid = new PointToEIDClass();
                pnToEid.GeometricNetwork = _geometricNetwork;
                pnToEid.SnapTolerance    = snapDist;
                pnToEid.SourceMap        = _context.FocusMap;
                pnToEid.GetNearestJunction(feature.Shape as IPoint, out _startEid, out _startPoint);
                return;
            }
            IPipelineLayer newLayer = _pipelineConfig.GetPipelineLayer(feature.Class.AliasName,
                                                                       enumPipelineDataType.Point);

            if (newLayer == null)
            {
                MessageService.Current.Warn("你选择的图层不是合法的管线图层!");
                return;
            }
            List <IBasicLayerInfo> basicInfos1 = newLayer.GetLayers(enumPipelineDataType.Junction);

            IFeatureClass featureClass2 = basicInfos1.Count > 0 ? basicInfos1[0].FeatureClass : null;

            if (featureClass2 == null)
            {
                MessageService.Current.Warn("第二个管线图层没有构建网络图层!");
                return;
            }
            INetworkClass networkClass2 = featureClass2 as INetworkClass;

            if (networkClass2.GeometricNetwork != _geometricNetwork)
            {
                if (MessageService.Current.Ask("两个点位属于不同的网络图层,使用第二个网络图层作为分析图层吗?") == false)
                {
                    return;
                }
                _geometricNetwork = networkClass2.GeometricNetwork;
                IPointToEID pnToEid = new PointToEIDClass();
                pnToEid.GeometricNetwork = _geometricNetwork;
                pnToEid.SnapTolerance    = snapDist;
                pnToEid.SourceMap        = _context.FocusMap;
                pnToEid.GetNearestJunction(feature.Shape as IPoint, out _startEid, out _startPoint);
                return;
            }

            try
            {
                IPointToEID pntEid = new PointToEIDClass();
                pntEid.GeometricNetwork = _geometricNetwork;
                pntEid.SourceMap        = _context.FocusMap;
                pntEid.SnapTolerance    = snapDist;

                pntEid.GetNearestJunction(feature.Shape as IPoint, out _endEid, out _endPoint);
                if (_endEid < 1)
                {
                    MessageService.Current.Warn("未能找到第二个分析点!");
                    return;
                }
                if (_startEid == _endEid)
                {
                    MessageService.Current.Warn("起点终点为同一个点!");
                    return;
                }

                INetElements  netElements  = _geometricNetwork.Network as INetElements;
                INetworkClass networkClass = feature.Class as INetworkClass;

                IJunctionFlag[] array   = new JunctionFlag[2];
                INetFlag        netFlag = new JunctionFlag() as INetFlag;

                int userClassID;
                int userID;
                int userSubID;
                netElements.QueryIDs(_endEid, esriElementType.esriETJunction, out userClassID, out userID, out userSubID);
                netFlag.UserClassID = (userClassID);
                netFlag.UserID      = (userID);
                netFlag.UserSubID   = (userSubID);
                IJunctionFlag value = netFlag as IJunctionFlag;
                array.SetValue(value, 0);
                INetFlag netFlag2 = new JunctionFlag() as INetFlag;
                netElements.QueryIDs(_startEid, esriElementType.esriETJunction, out userClassID,
                                     out userID, out userSubID);
                netFlag2.UserClassID = (userClassID);
                netFlag2.UserID      = (userID);
                netFlag2.UserSubID   = (userSubID);
                value = (netFlag2 as IJunctionFlag);
                array.SetValue(value, 1);
                ITraceFlowSolverGEN traceFlowSolverGEN = new TraceFlowSolver() as ITraceFlowSolverGEN;
                INetSolver          netSolver          = traceFlowSolverGEN as INetSolver;
                netSolver.SourceNetwork = _geometricNetwork.Network;
                traceFlowSolverGEN.PutJunctionOrigins(ref array);
                object[]    array2 = new object[1];
                IEnumNetEID enumNetEID;
                IEnumNetEID enumNetEID2;
                traceFlowSolverGEN.FindPath((esriFlowMethod)2, (esriShortestPathObjFn)1, out enumNetEID,
                                            out enumNetEID2, 1, ref array2);
                if (this.ipolyline_0 == null)
                {
                    this.ipolyline_0 = new Polyline() as IPolyline;
                }
                IGeometryCollection geometryCollection = this.ipolyline_0 as IGeometryCollection;
                geometryCollection.RemoveGeometries(0, geometryCollection.GeometryCount);
                if (enumNetEID2.Count <= 0)
                {
                    this.ifeature_0 = null;
                    MessageBox.Show("两点之间不存在路径可以连通!");
                }
                else
                {
                    ShowShortObjectForm showShortObjectForm = new ShowShortObjectForm(_context);
                    showShortObjectForm.pApp = _context;
                    ISpatialReference spatialReference = _context.FocusMap.SpatialReference;
                    IEIDHelper        eIDHelperClass   = new EIDHelper();
                    eIDHelperClass.GeometricNetwork       = (networkClass.GeometricNetwork);
                    eIDHelperClass.OutputSpatialReference = (spatialReference);
                    eIDHelperClass.ReturnGeometries       = (true);
                    eIDHelperClass.ReturnFeatures         = (true);
                    IEnumEIDInfo enumEIDInfo = eIDHelperClass.CreateEnumEIDInfo(enumNetEID2);
                    int          count       = enumEIDInfo.Count;
                    enumEIDInfo.Reset();
                    for (int i = 0; i < count; i++)
                    {
                        IEIDInfo  iEIDInfo = enumEIDInfo.Next();
                        IGeometry geometry = iEIDInfo.Geometry;
                        if (i == 0)
                        {
                            showShortObjectForm.AddPipeName(this.string_0);
                        }
                        showShortObjectForm.AddFeature(iEIDInfo.Feature);
                        geometryCollection.AddGeometryCollection(geometry as IGeometryCollection);
                    }
                    showShortObjectForm.AddShortPath(this.ipolyline_0);
                    showShortObjectForm.AddLenght(this.ipolyline_0.Length);
                    this.ifeature_2 = feature;
                    EsriUtils.ZoomToGeometry(this.ipolyline_0, _context.MapControl.Map, 1.3);
                    FlashUtility.FlashGeometry(this.ipolyline_0, _context.MapControl);
                    this.ifeature_0   = null;
                    _startEid         = 0;
                    _startPoint       = null;
                    _geometricNetwork = null;
                    showShortObjectForm.Show();
                }
            }
            catch (Exception ex)
            {
                this.ifeature_0 = null;
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 9
0
 public void OnMouseDown(int button, int shift, int x, int y)
 {
     if (button == 1)
     {
         try
         {
             IGeometry           shapeCopy = this._las[0].feature.ShapeCopy;
             IGeometry           geometry2 = this._las[1].feature.ShapeCopy;
             IRelationalOperator @operator = shapeCopy as IRelationalOperator;
             IRelationalOperator operator2 = geometry2 as IRelationalOperator;
             IPoint queryPoint             = this._ac.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
             IPoint pGeometry = ((IClone)queryPoint).Clone() as IPoint;
             pGeometry = GISFunFactory.UnitFun.ConvertPoject(pGeometry, shapeCopy.SpatialReference) as IPoint;
             if (@operator.Contains(pGeometry) || operator2.Contains(pGeometry))
             {
                 IPoint   hitPoint        = null;
                 double   hitDistance     = 0.0;
                 int      hitPartIndex    = -1;
                 int      hitSegmentIndex = -1;
                 bool     bRightSide      = false;
                 double   searchRadius    = this._ac.ScreenDisplay.DisplayTransformation.FromPoints(ToolConfig.MouseTolerance);
                 IHitTest linageShape     = Editor.UniqueInstance.LinageShape as IHitTest;
                 if (linageShape.HitTest(queryPoint, searchRadius, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide))
                 {
                     IPointCollection points = Editor.UniqueInstance.LinageShape as IPointCollection;
                     if ((hitSegmentIndex != 0) && (hitSegmentIndex != (points.PointCount - 1)))
                     {
                         object missing = Type.Missing;
                         object before  = hitSegmentIndex;
                         IGeometryCollection geometrys = Editor.UniqueInstance.LinageShape as IGeometryCollection;
                         (geometrys.get_Geometry(hitPartIndex) as IPointCollection).RemovePoints(hitSegmentIndex, 1);
                         try
                         {
                             Editor.UniqueInstance.StartEditOperation();
                             foreach (LinkArgs args in this._las)
                             {
                                 (args.feature.Shape as IHitTest).HitTest(pGeometry, searchRadius, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
                                 IFeature            feature = args.feature;
                                 IGeometryCollection shape   = feature.Shape as IGeometryCollection;
                                 IPointCollection    points3 = shape.get_Geometry(hitPartIndex) as IPointCollection;
                                 before = hitSegmentIndex;
                                 points3.RemovePoints(hitSegmentIndex, 1);
                                 shape.RemoveGeometries(hitPartIndex, 1);
                                 before = hitPartIndex;
                                 shape.AddGeometry(points3 as IGeometry, ref before, ref missing);
                                 feature.Shape = shape as IGeometry;
                                 feature.Store();
                             }
                             Editor.UniqueInstance.StopEditOperation("Linkage Delete Vertex");
                         }
                         catch
                         {
                             Editor.UniqueInstance.AbortEditOperation();
                         }
                         this._ac.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, this._ac.Extent);
                     }
                 }
             }
         }
         catch (Exception exception)
         {
             this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.LinkageDeleteVertex", "OnMouseDown", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         }
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// The mouse up performs the action appropriate for each sub-typed command:
        /// insert vertex, add vertex or delete vertex
        /// </summary>
        /// <param name="Button"></param>
        /// <param name="Shift"></param>
        /// <param name="X">The X screen coordinate of the clicked location</param>
        /// <param name="Y">The Y screen coordinate of the clicked location</param>
        public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            try
            {
                IEngineEditSketch editSketch = m_engineEditor as IEngineEditSketch;
                IGeometry         editShape  = editSketch.Geometry;

                //location clicked as a point object
                IPoint clickedPt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

                #region local variables used in the HitTest

                IHitTest hitShape                   = editShape as IHitTest;
                IPoint   hitPoint                   = new PointClass();
                double   hitDistance                = 0;
                int      hitPartIndex               = 0;
                int      hitSegmentIndex            = 0;
                bool     bRightSide                 = false;
                esriGeometryHitPartType hitPartType = esriGeometryHitPartType.esriGeometryPartNone;

                //the searchRadius is the maximum distance away, in map units, from the shape that will be used
                //for the test - change to an appropriate value.
                double searchRadius = 1;
                switch (m_lSubType)
                {
                case 1:
                    hitPartType = esriGeometryHitPartType.esriGeometryPartBoundary;
                    break;

                case 2:
                    hitPartType = esriGeometryHitPartType.esriGeometryPartVertex;
                    break;
                }

                #endregion

                hitShape.HitTest(clickedPt, searchRadius, hitPartType, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);

                //check whether the HitTest was successful (i.e within the search radius)
                if (hitPoint.IsEmpty == false)
                {
                    IEngineSketchOperation sketchOp = new EngineSketchOperationClass();
                    sketchOp.Start(m_engineEditor);

                    //Get the PointCollection for a specific path or ring by hitPartIndex to handle multi-part features
                    IGeometryCollection geometryCol = editShape as IGeometryCollection;
                    IPointCollection    pathOrRingPointCollection = geometryCol.get_Geometry(hitPartIndex) as IPointCollection;

                    object missing = Type.Missing;
                    object hitSegmentIndexObject = new object();
                    hitSegmentIndexObject = hitSegmentIndex;
                    object partIndexObject = new object();
                    partIndexObject = hitPartIndex;
                    esriEngineSketchOperationType opType = esriEngineSketchOperationType.esriEngineSketchOperationGeneral;

                    switch (m_lSubType)
                    {
                    case 1:     //Insert Vertex

                        //add new vertex to the path or ring PointCollection
                        pathOrRingPointCollection.AddPoint(clickedPt, ref missing, ref hitSegmentIndexObject);
                        sketchOp.SetMenuString("Insert Vertex (Custom)");
                        opType = esriEngineSketchOperationType.esriEngineSketchOperationVertexAdded;
                        break;

                    case 2:     //Delete Vertex.

                        //delete a vertex from the path or ring PointCollection
                        pathOrRingPointCollection.RemovePoints(hitSegmentIndex, 1);
                        sketchOp.SetMenuString("Delete Vertex (Custom)");
                        opType = esriEngineSketchOperationType.esriEngineSketchOperationVertexDeleted;
                        break;
                    }

                    //remove the old PointCollection from the GeometryCollection and replace with the new one
                    geometryCol.RemoveGeometries(hitPartIndex, 1);
                    geometryCol.AddGeometry(pathOrRingPointCollection as IGeometry, ref partIndexObject, ref missing);

                    sketchOp.Finish(null, opType, clickedPt);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Unexpected Error");
            }
        }
Exemplo n.º 11
0
 public void OnMouseUp(int button, int shift, int x, int y)
 {
     if (button != 2)
     {
         IPoint    pPoint         = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
         IEnvelope searchEnvelope = FeatureFuncs.GetSearchEnvelope(this.m_hookHelper.ActiveView, pPoint);
         IFeature  feature        = FeatureFuncs.SearchFeatures(Editor.UniqueInstance.TargetLayer, searchEnvelope, esriSpatialRelEnum.esriSpatialRelIntersects).NextFeature();
         if (feature != null)
         {
             bool flag = false;
             Editor.UniqueInstance.StartEditOperation();
             IGeometryCollection shape   = feature.Shape as IGeometryCollection;
             int           geometryCount = shape.GeometryCount;
             List <string> list          = new List <string>();
             for (int i = 0; i < geometryCount; i++)
             {
                 flag = false;
                 list.Clear();
                 IGeometry geometry = shape.get_Geometry(i);
                 int       num3     = 0;
                 if ((geometry.GeometryType == esriGeometryType.esriGeometryPolygon) || (geometry.GeometryType == esriGeometryType.esriGeometryRing))
                 {
                     IRing ring = geometry as IRing;
                     if (ring.IsClosed)
                     {
                         num3 = 1;
                     }
                 }
                 IPointCollection points = geometry as IPointCollection;
                 int pointCount          = points.PointCount;
                 for (int j = num3; j < pointCount; j++)
                 {
                     IPoint point2 = points.get_Point(j);
                     string item   = string.Format("{0:F3},{1:F3}", point2.X, point2.Y);
                     if (list.Contains(item))
                     {
                         points.RemovePoints(j, 1);
                         j--;
                         pointCount--;
                         flag = true;
                     }
                     else
                     {
                         list.Add(item);
                     }
                 }
                 if (flag)
                 {
                     object missing = Type.Missing;
                     object before  = new object();
                     before = i;
                     shape.RemoveGeometries(i, 1);
                     shape.AddGeometry(points as IGeometry, ref before, ref missing);
                 }
             }
             feature.Shape = shape as IGeometry;
             feature.Store();
             Editor.UniqueInstance.StopEditOperation("delete repeat point");
             this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, this.m_hookHelper.ActiveView.Extent);
         }
     }
 }
Exemplo n.º 12
0
        private IGeometry method_1(IPolyline ipolyline_0, int int_0, int int_1, int int_2, int int_3)
        {
            IPointCollection geometry;
            int i;
            IGeometryCollection ipolyline0    = ipolyline_0 as IGeometryCollection;
            IGeometryCollection polylineClass = null;
            object value = Missing.Value;

            if (int_2 != int_0)
            {
                if (int_0 != ipolyline0.GeometryCount - 1)
                {
                    ipolyline0.RemoveGeometries(int_0 + 1, ipolyline0.GeometryCount - int_0 - 1);
                }
                if (int_2 != 0)
                {
                    ipolyline0.RemoveGeometries(0, int_2);
                }
                geometry = ipolyline0.Geometry[0] as IPointCollection;
                if (int_3 != 0)
                {
                    geometry.RemovePoints(0, int_3);
                }
                ipolyline0.GeometriesChanged();
                geometry = ipolyline0.Geometry[int_0 - int_2] as IPointCollection;
                if (int_1 != geometry.PointCount - 1)
                {
                    geometry.RemovePoints(int_1 + 1, geometry.PointCount - int_1 - 1);
                }
                ipolyline0.GeometriesChanged();
            }
            else
            {
                geometry = ipolyline0.Geometry[int_0] as IPointCollection;
                if (int_3 - int_1 + 1 != geometry.PointCount)
                {
                    polylineClass = new Polyline() as IGeometryCollection;
                    for (i = 0; i < int_0 - 1; i++)
                    {
                        polylineClass.AddGeometry((ipolyline0.Geometry[i] as IClone).Clone() as IGeometry, ref value,
                                                  ref value);
                    }
                    IPointCollection pathClass = new ESRI.ArcGIS.Geometry.Path();
                    for (i = int_1; i < int_3 + 1; i++)
                    {
                        pathClass.AddPoint(geometry.Point[i], ref value, ref value);
                    }
                    if (pathClass is IRing)
                    {
                        (pathClass as IRing).Close();
                    }
                    polylineClass.AddGeometry(pathClass as IGeometry, ref value, ref value);
                    for (i = int_0 + 1; i < ipolyline0.GeometryCount; i++)
                    {
                        polylineClass.AddGeometry((ipolyline0.Geometry[i] as IClone).Clone() as IGeometry, ref value,
                                                  ref value);
                    }
                }
                else
                {
                    ipolyline0.RemoveGeometries(int_0, 1);
                    polylineClass = ipolyline0;
                }
            }
            return(polylineClass as IGeometry);
        }