Exemplo n.º 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);
            }
        }