コード例 #1
0
        /// <summary>
        /// 将线要素切割
        /// </summary>
        /// <param name="pFeature">被切割的线要素</param>
        /// <param name="pPoint">切割点</param>
        /// <returns>切割后的线要素</returns>
        public static IFeature SplitPolyLine(IFeature pFeature, IPoint pPoint)
        {
            IGeometry pGeometry = pFeature.Shape;

            if (((IPolyline)pGeometry).FromPoint.X == pPoint.X && ((IPolyline)pGeometry).FromPoint.Y == pPoint.Y)
            {
                return(pFeature);
            }
            if (((IPolyline)pGeometry).ToPoint.X == pPoint.X && ((IPolyline)pGeometry).ToPoint.Y == pPoint.Y)
            {
                return(pFeature);
            }
            try
            {
                IWorkspaceEdit pEditor = GeoDbUtils.InitWorkspace() as IWorkspaceEdit;
                pEditor.StartEditOperation();
                IFeatureEdit pEditFeature = pFeature as IFeatureEdit;
                ISet         pSet         = pEditFeature.Split(pPoint);
                pSet.Reset();
                IFeature pRetFeature = pSet.Next() as IFeature;
                pGeometry = pRetFeature.Shape;
                if (((IPointCollection)(IPolyline)pGeometry).PointCount == 2)
                {
                    pRetFeature = pSet.Next() as IFeature;
                }

                pEditor.StopEditOperation();
                return(pRetFeature);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }
        }
コード例 #2
0
        //移动所有要素
        private void MoveAllFeature(ISet pALLMoveSet, IPoint pPtStart, IPoint pPtFinal, IWorkspaceEdit pCurWorkspaceEdit, IMap pMap)
        {
            pCurWorkspaceEdit.StartEditOperation();

            ILine pLine = new LineClass();

            pLine.PutCoords(pPtStart, pPtFinal);
            //将空间参考赋给移动的线
            pLine.SpatialReference = pMap.SpatialReference;

            pALLMoveSet.Reset();
            IFeatureEdit pFeatureEdit = pALLMoveSet.Next() as IFeatureEdit;

            while (pFeatureEdit != null)
            {
                pFeatureEdit.MoveSet(pALLMoveSet, pLine);
                pFeatureEdit = pALLMoveSet.Next() as IFeatureEdit;
            }

            pCurWorkspaceEdit.StopEditOperation();
        }
