//获取矿界 private IPolygon GetPolygon() { IPolygon polygon2 = null; ILayer pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MINE_BOUNDARY); IFeatureLayer polygonLayer = (IFeatureLayer)pLayer; IQueryFilter filter = new QueryFilterClass(); filter.WhereClause = "layer = '预警矿界'"; IFeatureLayer featureLayer = polygonLayer as IFeatureLayer; IFeatureCursor featureCursor = featureLayer.Search(filter, false); ITopologicalOperator2 topologicalOperator = null; // 获得矿界组合成面 if (featureCursor != null) { ISegmentCollection polygon = new PolygonClass(); IFeature feature = featureCursor.NextFeature(); while (feature != null) { polygon.AddSegmentCollection((ISegmentCollection)feature.Shape); feature = featureCursor.NextFeature(); } topologicalOperator = (ITopologicalOperator2)polygon; topologicalOperator.IsKnownSimple_2 = true; topologicalOperator.Simplify(); polygon2 = (IPolygon)topologicalOperator; } return(polygon2); }
//获取矿界 private IPolygon GetPolygon() { IPolygon polygon2 = null; ILayer pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MINE_BOUNDARY); IFeatureLayer polygonLayer = (IFeatureLayer)pLayer; IQueryFilter filter = new QueryFilterClass(); filter.WhereClause = "layer = '预警矿界'"; IFeatureLayer featureLayer = polygonLayer as IFeatureLayer; IFeatureCursor featureCursor = featureLayer.Search(filter, false); ITopologicalOperator2 topologicalOperator = null; // 获得矿界组合成面 if (featureCursor != null) { ISegmentCollection polygon = new PolygonClass(); IFeature feature = featureCursor.NextFeature(); while (feature != null) { polygon.AddSegmentCollection((ISegmentCollection)feature.Shape); feature = featureCursor.NextFeature(); } topologicalOperator = (ITopologicalOperator2)polygon; topologicalOperator.IsKnownSimple_2 = true; topologicalOperator.Simplify(); polygon2 = (IPolygon)topologicalOperator; } return polygon2; }
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(); }