用线切割面

//不太常用,标记       

public IGeometryCollection CutPolygon(IPolygon polygon,IPolyline polyline)
        {
            if (polygon == null || polyline == null)
            {
                return null;
            }
            ITopologicalOperator4 topologicalOperator4 = polygon as ITopologicalOperator4; // Dynamic Cast
            IGeometryCollection geometryCollection = topologicalOperator4.Cut2(polyline);
            return geometryCollection;
       }

//大数据量计算时,速度不理想

        public void SplitPolygonFeaturesByLine(IFeatureClass polygonFC, IFeatureClass lineFC)
        {
            if (polygonFC.ShapeType != esriGeometryType.esriGeometryPolygon)
            {
                MessageBox.Show("The target layer is not a polygon layer.");
                return;
            }
            IFeatureCursor lineFeatureCursor = lineFC.Search(null, false);

            IGeoDataset geoDS = polygonFC as IGeoDataset;
            IEnvelope processingBounds = geoDS.Extent;

            //Define an IInValidArea object.
            IInvalidArea invalidArea = new InvalidAreaClass();

            //Define a construct feature object.
            IFeatureConstruction featureConstruction = new FeatureConstructionClass();

            //Start an edit session.
            IDataset dataset = polygonFC as IDataset;
            IWorkspace workspace = dataset.Workspace;
            IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

            if (workspaceEdit.IsBeingEdited() != true)
            {
                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();
            }
            try
            {
                featureConstruction.SplitPolygonsWithLinesFromCursor(null, polygonFC, processingBounds, lineFeatureCursor, invalidArea, -1);
                workspaceEdit.StopEditOperation();
                workspaceEdit.StopEditing(true);
            }

            catch (Exception e)
            {
                //Abort the edit operation if errors are detected.
                MessageBox.Show("Construct polygons failed. " + e.Message);
                workspaceEdit.AbortEditOperation();
            }
        }

你可能感兴趣的:(用线切割面)