コード例 #3
0
ファイル: TrimLineTool.cs プロジェクト: zhongshuiyuan/gews
        /// <summary>
        /// 根据参考线要素,对选择的线要素进行裁剪
        /// </summary>
        /// <param name="featTrim">待裁剪的线要素</param>
        /// <param name="featRef">参考线要素</param>
        /// <returns>成功返回True</returns>
        public bool TrimLine(IFeature featTrim, IFeature featRef, IPoint pMousePnt)
        {
            IFeatureEdit pFeatEdit = null;

            ESRI.ArcGIS.esriSystem.ISet pSet = null;
            IFeature pFeature = null;

            try
            {
                //当没有交点的时候不做任何操作
                IPolyline        pTrimLine     = featTrim.ShapeCopy as IPolyline;
                IPointCollection pIntelsectCol = GetIntersection(featRef.ShapeCopy, pTrimLine);
                if (pIntelsectCol == null || pIntelsectCol.PointCount < 1)
                {
                    System.Windows.Forms.MessageBox.Show("参考线与要裁剪的线没有交点,无法完成裁剪!");
                    return(false);
                }
                if (pIntelsectCol.PointCount > 1)  //大于1个交点也不处理
                {
                    System.Windows.Forms.MessageBox.Show("参考线与要裁剪的线交点大于1个,无法完成裁剪!");
                    return(false);
                }
                IPoint pIntersectPt = pIntelsectCol.Point[0];     //裁剪线与参考线的交点

                pFeatEdit = featTrim as IFeatureEdit;

                pSet = pFeatEdit.Split(pIntersectPt);
                pSet.Reset();

                //pFeature = (IFeature)pSet.Next();
                //while (pFeature != null)
                //{
                //    IPolyline5 polylineTemp = pFeature.ShapeCopy as IPolyline5;
                //    IRelationalOperator relaOperator = pMousePnt as IRelationalOperator;
                //    if (relaOperator.Within(polylineTemp))//如果包含鼠标点,则删除
                //    {
                //        if (m_engineEditor != null)
                //        {
                //            m_engineEditor.StartOperation();
                //            pFeature.Delete();
                //            m_engineEditor.StopOperation("Delete Features");
                //        }
                //    }
                //    pFeature = (IFeature)pSet.Next();
                //}


                //ISegmentCollection trimSegCol = featTrim.ShapeCopy as ISegmentCollection;
                //ISegmentCollection refSegCol = featRef.ShapeCopy as ISegmentCollection;

                ////得到选中地物离点击处最近的segment
                //ISegment seg = null;
                //int indexSegment = GetSelectSegment(featTrim, pMousePnt, ref seg);
                //if (seg == null)
                //    return false;

                ////得到与segment相交的所有交点
                //ISegmentCollection pLineSegCol = new PolylineClass();
                //pLineSegCol.AddSegment(seg);

                //IPolyline pSegLine = pLineSegCol as IPolyline;



                //IPoint pLeftPnt = null;
                //IPoint pRightPnt = null;
                //GetColseIntersect(pIntelsectCol, pMousePnt, seg, out pLeftPnt, out pRightPnt);
                //if (pLeftPnt == null || pRightPnt == null)
                //    return false;

                //List<IFeature> lstFeats = null;

                //IFeature pNewFeatOne = null;
                //IFeature pNewFeatTwo = null;

                ////修剪在启始端
                //if (indexSegment == 0 && pLeftPnt.X == pLineSegCol.Segment[0].FromPoint.X && pLeftPnt.Y == pLineSegCol.Segment[0].FromPoint.Y)
                //{
                //    lstFeats = new List<IFeature>();

                //    pFeatEdit = featTrim as IFeatureEdit;
                //    pSet = pFeatEdit.Split(pRightPnt);
                //    pSet.Reset();

                //    pFeature = (IFeature)pSet.Next();
                //    while (pFeature != null)
                //    {
                //        lstFeats.Add(pFeature);
                //        pFeature = (IFeature)pSet.Next();
                //    }

                //    pFeature = GetCloseFeature(m_hookHelper.FocusMap, pMousePnt, lstFeats);

                //    m_engineEditor.StartOperation();
                //    pFeature.Delete();
                //    m_engineEditor.StopOperation("Delete Features");

                //    for (int j = 0; j < lstFeats.Count; j++)
                //    {
                //        if (!lstFeats[j].Equals(pFeature))
                //            pNewFeatOne = lstFeats[j];
                //    }
                //}
                ////修剪在末端
                //else if (indexSegment == pLineSegCol.SegmentCount - 1 && pRightPnt.X == pLineSegCol.Segment[pLineSegCol.SegmentCount - 1].ToPoint.X)
                //{
                //    lstFeats = new List<IFeature>();

                //    pFeatEdit = featTrim as IFeatureEdit;
                //    pSet = pFeatEdit.Split(pLeftPnt);
                //    pSet.Reset();

                //    pFeature = (IFeature)pSet.Next();
                //    while (pFeature != null)
                //    {
                //        lstFeats.Add(pFeature);
                //        pFeature = (IFeature)pSet.Next();
                //    }

                //    pFeature = GetCloseFeature(m_hookHelper.FocusMap, pMousePnt, lstFeats);

                //    m_engineEditor.StartOperation();
                //    pFeature.Delete();
                //    m_engineEditor.StopOperation("Delete Features");

                //    for (int j = 0; j < lstFeats.Count; j++)
                //    {
                //        if (!lstFeats[j].Equals(pFeature))
                //            pNewFeatOne = lstFeats[j];
                //    }
                //}
                //else   //修剪在其它位置
                //{
                //    lstFeats = new List<IFeature>();

                //    pFeatEdit = featTrim as IFeatureEdit;
                //    pSet = pFeatEdit.Split(pLeftPnt);
                //    pSet.Reset();

                //    pFeature = (IFeature)pSet.Next();
                //    while (pFeature != null)
                //    {
                //        lstFeats.Add(pFeature);
                //        pFeature = (IFeature)pSet.Next();
                //    }

                //    pFeature = GetCloseFeature(m_hookHelper.FocusMap, pMousePnt, lstFeats);
                //    for (int j = 0; j < lstFeats.Count; j++)
                //    {
                //        if (!lstFeats[j].Equals(pFeature))
                //            pNewFeatOne = lstFeats[j];
                //    }


                //    lstFeats = new List<IFeature>();

                //    pFeatEdit = pFeature as IFeatureEdit;
                //    pSet = pFeatEdit.Split(pRightPnt);
                //    pSet.Reset();

                //    pFeature = (IFeature)pSet.Next();
                //    while (pFeature != null)
                //    {
                //        lstFeats.Add(pFeature);
                //        pFeature = (IFeature)pSet.Next();
                //    }

                //    pFeature = GetCloseFeature(m_hookHelper.FocusMap, pMousePnt, lstFeats);

                //    m_engineEditor.StartOperation();
                //    pFeature.Delete();
                //    m_engineEditor.StopOperation("Delete Features");

                //    for (int j = 0; j < lstFeats.Count; j++)
                //    {
                //        if (!lstFeats[j].Equals(pFeature))
                //            pNewFeatTwo = lstFeats[j];
                //    }
                //}
                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Trim Line");
                return(false);
            }
        }
        public void OnFinishSketch()
        {
            if (m_editSketch == null)
            {
                return;
            }

            bool hasCutPolygons = false;

            //Change the cursor to be hourglass shape.
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

            try
            {
                //Get the geometry that performs the cut from the edit sketch.
                IGeometry cutGeometry = m_editSketch.Geometry;

                //The sketch geometry is simplified to deal with a multi-part sketch as well
                //as the case where the sketch loops back over itself.
                ITopologicalOperator2 topoOperator = cutGeometry as ITopologicalOperator2;
                topoOperator.IsKnownSimple_2 = false;
                topoOperator.Simplify();

                //Create the spatial filter to search for features in the target feature class.
                //The spatial relationship we care about is whether the interior of the line
                //intersects the interior of the polygon.
                ISpatialFilter spatialFilter = new SpatialFilterClass();
                spatialFilter.Geometry   = m_editSketch.Geometry;
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                //Find the polygon features that cross the sketch.
                IFeatureClass  featureClass  = m_editLayer.TargetLayer.FeatureClass;
                IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);

                //Only do work if there are features that intersect the edit sketch.
                IFeature origFeature = featureCursor.NextFeature();
                if (origFeature != null)
                {
                    //Check the first feature to see if it is ZAware and if it needs to make the
                    //cut geometry ZAware.
                    IZAware zAware = origFeature.Shape as IZAware;
                    if (zAware.ZAware)
                    {
                        zAware        = cutGeometry as IZAware;
                        zAware.ZAware = true;
                    }

                    ArrayList comErrors = new ArrayList();

                    //Start an edit operation so we can have undo/redo.
                    m_engineEditor.StartOperation();

                    //Cycle through the features, cutting with the sketch.
                    while (origFeature != null)
                    {
                        try
                        {
                            //Split the feature. Use the IFeatureEdit::Split method which ensures
                            //the attributes are correctly dealt with.
                            IFeatureEdit featureEdit = origFeature as IFeatureEdit;
                            //Set to hold the new features that are created by the Split.
                            ISet newFeaturesSet = featureEdit.Split(cutGeometry);

                            //New features have been created.
                            if (newFeaturesSet != null)
                            {
                                newFeaturesSet.Reset();
                                hasCutPolygons = true;
                            }
                        }
                        catch (COMException comExc)
                        {
                            comErrors.Add(String.Format("OID: {0}, Error: {1} , {2}", origFeature.OID.ToString(), comExc.ErrorCode, comExc.Message));
                        }
                        finally
                        {
                            //Continue to work on the next feature if it fails to split the current one.
                            origFeature = featureCursor.NextFeature();
                        }
                    }
                    //If any polygons were cut, refresh the display and stop the edit operation.
                    if (hasCutPolygons)
                    {
                        //Clear the map's selection.
                        m_engineEditor.Map.ClearSelection();

                        //Refresh the display including modified layer and any previously selected component.
                        IActiveView activeView = m_engineEditor.Map as IActiveView;
                        activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent);

                        //Complete the edit operation.
                        m_engineEditor.StopOperation("Cut Polygons Without Selection");
                    }
                    else
                    {
                        m_engineEditor.AbortOperation();
                    }

                    //report any errors that have arisen while splitting features
                    if (comErrors.Count > 0)
                    {
                        StringBuilder stringBuilder = new StringBuilder("The following features could not be split: \n", 200);
                        foreach (string comError in comErrors)
                        {
                            stringBuilder.AppendLine(comError);
                        }

                        MessageBox.Show(stringBuilder.ToString(), "Cut Errors");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Unable to perform the cut task.\n" + e.Message);
                m_engineEditor.AbortOperation();
            }
            finally
            {
                //Change the cursor shape to default.
                System.Windows.Forms.Cursor.Current = Cursors.Default;
            }
        }
