zoukankan      html  css  js  c++  java
  • C# ArcGIS Engine 线打断

    /// <summary>
            /// 打断线,用于在点击点处,打断该条线
            /// </summary>
            /// <param name="t_pLineFeatureClass">线图层</param>
            /// <param name="t_pPoint">点击的点</param>
            public static void SplitePolylineByHitPoint(IFeatureClass t_pLineFeatureClass, IPoint t_pPoint)
            {
    
                IFeatureClass pFeatureClass = t_pLineFeatureClass;
                IFeatureCursor pFeatureCursor;
                IFeature pFeature;
                pFeatureCursor = pFeatureClass.Search(null, false);
                pFeature = pFeatureCursor.NextFeature();
    
                IDataset dataset = (IDataset)pFeatureClass;
                IWorkspace workspace = dataset.Workspace;
                IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
    
                IRelationalOperator pRelationalOperator;
                //遍历featureClass找到点中的那条线
                while (pFeature != null)
                {
                    pRelationalOperator = (IRelationalOperator) pFeature.Shape;
                    bool bHasCrosses = pRelationalOperator.Contains(t_pPoint);
                    if (bHasCrosses)
                    {
                        //对那条线在点击点处,进行打断
                        IPolycurve pPolycurve = (IPolycurve) pFeature.Shape;
                        bool HasSplitHappened;
                        int newPartIndex;
                        int newSegmentIndex;
                        //打断
                        pPolycurve.SplitAtPoint(t_pPoint, false, true, out HasSplitHappened, out newPartIndex,
                            out newSegmentIndex);
                        if (HasSplitHappened)
                        {
                            //从GeometryCollection中分离出打断后的要素,并生成新的要素,并赋于属性
                            IFeature pNewFeature;
                            IGeometryCollection pGeometryCollection = (IGeometryCollection) pPolycurve;
    
                            for (int i = 0; i < pGeometryCollection.GeometryCount; i++)
                            {
                                //生成新的要素
                                workspaceEdit.StartEditing(false);
                                workspaceEdit.StartEditOperation();
                                pNewFeature = pFeatureClass.CreateFeature();
                                IGeometryCollection pline = new PolylineClass();
                                IGeometry pGeo = pGeometryCollection.get_Geometry(i);
                                pline.AddGeometries(1, ref pGeo);
                                pNewFeature.Shape = (IPolyline) pline;
                                pNewFeature.Store();
                                workspaceEdit.StopEditOperation();
                                workspaceEdit.StopEditing(true);
                                #region 属性复制(注释掉)
                                //IRow pRow = (IRow) pFeature;
                                //int intIndex = pRow.Fields.FindField("CRoadID");
                                //进行属性复制
                                //for (int k = 2; k < pRow.Fields.FieldCount - 3; k++) //前后几个属性字段不添加
                                //{
                                //    if (pRow.Fields.get_Field(k).Name == "Shape_Length")
                                //    {
                                //        continue;
                                //    }
                                //    if (k != intIndex)
                                //    {
                                //        if (!pRow.get_Value(k).ToString().Equals(""))
                                //        {
    
                                //            pNewFeature.set_Value(k, pRow.get_Value(k));
                                //        }
                                //    }
                                //    else
                                //    {
                                //        if (k == 0)
                                //        {
                                //            if (!pRow.get_Value(k).ToString().Equals(""))
                                //            {
                                //                pNewFeature.set_Value(k, pRow.get_Value(k));
                                //            }
                                //        }
                                //        else
                                //        {
    
                                //            if (!pRow.get_Value(k).ToString().Equals(""))
                                //            {
                                //                int intNO = System.Convert.ToInt32(pRow.get_Value(k).ToString()) + 1000*i;
                                //                pNewFeature.set_Value(k, intNO);
                                //            }
                                //        }
                                //    }
                                //}
                                //pNewFeature.Store();
                                #endregion
                            }
                            pFeature.Delete();
                        }
                    }
                    pFeature = pFeatureCursor.NextFeature();
                }
            }
  • 相关阅读:
    Python Day 10 函数、函数作用、组成部分、返回值return作用
    SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis
    深入理解HTTP Session
    JSP中两种include的区别
    Spring MVC控制层传递对象后在JSP页面中的取值方法
    Servlet和Filter的url匹配以及url-pattern详解 及 filter 循环问题的解决
    SSH:Action中Service无法实例化
    java实现邮箱找密码
    登陆界面验证码实现
    css 行内元素 块元素 替换元素 非替换元素 以及这些元素的width height margin padding 特性
  • 原文地址:https://www.cnblogs.com/joysky/p/4030279.html
Copyright © 2011-2022 走看看