public virtual void Cut(IGeometry GeoByCut, IGeometry cutter, out IGeometry leftGeom, out IGeometry rightGeom) { ITopologicalOperator Top = cutter as ITopologicalOperator; Top.Simplify(); IPolyline pcutter = Top.Boundary as IPolyline; Top = GeoByCut as ITopologicalOperator; try { Top.Cut(pcutter, out leftGeom, out rightGeom); } catch (Exception ee) { leftGeom = null; rightGeom = null; System.Diagnostics.Debug.WriteLine(ee.ToString()); } }
public static bool CutPolygonByLine(IPolygon pPolygon, IPolyline pCutLine, ref IGeometry pRight, ref IGeometry pLeft) { pRight = null; pLeft = null; if (pPolygon == null || pPolygon.IsEmpty || pCutLine == null || pCutLine.IsEmpty) { return(false); } try { ITopologicalOperator pTopologicalOperator = pPolygon as ITopologicalOperator; pTopologicalOperator.Cut(pCutLine, out pLeft, out pRight); return(true); } catch (Exception e) { return(false); } }
public bool Split(IPolyline ipolyline_0, out IGeometryBag igeometryBag_0) { bool flag; IGeometry geometry; IGeometry geometry1; igeometryBag_0 = null; if (this.m_pGeometry.GeometryType != esriGeometryType.esriGeometryPoint) { try { ITopologicalOperator mPGeometry = this.m_pGeometry as ITopologicalOperator; if (mPGeometry != null) { if (!mPGeometry.IsSimple) { mPGeometry.Simplify(); } mPGeometry.Cut(ipolyline_0, out geometry, out geometry1); object value = Missing.Value; igeometryBag_0 = new GeometryBag() as IGeometryBag; (igeometryBag_0 as IGeometryCollection).AddGeometry(geometry, ref value, ref value); (igeometryBag_0 as IGeometryCollection).AddGeometry(geometry1, ref value, ref value); } else { flag = false; return(flag); } } catch { } flag = false; } else { flag = false; } return(flag); }
/// <summary> /// 分割多边形 /// </summary> /// <param name="polygon"></param> /// <param name="polyline"></param> /// <returns></returns> public static List <IGeometry> CutGeometry(IGeometry polygon, IGeometry polyline) { List <IGeometry> geos = new List <IGeometry>(); try { IGeometry pLeftGeo, pRightGeo; ITopologicalOperator pTopologBoundary = polygon as ITopologicalOperator; pTopologBoundary.Simplify(); pTopologBoundary.Cut((IPolyline)polyline, out pLeftGeo, out pRightGeo); if (pLeftGeo != null && pRightGeo != null) { geos.Add(pLeftGeo); geos.Add(pRightGeo); } } catch (Exception ex) { throw ex; } return(geos); }
//使用外部要素IGeometry进行分割 public virtual void Cut(IGeometry GeoByCut, IPolyline cutter, out IGeometry leftGeom, out IGeometry rightGeom) { ITopologicalOperator Top = GeoByCut as ITopologicalOperator; Top.Cut(cutter, out leftGeom, out rightGeom); }
public void SplitPolygons() //分割面 { m_pLineFeed = (INewLineFeedback)m_pFeedback; if (m_pLineFeed == null) { Reset(); return; } IPolyline pFeatureScissors = m_pLineFeed.Stop(); //结束绘制切割线 if (pFeatureScissors.Length == 0) { Reset(); return; } ILayer pFeatureLayer; pFeatureLayer = m_App.CurrentEditLayer; IGeometry pOldGeometry; IFeature pOldFeature; IWorkspaceEdit pWorkspaceEdit; pWorkspaceEdit = (IWorkspaceEdit)CommonFunction.GetLayerWorkspace(pFeatureLayer); if (pWorkspaceEdit == null) { return; } pWorkspaceEdit.StartEditOperation(); for (int i = 0; i < m_OriginFeatureArray.Count; i++) //遍历每个选中的要素 { IArray pArrGeo = new ArrayClass(); pOldFeature = (IFeature)m_OriginFeatureArray.get_Element(i); pOldGeometry = (IGeometry)pOldFeature.Shape; if ((pOldGeometry == null) || (pFeatureScissors == null)) { return; } if (pOldGeometry.GeometryType != esriGeometryType.esriGeometryPolygon) { return; } ITopologicalOperator pTopologim_CalOperator = (ITopologicalOperator)pOldGeometry; IGeometry oRsGeo_1 = null, oRsGeo_2 = null; try { pTopologim_CalOperator.Simplify(); pTopologim_CalOperator.Cut(pFeatureScissors, out oRsGeo_1, out oRsGeo_2); IGeometryCollection oGeoCol = (IGeometryCollection)oRsGeo_1; for (int j = 0; j < oGeoCol.GeometryCount; j++) { ISegmentCollection oNewPoly = new PolygonClass(); oNewPoly.AddSegmentCollection((ISegmentCollection)oGeoCol.get_Geometry(j)); pArrGeo.Add(oNewPoly); } oGeoCol = (IGeometryCollection)oRsGeo_2; for (int j = 0; j < oGeoCol.GeometryCount; j++) { ISegmentCollection oNewPoly = new PolygonClass(); oNewPoly.AddSegmentCollection((ISegmentCollection)oGeoCol.get_Geometry(j)); pArrGeo.Add(oNewPoly); } for (int j = 0; j < pArrGeo.Count; j++) { CommonFunction.AddFeature0(m_MapControl, (IGeometry)pArrGeo.get_Element(j), m_App.CurrentEditLayer, pOldFeature); } pOldFeature.Delete(); } catch { //MessageBox.Show(Ex.ToString()); } } m_App.Workbench.CommandBarManager.Tools["2dmap.DFEditorTool.Undo"].SharedProps.Enabled = true; pWorkspaceEdit.StopEditOperation(); Reset(); }
//to be improved, a vertical cutter may cause unexpected problems // public void CreateBufferWithoutEnds(IGeometry fBufferGeo, double dblBuffer) { //StartCutPolyline ILine pStartNormal = new LineClass(); this.pPolyline.QueryNormal(esriSegmentExtension.esriNoExtension, 0, true, dblBuffer, pStartNormal); IPoint StartFrPt = new PointClass(); pStartNormal.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1.5, true, StartFrPt); IPoint StartToPt = new PointClass(); pStartNormal.QueryPoint(esriSegmentExtension.esriExtendAtTo, 1.5, true, StartToPt); IPointCollection4 pStartCutterCol = new PolylineClass(); pStartCutterCol.AddPoint(StartFrPt); pStartCutterCol.AddPoint(StartToPt); IPolyline5 pStartCutter = pStartCutterCol as IPolyline5; //EndCutPolyline ILine pEndNormal = new LineClass(); this.pPolyline.QueryNormal(esriSegmentExtension.esriNoExtension, 1, true, dblBuffer, pEndNormal); IPoint EndFrPt = new PointClass(); pEndNormal.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1.5, true, EndFrPt); IPoint EndToPt = new PointClass(); pEndNormal.QueryPoint(esriSegmentExtension.esriExtendAtTo, 1.5, true, EndToPt); IPointCollection4 pEndCutterCol = new PolylineClass(); pEndCutterCol.AddPoint(EndFrPt); pEndCutterCol.AddPoint(EndToPt); IPolyline5 pEndCutter = pEndCutterCol as IPolyline5; //TopologicalOperators ITopologicalOperator pStartPtTop = this.pPolyline.FromPoint as ITopologicalOperator; IGeometry pStartPtBuffer = pStartPtTop.Buffer(dblBuffer); ITopologicalOperator pEndPtTop = this.pPolyline.ToPoint as ITopologicalOperator; IGeometry pEndPtBuffer = pEndPtTop.Buffer(dblBuffer); //Cut ITopologicalOperator pStartPtBufferTop = pStartPtBuffer as ITopologicalOperator; IGeometry StartLeftOutGeometry; IGeometry StartRightOutGeometry; pStartPtBufferTop.Cut(pStartCutter, out StartLeftOutGeometry, out StartRightOutGeometry); ITopologicalOperator pEndPtBufferTop = pEndPtBuffer as ITopologicalOperator; IGeometry EndLeftOutGeometry; IGeometry EndRightOutGeometry; pEndPtBufferTop.Cut(pEndCutter, out EndLeftOutGeometry, out EndRightOutGeometry); //Difference ITopologicalOperator pBufferTop = fBufferGeo as ITopologicalOperator; IGeometry pDiffStart = pBufferTop.Difference(StartRightOutGeometry); ITopologicalOperator pDiffStartTop = pDiffStart as ITopologicalOperator; IGeometry pDiffEnd = pDiffStartTop.Difference(EndLeftOutGeometry); _pBufferGeoWithoutEnds = pDiffEnd; }