コード例 #5
0
        void IEditTask.OnFinishSketch()
        {
            if (m_editSketch == null)
            {
                return;
            }

            bool HasCutPolygons = false;

            //Change the cursor to be hourglass shape.
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

            try
            {
                //Get the geometry that performs the cut from the edit sketch.
                IGeometry cutGeometry = m_editSketch.Geometry;

                //The sketch geometry is simplified to deal with a multi-part sketch as well
                //as the case where the sketch loops back over itself.
                ITopologicalOperator2 topoOperator = cutGeometry as ITopologicalOperator2;
                topoOperator.IsKnownSimple_2 = false;
                topoOperator.Simplify();

                //Get ready to invalidate the features.
                IInvalidArea refreshArea = new InvalidAreaClass();
                refreshArea.Add(cutGeometry.Envelope);

                //Create the spatial filter to search for features in the target feature class.
                //The spatial relationship we care about is whether the interior of the line
                //intesects the interior of the polygon.
                ISpatialFilter spatialFilter = new SpatialFilterClass();
                spatialFilter.Geometry   = m_editSketch.Geometry;
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                //Find the polygon features that cross the sketch.
                IFeatureClass  featureClass  = m_editLayer.CurrentLayer.FeatureClass;
                IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);

                //Only do work if there are features that intersect the edit sketch.
                IFeature origFeature = featureCursor.NextFeature();
                if (origFeature != null)
                {
                    //Check the first feature to see if it is ZAware and if it needs to make the
                    //cut geometry ZAware.
                    IZAware zAware = origFeature.Shape as IZAware;
                    if (zAware.ZAware)
                    {
                        zAware        = cutGeometry as IZAware;
                        zAware.ZAware = true;
                    }

                    //The result selection set will be the new features created. This means
                    //we need to add the currently selected features to the refresh area so
                    //they are correctly invalidated.
                    if (m_editor.SelectionCount > 0)
                    {
                        IEnumFeature selectedFeatures = m_editor.EditSelection;
                        selectedFeatures.Reset();
                        IFeature selectedFeature = selectedFeatures.Next();
                        while (selectedFeature != null)
                        {
                            refreshArea.Add(selectedFeature);
                            selectedFeature = selectedFeatures.Next();
                        }
                    }

                    //Initialize the selection set for the new features.
                    IFeatureSelection featureSelect = m_editLayer.CurrentLayer as IFeatureSelection;
                    featureSelect.Clear();
                    //Cache the new features created.
                    ISelectionSet selectionSet = featureSelect.SelectionSet;

                    //Start an edit operation so we can have undo/redo.
                    m_editor.StartOperation();

                    //Cycle through the features, cutting with the sketch.
                    while (origFeature != null)
                    {
                        try
                        {
                            //Add the feature to the invalidate object.
                            refreshArea.Add(origFeature);

                            //Split the feature. Use the IFeatureEdit::Split method which ensures
                            //the attributes are correctly dealt with.
                            IFeatureEdit featureEdit = origFeature as IFeatureEdit;
                            //Set to hold the new features that are created by the Split.
                            ISet newFeaturesSet = featureEdit.Split(cutGeometry);

                            //New features have been created, loop through the set and flash
                            //each feature and get it's OID for the final selection set.
                            if (newFeaturesSet != null)
                            {
                                newFeaturesSet.Reset();

                                //A list to hold the selected features' OIDs.
                                List <int> iOIDList = new List <int>();

                                for (int featureCount = 0; featureCount < newFeaturesSet.Count; featureCount++)
                                {
                                    HasCutPolygons = true;
                                    //Flash the new features.
                                    IFeature newFeature = newFeaturesSet.Next() as IFeature;
                                    FlashGeometry(newFeature.Shape, m_editor.Display);

                                    //Add the feature to the new selection set
                                    iOIDList.Add(newFeature.OID);
                                }
                                int[] iOIDArray = iOIDList.ToArray();

                                selectionSet.AddList(newFeaturesSet.Count, ref iOIDArray[0]);
                            }
                        }
                        catch (COMException)
                        {
                        }
                        finally
                        {
                            //Continue to work on the next feature if it fails to split the current one.
                            origFeature = featureCursor.NextFeature();
                        }
                    }
                    //If any polygons were cut, invalidate the display and stop the edit operation.
                    if (HasCutPolygons)
                    {
                        //Clear the map's selection.
                        m_mxDoc.FocusMap.ClearSelection();

                        //Select the new features.
                        featureSelect.SelectionSet = selectionSet;

                        //Refresh the display.
                        refreshArea.Display = m_editor.Display;
                        refreshArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);

                        //Complete the edit operation.
                        m_editor.StopOperation("Cut Polygons Without Selection");

                        //As we changed the selection set, the map has no idea we did this.
                        //Fire the event to inform others the selection has changed.
                        featureSelect.SelectionChanged();
                    }
                    else
                    {
                        m_editor.AbortOperation();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Unable to perform the cut task.\n" + e.ToString());
                //In the event of an error, abort the operation.
                m_editor.AbortOperation();
            }
            finally
            {
                //Change the cursor shape to default.
                System.Windows.Forms.Cursor.Current = Cursors.Default;
            }
        }
コード例 #6
0
        //分割要素
        private bool splitFeature(IGeometry pGeometry)
        {
            IFeatureLayer curLayer = getEditLayer.isExistLayer(m_MapControl.Map) as IFeatureLayer;

            if (curLayer == null)
            {
                return(false);
            }
            IFeatureSelection curLayerSn = curLayer as IFeatureSelection;
            bool hasCut = false;

            //空间查询,找出被切割要素
            ISpatialFilter spatialFilter = new SpatialFilterClass();

            spatialFilter.Geometry = pGeometry;
            if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
            {
                spatialFilter.SpatialRel            = esriSpatialRelEnum.esriSpatialRelRelation;
                spatialFilter.SpatialRelDescription = "TTTFFTTTT";
            }
            else if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
            {
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            }
            IFeatureClass  featureClass = curLayer.FeatureClass;
            IWorkspaceEdit iWE          = (featureClass as IDataset).Workspace as IWorkspaceEdit;

            if (!iWE.IsBeingEdited())
            {
                iWE.StartEditing(false);
            }
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
            try
            {
                IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
                IFeature       origFeature   = featureCursor.NextFeature();
                if (origFeature != null)
                {
                    //检查第一个要素是否Z敏感则将切割线设成Z敏感
                    IZAware zAware = origFeature.Shape as IZAware;
                    if (zAware.ZAware)
                    {
                        zAware        = pGeometry as IZAware;
                        zAware.ZAware = true;
                    }

                    ArrayList comErrors = new ArrayList();

                    //开始操作
                    iWE.StartEditOperation();

                    //循环空间查询的要素,执行切割
                    while (origFeature != null)
                    {
                        try
                        {
                            //切割要素,IFeatureEdit.Split此方法可自动处理属性
                            IFeatureEdit featureEdit    = origFeature as IFeatureEdit;
                            ISet         newFeaturesSet = null;
                            //保存切割生成的新要素的集合
                            //若源要素是线,则切割图形是交点
                            if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                            {
                                ITopologicalOperator iTo    = pGeometry as ITopologicalOperator;
                                IGeometry            pTmpG  = iTo.Intersect(origFeature.ShapeCopy, esriGeometryDimension.esriGeometry0Dimension);
                                IPointCollection     pTmpPc = pTmpG as IPointCollection;
                                for (int i = pTmpPc.PointCount - 1; i >= 0; i--)
                                {
                                    //newFeaturesSet = featureEdit.Split(pTmpG);
                                    newFeaturesSet = featureEdit.Split(pTmpPc.get_Point(pTmpPc.PointCount - 1));

                                    //新要素已经生成
                                    if (newFeaturesSet != null)
                                    {
                                        newFeaturesSet.Reset();
                                        IFeature pSplitFeature = null;
                                        pSplitFeature = newFeaturesSet.Next() as IFeature;
                                        //IFeatureEdit tmpFE = pSplitFeature as IFeatureEdit;
                                        while (pSplitFeature != null)
                                        {
                                            //闪烁新要素
                                            m_MapControl.FlashShape(pSplitFeature.ShapeCopy, 1, 300, Type.Missing);
                                            pSplitFeature = newFeaturesSet.Next() as IFeature;
                                        }
                                        hasCut = true;
                                    }
                                }
                            }
                            //如果是面,切割图形是线
                            else
                            {
                                newFeaturesSet = featureEdit.Split(pGeometry);

                                //新要素已经生成
                                if (newFeaturesSet != null)
                                {
                                    newFeaturesSet.Reset();
                                    IFeature pSplitFeature = null;
                                    pSplitFeature = newFeaturesSet.Next() as IFeature;
                                    while (pSplitFeature != null)
                                    {
                                        //闪烁新要素
                                        m_MapControl.FlashShape(pSplitFeature.ShapeCopy, 1, 300, Type.Missing);
                                        pSplitFeature = newFeaturesSet.Next() as IFeature;
                                    }
                                    hasCut = true;
                                }
                            }
                        }
                        catch (COMException comExc)
                        {
                            comErrors.Add(String.Format("OID: {0}, 错误: {1} , {2}", origFeature.OID.ToString(), comExc.ErrorCode, comExc.Message));
                        }
                        finally
                        {
                            //当前的失败,则继续下一个
                            origFeature = featureCursor.NextFeature();
                        }
                    }
                    //如果有切割动作,则刷新视图并保存
                    if (hasCut)
                    {
                        //清除地图选择集
                        m_MapControl.Map.ClearSelection();

                        //刷新视图

                        m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, m_MapControl.ActiveView.Extent);

                        //完成编辑操作
                        iWE.StopEditOperation();
                    }
                    else
                    {
                        iWE.AbortEditOperation();
                    }

                    //报告错误
                    if (comErrors.Count > 0)
                    {
                        StringBuilder stringBuilder = new StringBuilder("以下要素不能被切割: \n", 200);
                        foreach (string comError in comErrors)
                        {
                            stringBuilder.AppendLine(comError);
                        }

                        MessageBox.Show(stringBuilder.ToString(), "切割错误");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandle.ShowFrmErrorHandle("提示", "切割失败!\r\n" + ex.Message);
                iWE.AbortEditOperation();
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = Cursors.Default;
            }
            return(hasCut);
        }
コード例 #7
0
        // this method splits the centerline
        public void doCenterlineSplit(IFeature arcParentFeature, IPoint arcSplitPoint)
        {
            try
            {
                // set address field range fields
                string strLeftFromName  = "L_F_ADD";
                string strLeftToName    = "L_T_ADD";
                string strRightFromName = "R_F_ADD";
                string strRightToName   = "R_T_ADD";
                long   longLeftFromNum;
                long   longLeftToNum;
                long   longRightFromNum;
                long   longRightToNum;


                ICurve arcParentCurve = arcParentFeature.Shape as ICurve;

                // check if the curve is nothing
                if (arcParentCurve == null)
                {
                    MessageBox.Show("The selected polyline does not have a valid shape.", "Can Not Split", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // check if the curve is nothing
                if (arcParentCurve.IsEmpty == true)
                {
                    MessageBox.Show("The selected polyline has an empty geometry.", "Can Not Split", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // check if the curve is nothing
                if (arcParentCurve.Length == 0)
                {
                    MessageBox.Show("The selected polyline has a length of zero.", "Can Not Split", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


                // make sure the required fields which contain the house numbers have been specified
                IFields arcFields = arcParentFeature.Fields;
                longLeftFromNum  = arcFields.FindField(strLeftFromName);
                longLeftToNum    = arcFields.FindField(strLeftToName);
                longRightFromNum = arcFields.FindField(strRightFromName);
                longRightToNum   = arcFields.FindField(strRightToName);

                // check for Null values in the 4 house number fields (modGlobals has comments on g_pExtension)
                if (longLeftFromNum == null | longLeftToNum == null | longRightFromNum == null | longRightToNum == null)
                {
                    MessageBox.Show("One or more of the house numbers are Null for the selected line.", "Can Not Split", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // try to get a valid house number from each of the 4 house number fields.
                // this is especially important if the fields are Text, which is common for geocoding data.
                long lngFrom_Left_HouseNum  = TryToGetValidHouseNum(arcSelectedFeature.get_Value(arcSelectedFeature.Fields.FindField("L_F_ADD")).ToString().Trim());
                long lngFrom_Right_HouseNum = TryToGetValidHouseNum(arcSelectedFeature.get_Value(arcSelectedFeature.Fields.FindField("R_F_ADD")).ToString().Trim());
                long lngTo_Left_HouseNum    = TryToGetValidHouseNum(arcSelectedFeature.get_Value(arcSelectedFeature.Fields.FindField("L_T_ADD")).ToString().Trim());
                long lngTo_Right_HouseNum   = TryToGetValidHouseNum(arcSelectedFeature.get_Value(arcSelectedFeature.Fields.FindField("R_T_ADD")).ToString().Trim());

                if (lngFrom_Left_HouseNum == -1 | lngFrom_Right_HouseNum == -1 | lngTo_Left_HouseNum == -1 | lngTo_Right_HouseNum == -1)
                {
                    MessageBox.Show("One or more of the house numbers are invalid for the selected line.  Please see the attribute table and verify that address ranges are valid.", "Can Not Split", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                bool blnMixedParity = false;

                // check left address ranges //
                // both of these values should retrun as false (if only odd numbers are on left) - meaning the to and from range for that side of the road is odd
                bool blnLeftFromIsEven = isEven(lngFrom_Left_HouseNum);
                bool blnLeftToIsEven   = isEven(lngTo_Left_HouseNum);

                // check if side of the road is both even or both odd
                if (blnLeftToIsEven != blnLeftFromIsEven)
                {
                    MessageBox.Show("The left side of the selected line has both even and odd numbers.  Ensure the left ranges are both either odd or even.", "Mixed Parity", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


                // check right address ranges //
                // both ranges should be same
                bool blnRightFromIsEven   = isEven(lngFrom_Right_HouseNum);
                bool blnRightToIsEven     = isEven(lngTo_Right_HouseNum);
                bool blnRightSideZeros    = false;
                bool blnLeftSideZeros     = false;
                bool blnBothSidesAllZeros = false;

                // check if side of the road is both even or odd
                if (blnRightFromIsEven != blnRightToIsEven)
                {
                    MessageBox.Show("The right side of the selected line has both even and odd numbers.  Ensure the right ranges are both either odd or even.", "Mixed Parity", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // verify the 2 sides of the polyline have opposite parity (unless one side has 2 zeros)
                bool blnLeftIsEven = isEven(lngFrom_Left_HouseNum);
                bool blnOneSideHasZeros;

                // check if any of the range values are zero
                if ((lngFrom_Left_HouseNum == 0 & lngTo_Left_HouseNum == 0) | (lngFrom_Right_HouseNum == 0 & lngTo_Right_HouseNum == 0))
                {
                    blnOneSideHasZeros = true;
                }
                else
                {
                    blnOneSideHasZeros = false;
                }


                if (blnOneSideHasZeros == false)
                {
                    // check if both the right and left "from" ranges are of same parity
                    if (blnLeftFromIsEven == blnRightFromIsEven)
                    {
                        if (blnLeftFromIsEven == false)
                        {
                            MessageBox.Show("Both sides of the selected line begin with odd numbers.  Ensure one side of segment begins with an odd number and the other begins with an even number.", "Mixed Parity", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Both sides of the selected line begin with even numbers.  Ensure one side of segment begins with an odd number and the other begins with an even number.", "Mixed Parity", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    // check if both the right and left "to" ranges are of same parity
                    if (blnLeftToIsEven == blnRightToIsEven)
                    {
                        if (blnLeftToIsEven == false)
                        {
                            MessageBox.Show("Both sides of the selected line end with odd numbers.  Ensure one side of segment ends with an odd number and the other ends with an even number.", "Mixed Parity", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Both sides of the selected line end with even numbers.  Ensure one side of segment ends with an odd number and the other ends with an even number.", "Mixed Parity", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
                else if (blnOneSideHasZeros == true)
                {
                    // check what side has the zeros, and make sure the other side has values
                    //check left side for two zeros
                    if (lngFrom_Left_HouseNum == 0 & lngTo_Left_HouseNum == 0)
                    {
                        blnLeftSideZeros = true;
                    }
                    //check right side for two zeros
                    if (lngFrom_Right_HouseNum == 0 & lngTo_Right_HouseNum == 0)
                    {
                        blnRightSideZeros = true;
                    }

                    if (blnRightSideZeros & blnLeftSideZeros)
                    {
                        MessageBox.Show("Both sides of the selected line have zero range vales.  There must be valid numbers on at least one side of the road segment.", "Zero Address Ranges", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }


                // create the point that will be used to split the selected polyline //
                if (arcSplitPoint == null)
                {
                    MessageBox.Show("A valid split point could not be created. The split point (from user mouse-click) returned null.", "Can not Split", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (arcSplitPoint.IsEmpty == true)
                {
                    MessageBox.Show("A valid split point could not be created. The split point (from user mouse-click) returned IsEmpty.", "Can not Split", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


                // split the parent feature into 2 offspring features. we use IFeatureEdit::Split since
                // it respects geodatabase behaviour (subtypes, domains, split policies etc). it also maintains
                // M and Z values, and works for geometric networks and topological ArcInfo coverages
                IFeatureEdit arcFeatureEdit = arcParentFeature as IFeatureEdit;
                ESRI.ArcGIS.esriSystem.ISet arcNewSet;

                // start an edit operation
                clsGlobals.arcEditor.StartOperation();

                // split the segment
                arcNewSet = arcFeatureEdit.Split(arcSplitPoint);

                // make sure the segment was split into 2 segments
                if (arcNewSet.Count != 2)
                {
                    MessageBox.Show("The selected line was not split into two segments -- unknown error.  Please check selected segment and try process again.", "Can not Split", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    clsGlobals.arcEditor.AbortOperation();
                    return;
                }


                // we now need to modify the house numbers of the 2 offspring polylines. before doing this,
                // we must be sure pNewFeature1 is the offspring line that contains the parent's from vertex,
                // or our logic will not work. Since ISet::Next does not return the features in any particular
                // order, we must test and switch if needed.
                IFeature arcNewFeature1 = arcNewSet.Next() as IFeature;  // will be wrong 50% of the time
                IFeature arcNewFeature2;
                ICurve   arcNewFeatCurve1 = arcNewFeature1.Shape as ICurve;
                ICurve   arcNewFeatCurve2;

                // get the from points from each curve
                IPoint arcParentFromPnt      = arcParentCurve.FromPoint;
                IPoint arcNewFeature1FromPnt = arcNewFeatCurve1.FromPoint;

                // set up relational operator to check if points are equal
                IRelationalOperator arcRelationalOperator = arcParentFromPnt as IRelationalOperator;
                if (arcRelationalOperator.Equals(arcNewFeature1FromPnt) == true)
                {
                    // no need to switch... just set the from point for the 2nd segment (the other split segment)
                    arcNewFeature2   = arcNewSet.Next() as IFeature;
                    arcNewFeatCurve2 = arcNewFeature2.Shape as ICurve;
                }
                else // will happen 50% of the time, need to switch features
                {
                    arcNewFeature2   = arcNewFeature1;
                    arcNewFeatCurve2 = arcNewFeature2.Shape as ICurve;
                    arcNewFeature1   = arcNewSet.Next() as IFeature;
                    arcNewFeatCurve1 = arcNewFeature1.Shape as ICurve;
                }


                // get the distance along the curve (as a ratio) where the split point falls. we will need
                // this soon for the interpolation of house numbers.
                double dblDistAlongCurve = arcNewFeatCurve1.Length / (arcNewFeatCurve1.Length + arcNewFeatCurve2.Length);

                // fix the 4 house numbers that are not correct (main part of code). the other 4 numbers are
                // already correct (the FROM_LEFT and FROM_RIGHT of the first feature, and the TO_LEFT and TO_RIGHT of the second feature).
                long lngLeftNum;
                long lngRightNum;
                if (blnLeftSideZeros)
                {
                    lngLeftNum = 0;
                }
                else
                {
                    lngLeftNum = getInterpolatedHouseNumber(lngFrom_Left_HouseNum, lngTo_Left_HouseNum, dblDistAlongCurve);
                }
                if (blnRightSideZeros)
                {
                    lngRightNum = 0;
                }
                else
                {
                    lngRightNum = getInterpolatedHouseNumber(lngFrom_Right_HouseNum, lngTo_Right_HouseNum, dblDistAlongCurve);
                }



                // the following 10 lines set the TO_LEFT and TO_RIGHT numbers of the first feature //
                if (isNumeric_ACSName | isNumeric_StName) // there was an intersecting road with a numberic street name
                {
                    // use the numeric street name to populate the address ranges
                    if (isNumeric_StName) // use numeric values from street name
                    {
                        // check if intersecting numeric street name is even or odd
                        bool blnIsEven_NumericStName = isEven(Convert.ToInt64(intStreetName)); // convert b/c method is expecting long

                        if (blnIsEven_NumericStName)                                           // intersecting street is even
                        {
                            if (blnLeftSideZeros)
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), intStreetName - 1);
                            }
                            if (blnRightSideZeros)
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), intStreetName - 2);
                            }
                        }
                        else // intersecting street is odd
                        {
                            if (blnLeftSideZeros)
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), intStreetName - 2);
                            }
                            if (blnRightSideZeros)
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), intStreetName - 1);
                            }
                        }
                    }
                    else // use numeric values from acs alias field
                    {
                        // check if value is even or odd
                        bool blnIsEvenAcsName = isEven(Convert.ToInt64(intACSName));

                        if (blnIsEvenAcsName) // intersecting street is even
                        {
                            if (blnLeftSideZeros)
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), intACSName - 1);
                            }
                            if (blnRightSideZeros)
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), intACSName - 2);
                            }
                        }
                        else // intersecting street is odd
                        {
                            if (blnLeftSideZeros)
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), intACSName - 2);
                            }
                            if (blnRightSideZeros)
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), intACSName - 1);
                            }
                        }
                    }
                }
                else // there was not an intersecting road with a numberic street name
                {
                    if (lngFrom_Left_HouseNum == lngTo_Left_HouseNum) // if parent had no range of house numbers
                    {
                        arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), lngFrom_Left_HouseNum);
                    }
                    else
                    {
                        arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("L_T_ADD"), lngLeftNum);
                    }
                    if (lngFrom_Right_HouseNum == lngTo_Right_HouseNum)
                    {
                        arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), lngFrom_Right_HouseNum);
                    }
                    else
                    {
                        arcNewFeature1.set_Value(arcNewFeature1.Fields.FindField("R_T_ADD"), lngRightNum);
                    }
                }

                //store feature1
                arcNewFeature1.Store();

                //get field values for address ranges
                long lngFeat1_L_T_ADD = Convert.ToInt64(arcNewFeature1.get_Value(arcNewFeature1.Fields.FindField("L_T_ADD")));
                long lngFeat1_R_T_ADD = Convert.ToInt64(arcNewFeature1.get_Value(arcNewFeature1.Fields.FindField("R_T_ADD")));

                // the following lines set the FROM_LEFT and FROM_RIGHT numbers of the second feature
                // set the left_from
                if (isNumeric_ACSName | isNumeric_StName) // there was an intersecting road with a numberic street name
                {
                    // use the numeric street name to populate the address ranges
                    if (isNumeric_StName) // use numeric values from street name
                    {
                        // check if intersecting numeric street name is even or odd
                        bool blnIsEven_NumericStName = isEven(Convert.ToInt64(intStreetName)); // convert b/c method is expecting long

                        if (blnIsEven_NumericStName)                                           // intersecting street is even
                        {
                            if (blnLeftSideZeros)
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), intStreetName + 1);
                            }
                            if (blnRightSideZeros)
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), intStreetName);
                            }
                        }
                        else // intersecting street is odd
                        {
                            if (blnLeftSideZeros)
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), intStreetName);
                            }
                            if (blnRightSideZeros)
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), intStreetName + 1);
                            }
                        }
                    }
                    else  // use numeric values from acs alias field
                    {
                        // check if value is even or odd
                        bool blnIsEvenAcsName = isEven(Convert.ToInt64(intACSName));

                        if (blnIsEvenAcsName) // intersecting street is even
                        {
                            if (blnLeftSideZeros)
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), intACSName + 1);
                            }
                            if (blnRightSideZeros)
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), intACSName);
                            }
                        }
                        else // intersecting street is odd
                        {
                            if (blnLeftSideZeros)
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), intACSName);
                            }
                            if (blnRightSideZeros)
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), 0);
                            }
                            else
                            {
                                arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), intACSName + 1);
                            }
                        }
                    }
                }
                else // there was not an intersecting road with a numberic street name
                {
                    if (lngFrom_Left_HouseNum < lngTo_Left_HouseNum)
                    {
                        //long intLTADD = Convert.ToInt64(arcNewFeature1.get_Value(arcNewFeature1.Fields.FindField("L_T_ADD")));
                        //arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), arcNewFeature1.get_Value(arcNewFeature1.Fields.FindField("L_T_ADD") + 2));
                        if (blnLeftSideZeros)
                        {
                            arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), 0);
                        }
                        else
                        {
                            arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), lngFeat1_L_T_ADD + 2);
                        }
                    }
                    else if (lngFrom_Left_HouseNum == lngTo_Left_HouseNum) // if parent had no range of house numbers
                    {
                        arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), lngFrom_Left_HouseNum);
                    }
                    else // if house numbers run opposite to the polyline's digitized direction
                    {
                        if (blnLeftSideZeros)
                        {
                            arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), 0);
                        }
                        else
                        {
                            arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("L_F_ADD"), lngFeat1_L_T_ADD - 2);
                        }
                    }

                    // set the right_from for the feature 2
                    if (lngFrom_Right_HouseNum < lngTo_Right_HouseNum)
                    {
                        if (blnRightSideZeros)
                        {
                            arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), 0);
                        }
                        else
                        {
                            arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), lngFeat1_R_T_ADD + 2);
                        }
                    }
                    else if (lngFrom_Right_HouseNum == lngTo_Right_HouseNum)
                    {
                        arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), lngFrom_Right_HouseNum);
                    }
                    else // if house numbers run opposite to the polyline's digitized direction
                    {
                        if (blnRightSideZeros)
                        {
                            arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), 0);
                        }
                        else
                        {
                            arcNewFeature2.set_Value(arcNewFeature2.Fields.FindField("R_F_ADD"), lngFeat1_R_T_ADD - 2);
                        }
                    }
                }

                // store the features
                //arcNewFeature1.Store();
                arcNewFeature2.Store();

                // stop the edit operation
                clsGlobals.arcEditor.StopOperation("AGRC Split Line");
            }
            catch (Exception ex)
            {
                // abort the operation if there's an error
                clsGlobals.arcEditor.AbortOperation();


                MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                "Error Location:" + Environment.NewLine + ex.StackTrace,
                                "UTRANS Editor tool error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return;
            }
        }
コード例 #8
0
ファイル: ToolSplitLine.cs プロジェクト: eglrp/TESTPROJECT-1
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            try
            {
                pt = ((m_hookHelper.ActiveView.ScreenDisplay).DisplayTransformation).ToMapPoint(X, Y);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            bool ddd = snapEnvironment.SnapPoint(pt);

            if (pMPfeedback != null)
            {
                pMPfeedback.Stop();
            }
            pMPfeedback = null;

            bool hasCut         = false;
            ISet newFeaturesSet = null;

            try
            {
                IFeatureSelection featureSelection = m_editLayer.TargetLayer as IFeatureSelection;
                ISelectionSet     selectionSet     = featureSelection.SelectionSet;
                IEnumIDs          enumIDs          = selectionSet.IDs;
                int iD = enumIDs.Next();
                while (iD != -1) //-1 is reutned after the last valid ID has been reached
                {
                    m_engineEditor.StartOperation();
                    IFeatureClass featureClass = m_editLayer.TargetLayer.FeatureClass;
                    IFeature      feature      = featureClass.GetFeature(iD);
                    // 判断点是否在线上,不是则跳过
                    ITopologicalOperator pto       = feature.Shape as ITopologicalOperator;
                    IGeometry            pgeometry = pto.Intersect(pt, esriGeometryDimension.esriGeometry0Dimension);
                    if (pgeometry.IsEmpty == true)
                    {
                        iD = enumIDs.Next();
                        continue;
                    }
                    IFeatureEdit featureedit = feature as IFeatureEdit;
                    /*ISet*/
                    newFeaturesSet = featureedit.Split(pgeometry);
                    if (newFeaturesSet != null)
                    {
                        newFeaturesSet.Reset();
                        hasCut = true;
                        break;
                    }
                    iD = enumIDs.Next();
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (hasCut)
            {
                //如果操作成功,选中切割的两条线
                //IFeatureSelection featureSelection = m_editLayer.TargetLayer as IFeatureSelection;
                //ISelectionSet selectionSet = featureSelection.SelectionSet;
                //for (int i = 0; i < newFeaturesSet.Count; i++)
                //{
                //    selectionSet.Add(((IFeature)newFeaturesSet.Next()).OID);
                //}
                //selectionSet.Refresh();

                //Refresh the display including modified layer and any previously selected component.
                IActiveView activeView = m_engineEditor.Map as IActiveView;
                activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent);
                activeView.Refresh();
                //Complete the edit operation.
                m_engineEditor.StopOperation("Split a line");
                // 将当前工具设置为选择工具
                IToolbarControl toolbarctl = m_hookHelper.Hook as IToolbarControl;
                //ICommand com = new ControlsEditingEditToolClass();
                //com.OnCreate(m_mapControl.Object);
                //this.m_mapControl.CurrentTool = com as ITool;
                for (int i = 0; i < toolbarctl.Count; i++)
                {
                    IToolbarItem tbi = toolbarctl.GetItem(i);
                    if (tbi.Command != null && tbi.Command.Name.Equals("ControlToolsEditing_Edit"))
                    {
                        tbi.Command.OnClick();// = true;
                        toolbarctl.CurrentTool = tbi.Command as ITool;
                        IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy;
                        break;
                    }
                }
                //  操作成功后将当前工具置为以前的工具
                //IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy;
                //toolbarbuddy.CurrentTool = oldtool;
                //((IToolbarControl)m_hookHelper.Hook).SetBuddyControl(toolbarbuddy);
                this.Deactivate();
            }
            else
            {
                m_engineEditor.AbortOperation();
                MessageBox.Show("切割点不在线上,未能成功切割选择的线段");
                //重新开始选点
                this.OnClick();
            }
            base.OnMouseDown(Button, Shift, X, Y);
        }
コード例 #9
0
        //合并要素
        private void UnionFeatures(IEnumFeature selectedFeatures, IFeature pMergeFeature)
        {
            try
            {
                IFeature feature = null;
                object   missing = Type.Missing;
                selectedFeatures.Reset();
                feature = selectedFeatures.Next();
                if (feature == null)
                {
                    return;
                }
                IFeatureClass featureClass = feature.Class as IFeatureClass;
                switch (featureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolyline:
                case esriGeometryType.esriGeometryPolygon:
                    break;

                default:
                    MessageBox.Show("请选择线或者面要素", "提示");
                    return;
                }
                IGeometryCollection geometries    = new GeometryBagClass();
                IDataset            dataset       = featureClass as IDataset;
                IWorkspaceEdit      workspaceEdit = dataset.Workspace as IWorkspaceEdit;
                while (feature != null)
                {
                    if (!feature.ShapeCopy.IsEmpty)
                    {
                        IGeometry           pGeometry           = feature.ShapeCopy;
                        IGeometryCollection pGeometryCollection = pGeometry as IGeometryCollection;
                        int geomCount = pGeometryCollection.GeometryCount;
                        if (geomCount > 1)
                        {
                            for (int k = 0; k < geomCount; k++)
                            {
                                IFeature     newFeature  = (feature.Class as IFeatureClass).CreateFeature();
                                IFeatureEdit featureEdit = feature as IFeatureEdit;
                                featureEdit.SplitAttributes(newFeature);
                                IGeometry newGeom = pGeometryCollection.Geometry[k];
                                if (feature.ShapeCopy.GeometryType == esriGeometryType.esriGeometryPolygon)
                                {
                                    IGeometryCollection polyGonC = new PolygonClass();
                                    polyGonC.AddGeometry(newGeom as IGeometry);
                                    IGeometry pGeoNew2 = polyGonC as IGeometry;
                                    pGeoNew2.SpatialReference = feature.ShapeCopy.SpatialReference;
                                    int          index        = feature.Fields.FindField("Shape");
                                    IGeometryDef pGeometryDef = pGeometryDef = feature.Fields.get_Field(index).GeometryDef as IGeometryDef;
                                    if (pGeometryDef.HasZ)
                                    {
                                        IZAware pZAware = (IZAware)pGeoNew2;
                                        pZAware.ZAware = true;
                                        IZ iz1 = (IZ)pGeoNew2;
                                        iz1.SetConstantZ(0);   //将Z值设置为0
                                    }
                                    else
                                    {
                                        IZAware pZAware = (IZAware)pGeoNew2;
                                        pZAware.ZAware = false;
                                    }
                                    if (pGeometryDef.HasM)
                                    {
                                        IMAware pMAware = (IMAware)pGeoNew2;
                                        pMAware.MAware = true;
                                    }
                                    else
                                    {
                                        IMAware pMAware = (IMAware)pGeoNew2;
                                        pMAware.MAware = false;
                                    }
                                    newFeature.Shape = pGeoNew2;
                                }
                                if (feature.ShapeCopy.GeometryType == esriGeometryType.esriGeometryPolyline)
                                {
                                    IGeometryCollection polyGonC = new PolylineClass();
                                    polyGonC.AddGeometry(newGeom as IGeometry);
                                    IGeometry pGeoNew2 = polyGonC as IGeometry;
                                    pGeoNew2.SpatialReference = feature.ShapeCopy.SpatialReference;
                                    int          index        = feature.Fields.FindField("Shape");
                                    IGeometryDef pGeometryDef = pGeometryDef = feature.Fields.get_Field(index).GeometryDef as IGeometryDef;
                                    if (pGeometryDef.HasZ)
                                    {
                                        IZAware pZAware = (IZAware)pGeoNew2;
                                        pZAware.ZAware = true;
                                        IZ iz1 = (IZ)pGeoNew2;
                                        iz1.SetConstantZ(0);   //将Z值设置为0
                                    }
                                    else
                                    {
                                        IZAware pZAware = (IZAware)pGeoNew2;
                                        pZAware.ZAware = false;
                                    }
                                    if (pGeometryDef.HasM)
                                    {
                                        IMAware pMAware = (IMAware)pGeoNew2;
                                        pMAware.MAware = true;
                                    }
                                    else
                                    {
                                        IMAware pMAware = (IMAware)pGeoNew2;
                                        pMAware.MAware = false;
                                    }
                                    newFeature.Shape = pGeoNew2;
                                }
                                newFeature.Store();
                            }
                            feature.Delete();
                        }
                    }
                    feature = selectedFeatures.Next();
                }
                workspaceEdit.StopEditOperation();
                selectedFeatures.Reset();
                //如果没有IWorkspaceEdit则无法进行撤销重做操作
            }
            catch (Exception ex)
            {
                //SysLogHelper.WriteOperationLog("要素合并错误", ex.Source, "数据编辑");
                MessageBox.Show(ex.Message);
            }
        }
コード例 #10
0
        private void CutSelectedPolygon()
        {
            if (m_selectedFeature == null)
            {
                MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                m_toolPhase = ToolPhase.SelectFeature;
                return;
            }

            //在屏幕上绘制用于分割的线要素
            IScreenDisplay    screenDisplay = m_activeView.ScreenDisplay;
            ISimpleLineSymbol sym           = new SimpleLineSymbolClass();
            IRgbColor         color         = new RgbColorClass();

            color.Red   = 255;
            color.Green = 128;
            color.Blue  = 128;
            sym.Color   = color;
            sym.Style   = esriSimpleLineStyle.esriSLSSolid;
            sym.Width   = 2;
            IRubberBand cutBand     = new RubberLineClass();
            IGeometry   cutGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol);

            screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            screenDisplay.SetSymbol(sym as ISymbol);
            screenDisplay.DrawPolyline(cutGeometry);
            screenDisplay.FinishDrawing();

            IFeatureClass  featureClass  = m_selectedFeature.Class as IFeatureClass;
            IDataset       dataset       = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }

            //分割选择的面要素
            if (cutGeometry.IsEmpty == true)
            {
                return;
            }
            try
            {
                workspaceEdit.StartEditOperation();
                IFeatureEdit featureEdit = m_selectedFeature as IFeatureEdit;
                //分割产生新的面要素
                ISet newFeaturesSet = featureEdit.Split(cutGeometry);
                //亮闪新要素
                if (newFeaturesSet != null)
                {
                    newFeaturesSet.Reset();
                    for (int featureCount = 0; featureCount < newFeaturesSet.Count; featureCount++)
                    {
                        IFeature newFeature = newFeaturesSet.Next() as IFeature;
                        FlashGeometry(newFeature.Shape, 3, 20);
                    }
                }
                workspaceEdit.StopEditOperation();
            }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                //SysLogHelper.WriteOperationLog("要素分割错误", ex.Source, "数据编辑");
                MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
            m_toolPhase = ToolPhase.SelectFeature;
        }