private void UpdateFeature(IFeature selectedFeature, ISegmentCollection polylineSegments) { ISegmentCollection polyline = new PolylineClass(); polyline.AddSegmentCollection(polylineSegments); IFeatureClass featureClass = selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } try { workspaceEdit.StartEditOperation(); selectedFeature.Shape = polyline as IGeometry; selectedFeature.Store(); workspaceEdit.StopEditOperation(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("移动线段失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static void LinesToPolygons(IFeatureClass ifeatureClass_0, IFeatureClass ifeatureClass_1) { if (ifeatureClass_0.ShapeType == esriGeometryType.esriGeometryPolygon) { IFeatureCursor featureCursor = ifeatureClass_1.Search(null, false); IEnvelope envelope = (ifeatureClass_1 as IGeoDataset).Extent.Envelope; IInvalidArea invalidAreaClass = new InvalidArea(); IFeatureConstruction featureConstructionClass = new FeatureConstruction(); IWorkspaceEdit workspace = (ifeatureClass_0 as IDataset).Workspace as IWorkspaceEdit; if (!workspace.IsBeingEdited()) { workspace.StartEditing(false); workspace.StartEditOperation(); } try { featureConstructionClass.ConstructPolygonsFromFeaturesFromCursor(null, ifeatureClass_0, envelope, true, false, featureCursor, invalidAreaClass, -1, null); workspace.StopEditOperation(); workspace.StopEditing(true); } catch (Exception exception1) { Exception exception = exception1; MessageBox.Show(string.Concat("Construct polygons failed. ", exception.Message)); workspace.AbortEditOperation(); } ComReleaser.ReleaseCOMObject(featureCursor); } else { MessageBox.Show("目标层不是一个面层."); } }
public static void LinesSelfBreak(IFeatureClass ifeatureClass_0, string string_0) { if (ifeatureClass_0.ShapeType == esriGeometryType.esriGeometryPolyline) { IQueryFilter queryFilterClass = new QueryFilter() { WhereClause = string_0 }; IFeatureCursor featureCursor = ifeatureClass_0.Search(queryFilterClass, false); IFeatureConstruction featureConstructionClass = new FeatureConstruction(); IWorkspaceEdit workspace = (ifeatureClass_0 as IDataset).Workspace as IWorkspaceEdit; if (!workspace.IsBeingEdited()) { workspace.StartEditing(false); workspace.StartEditOperation(); } try { featureConstructionClass.PlanarizeLinesFromCursor(null, ifeatureClass_0, featureCursor, -1); workspace.StopEditOperation(); workspace.StopEditing(true); } catch (Exception exception1) { Exception exception = exception1; MessageBox.Show(string.Concat("线打断出错. ", exception.Message)); workspace.AbortEditOperation(); } ComReleaser.ReleaseCOMObject(featureCursor); } else { MessageBox.Show("目标层不是一个线层."); } }
public void updateCoverages(double deadCoverage, double receptionCoverage) { IWorkspaceEdit pWorkspaceEdit = null; try { pWorkspaceEdit = (IWorkspaceEdit)((IDataset)ServiceTerritoryFeature.Class).Workspace; IMultiuserWorkspaceEdit pMUWorkspaceEdit = (IMultiuserWorkspaceEdit)pWorkspaceEdit; pMUWorkspaceEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); //pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); ServiceTerritoryFeature.set_Value(ServiceTerritoryFeature.Fields.FindField("DEADCOVERAGE"), deadCoverage); ServiceTerritoryFeature.set_Value(ServiceTerritoryFeature.Fields.FindField("RECEPTIONCOVERAGE"), receptionCoverage); ServiceTerritoryFeature.Store(); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); } catch { pWorkspaceEdit.AbortEditOperation(); } }
/// <summary> /// Rollback (abort) Operation then Stop Edit. /// </summary> /// <param name="workspace"></param> public static void StopEditAndRollback(IWorkspace workspace) { IWorkspaceEdit iWorkspaceEdit = workspace as IWorkspaceEdit; bool saveEdits = false; if (iWorkspaceEdit.IsBeingEdited()) { iWorkspaceEdit.AbortEditOperation(); iWorkspaceEdit.StopEditing(saveEdits); } }
/// <summary> /// 插入新要素 /// </summary> /// <param name="featureLayer">图层</param> /// <param name="geom">插入要素几何图形</param> /// <param name="ID">要素ID(绑定ID)</param> /// <returns></returns> public static bool InsertNewFeature(IFeatureLayer featureLayer, IGeometry geom, string ID) { IWorkspaceEdit workspaceEdit = null; IFeatureCursor featureCursor = null; try { IFeatureClass featureClass = featureLayer.FeatureClass; IDataset dataset = (IDataset)featureClass; IWorkspace workspace = dataset.Workspace; workspaceEdit = workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer(); DataEditCommon.ZMValue(featureBuffer, geom); //几何图形Z值处理 featureBuffer.Shape = geom; int iFieldID = featureBuffer.Fields.FindField("ID"); featureBuffer.Value[iFieldID] = ID.ToString(); //开始插入要素 featureCursor = featureClass.Insert(true); object featureOID = featureCursor.InsertFeature(featureBuffer); //保存要素 featureCursor.Flush(); IFeature feature = featureCursor.NextFeature(); workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); workspaceEdit.AbortEditOperation(); workspaceEdit.StopEditing(false); return(false); } finally { if (featureCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); //释放指针 } } }
/// <summary> /// Abort (rollback) operation. /// </summary> /// <param name="workspace"></param> public static void AbortOperation(IWorkspace workspace) { IWorkspaceEdit iWorkspaceEdit = workspace as IWorkspaceEdit; if (!iWorkspaceEdit.IsBeingEdited()) { throw new InvalidOperationException("Workspace is not start edit yet."); } iWorkspaceEdit.AbortEditOperation(); }
public bool AbortEditing(IWorkspace TheWorkspace) { IWorkspaceEdit pWSEdit = (IWorkspaceEdit)TheWorkspace; pWSEdit.AbortEditOperation(); pWSEdit.EnableUndoRedo(); if (pWSEdit.IsBeingEdited()) { pWSEdit.StopEditing(false); } return(true); }
private void method_10(IWorkspaceEdit iworkspaceEdit_0, bool bool_2) { if (bool_2) { iworkspaceEdit_0.StopEditOperation(); iworkspaceEdit_0.StopEditing(true); } else { iworkspaceEdit_0.AbortEditOperation(); iworkspaceEdit_0.StopEditing(false); } }
private void UpdateFeature(IFeature selectedFeature, IPointCollection4 polylinePoints) { IPointCollection4 geometry; esriGeometryType geometryType = selectedFeature.Shape.GeometryType; switch (geometryType) { case esriGeometryType.esriGeometryMultipoint: geometry = new MultipointClass(); break; case esriGeometryType.esriGeometryPolyline: geometry = new PolylineClass(); break; case esriGeometryType.esriGeometryPolygon: geometry = new PolygonClass(); break; default: geometry = null; break; } if (geometry == null) { return; } geometry.AddPointCollection(polylinePoints); IFeatureClass featureClass = selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } try { workspaceEdit.StartEditOperation(); selectedFeature.Shape = geometry as IGeometry; selectedFeature.Store(); workspaceEdit.StopEditOperation(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("移动要素顶点失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Start Editing operation /// </summary> /// <param name="ipWorkspace">IWorkspace</param> public static void StartEditOperation(IWorkspace ipWorkspace) { IWorkspaceEdit ipWsEdit = ipWorkspace as IWorkspaceEdit; try { ipWsEdit.StartEditOperation(); } catch (Exception ex) { ipWsEdit.AbortEditOperation(); throw (ex); } }
private void TrimPolyline(IFeature trimFeature, IFeature targetFeature, IPoint secondPoint) { IGeometry preservedGeom = null; IGeometry leftGeom = null; IGeometry rightGeom = null; double distanceOnCurve = 0; double nearestDistance = 0; bool isRightSide = false; IPoint outPoint = new PointClass(); IFeatureClass featureClass = trimFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } try { IGeometry targetGeometry = targetFeature.ShapeCopy; IGeometry trimGeometry = trimFeature.ShapeCopy; ITopologicalOperator2 topo = trimGeometry as ITopologicalOperator2; topo.IsKnownSimple_2 = false; topo.Simplify(); ITopologicalOperator2 topo2 = targetGeometry as ITopologicalOperator2; topo2.IsKnownSimple_2 = false; topo2.Simplify(); topo.Cut(targetGeometry as IPolyline, out leftGeom, out rightGeom); ICurve curve = targetGeometry as ICurve; curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, secondPoint, false, outPoint, ref distanceOnCurve, ref nearestDistance, ref isRightSide); if (isRightSide) { preservedGeom = leftGeom; } else { preservedGeom = rightGeom; } workspaceEdit.StartEditOperation(); trimFeature.Shape = preservedGeom; trimFeature.Store(); workspaceEdit.StopEditOperation(); FlashGeometry(trimGeometry as IGeometry, 3, 10); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("线要素延伸失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static void AbortOperation() { if (engineEditor.EditState != esriEngineEditState.esriEngineStateEditing) { throw new InvalidOperationException("Editor State not in Start Editing"); } //IWorkspaceEdit2 oWorkspaceEdit = engineEditor.EditWorkspace as IWorkspaceEdit2; IWorkspaceEdit oWorkspaceEdit = engineEditor.EditWorkspace as IWorkspaceEdit; if (IsInEditOperation) { oWorkspaceEdit.AbortEditOperation(); } }
/// <summary> /// Stop Editing operation /// </summary> /// <param name="ipWorkspace">IWorkspace</param> /// <returns>True if successful, false otherwise</returns> public static bool StopEditOperation(IWorkspace ipWorkspace) { bool blnWasSuccessful = false; IWorkspaceEdit ipWsEdit = ipWorkspace as IWorkspaceEdit; try { ipWsEdit.StopEditOperation(); blnWasSuccessful = true; } catch (Exception ex) { ipWsEdit.AbortEditOperation(); } return(blnWasSuccessful); }
public void Rollback() { if (_currentWorkspace == null) { System.Diagnostics.Debug.WriteLine("Current Workspace em UnitOfWork é nulo."); return; } OnBeforeRollback(EventArgs.Empty); IWorkspaceEdit edit = _currentWorkspace as IWorkspaceEdit; ClearPendingRecords(); edit.AbortEditOperation(); edit.StopEditing(false); OnAfterRollback(EventArgs.Empty); }
/// <summary> /// Start Editing operation /// </summary> /// <param name="ipWorkspace">IWorkspace</param> public static bool StartEditOperation(IWorkspace ipWorkspace) { bool blnWasSuccessful = false; IWorkspaceEdit ipWsEdit = ipWorkspace as IWorkspaceEdit; if (ipWsEdit != null) { try { ipWsEdit.StartEditOperation(); blnWasSuccessful = true; } catch (Exception ex) { ipWsEdit.AbortEditOperation(); throw (ex); } } return(blnWasSuccessful); }
/// <summary> /// 结束编辑 /// </summary> /// <param name="Save"></param> public void StopEditing(bool Save) { if (If_isEdited) { If_isEdited = false; if (MyselectedLayer == null) { return; } IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return; } IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (workspaceEdit.IsBeingEdited()) { try { workspaceEdit.StopEditing(Save); } catch { workspaceEdit.AbortEditOperation(); return; } } } }
public void GetTowerCoverage(Towers pTowers) { IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)_workspace; IFeatureClass pRangeFC = pFeatureWorkspace.OpenFeatureClass("TowerRanges"); IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)_workspace; try { pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureCursor pRangeCursor = pRangeFC.Update(null, false); //IFeature pFeature = pRangeCursor.NextFeature(); while (pRangeCursor.NextFeature() != null) { //pFeature.Delete(); //pFeature = pRangeCursor.NextFeature(); pRangeCursor.DeleteFeature(); } foreach (Tower pTower in pTowers.Items) { //Tower pTower = tm.GetTowerByID("T04"); double towerRange = pTower.towerCoverage; ITopologicalOperator pTopo = (ITopologicalOperator)pTower.towerLocation; IPolygon range3Bars = (IPolygon)pTopo.Buffer(towerRange / 3); IPolygon range2BarsWhole = (IPolygon)pTopo.Buffer(towerRange * 2 / 3); ITopologicalOperator p2BarTopo = (ITopologicalOperator)range2BarsWhole; IPolygon range2BarsDonut = (IPolygon)p2BarTopo.Difference(range3Bars); IPolygon range1BarWhole = (IPolygon)pTopo.Buffer(towerRange); ITopologicalOperator p1BarTopo = (ITopologicalOperator)range1BarWhole; IPolygon range1BarDonut = (IPolygon)p1BarTopo.Difference(range2BarsWhole); //IFeatureWorkspace pFWorkspace = (IFeatureWorkspace)pWorkspaceEdit; //IFeatureClass pTowerRangeFC = pFWorkspace.OpenFeatureClass("TowerRanges"); IFeature pFeature = pRangeFC.CreateFeature(); pFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); pFeature.set_Value(pFeature.Fields.FindField("RANGE"), 3); pFeature.Shape = range3Bars; pFeature.Store(); IFeature p2BarsFeature = pRangeFC.CreateFeature(); p2BarsFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); p2BarsFeature.set_Value(pFeature.Fields.FindField("RANGE"), 2); p2BarsFeature.Shape = range2BarsDonut; p2BarsFeature.Store(); IFeature p1BarsFeature = pRangeFC.CreateFeature(); p1BarsFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); p1BarsFeature.set_Value(pFeature.Fields.FindField("RANGE"), 1); p1BarsFeature.Shape = range1BarDonut; p1BarsFeature.Store(); } pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); } catch (Exception ex) { pWorkspaceEdit.AbortEditOperation(); MessageBox.Show(ex.ToString()); } }
protected virtual void AbortEditOperation() { Assert.NotNull(_workspaceEdit); _workspaceEdit.AbortEditOperation(); }
/// <summary> /// 绘制小柱状 /// </summary> /// <param name="datasources">各地质层厚度(0.83,0.3,1.2,200)最后一个值为底板标高</param> /// <param name="pt">小柱状中心点</param> /// <param name="Angle">旋转角度</param> /// <param name="bili">比例</param> /// <param name="bid">BID</param> /// <param name="edit">函数外控制编辑状态为false,函数内自动控制编辑状态为true,当批量绘图时建议函数外控制编辑状态</param> public static bool drawXZZ(List <KeyValuePair <int, double> > datasources, IPoint pt, double Angle, string bid, double bili = 1, bool edit = true) { double angle = -Angle; Angle = -Angle * Math.PI / 180; DrawXZZMap draw = new DrawXZZMap(bili); var AnnoLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_AnnotationXZZ) as IFeatureLayer; //注记图层 var lineLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolylineXZZ) as IFeatureLayer; //线源图层 var topLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolygonXZZ) as IFeatureLayer; //外部图形图层 if (AnnoLayer == null || lineLayer == null || topLayer == null) { System.Windows.Forms.MessageBox.Show("小柱状图层缺失!"); return(false); } IWorkspaceEdit workspaceEdit = null; if (edit) { var dataset = lineLayer.FeatureClass as IDataset; workspaceEdit = dataset.Workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); } try { // 准备添加数据 var polygonTopCursor = topLayer.FeatureClass.Insert(true); var polylineCursor = lineLayer.FeatureClass.Insert(true); var AnnoCursor = AnnoLayer.FeatureClass.Insert(true); // 从数据源图层获得数据 var num1 = datasources[datasources.Count - 1].Value; // 最后一条横线数值 datasources.RemoveAt(datasources.Count - 1); if (datasources.Count > 1) { List <IPoint> txtPoints; List <IPoint> lineStartPoints; var polygons = new List <KeyValuePair <string, IPolygon> >(); // 构造图形 draw.ContructGeometry(pt, datasources, out polygons, out lineStartPoints, out txtPoints); ITransform2D pTrans2D; // 生成方框图形 foreach (var polygon in polygons) { var feature2 = topLayer.FeatureClass.CreateFeatureBuffer(); feature2.set_Value(feature2.Fields.FindField("BID"), bid); if (polygon.Key == "top") { feature2.set_Value(feature2.Fields.FindField("type"), 0); } else if (polygon.Key == "white") { feature2.set_Value(feature2.Fields.FindField("type"), 1); } else if (polygon.Key == "black") { feature2.set_Value(feature2.Fields.FindField("type"), 2); } pTrans2D = polygon.Value as ITransform2D; //旋转要素 pTrans2D.Rotate(pt, Angle); IPolygon ppp = pTrans2D as IPolygon; GIS.Common.DataEditCommon.ZMValue(feature2, ppp); feature2.Shape = ppp; polygonTopCursor.InsertFeature(feature2); } // 生成注记 var enveloplist = new List <IEnvelope>(); for (int i = 0; i < txtPoints.Count; i++) { var featureAnno = AnnoLayer.FeatureClass.CreateFeatureBuffer(); IAnnotationFeature AnnoFeature = (IAnnotationFeature)featureAnno; pTrans2D = txtPoints[i] as ITransform2D; //旋转要素 pTrans2D.Rotate(pt, Angle); ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Angle = angle; var elementTxt = new TextElementClass { Geometry = pTrans2D as IGeometry, FontName = "微软雅黑", Size = 12 * bili, SymbolID = 0, Symbol = pTextSymbol }; if (i == txtPoints.Count - 1) { elementTxt.Text = num1.ToString(); // 最后一条横线的数值 elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; // 显示在线下边 featureAnno.set_Value(featureAnno.Fields.FindField("strType"), 2); } else { elementTxt.Text = datasources[i].Value.ToString(); elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; featureAnno.set_Value(featureAnno.Fields.FindField("strType"), datasources[i].Key); } AnnoFeature.Annotation = elementTxt; featureAnno.set_Value(featureAnno.Fields.FindField("strAngle"), -angle); featureAnno.set_Value(featureAnno.Fields.FindField("strX"), pt.X); featureAnno.set_Value(featureAnno.Fields.FindField("strY"), pt.Y); featureAnno.set_Value(featureAnno.Fields.FindField("strScale"), bili); featureAnno.set_Value(featureAnno.Fields.FindField("strIndex"), i + 1); featureAnno.set_Value(featureAnno.Fields.FindField("BID"), bid); pTrans2D = featureAnno.Shape as ITransform2D; pTrans2D.Rotate(pt, -Angle); enveloplist.Add(((IGeometry)pTrans2D).Envelope); AnnoCursor.InsertFeature(featureAnno); } // 生成线 var polyline = new PolylineClass(); for (int i = 0; i < enveloplist.Count; i++) { // 计算注记的终点 IPoint toPoint = new PointClass(); if (i % 2 == 0) { toPoint.X = enveloplist[i].XMax; } else { toPoint.X = enveloplist[i].XMin; } toPoint.Y = lineStartPoints[i].Y; var line = new PathClass { FromPoint = lineStartPoints[i], ToPoint = toPoint }; polyline.AddGeometry(line); } var featureLine = lineLayer.FeatureClass.CreateFeatureBuffer(); pTrans2D = polyline as ITransform2D; pTrans2D.Rotate(pt, Angle); IPolyline mline = pTrans2D as IPolyline; GIS.Common.DataEditCommon.ZMValue(featureLine, mline); featureLine.Shape = mline; featureLine.set_Value(featureLine.Fields.FindField("BID"), bid); polylineCursor.InsertFeature(featureLine); } AnnoCursor.Flush(); polygonTopCursor.Flush(); polylineCursor.Flush(); if (edit) { workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); DataEditCommon.g_pMyMapCtrl.ActiveView.Refresh(); } return(true); } catch (Exception ex) { if (edit) { workspaceEdit.AbortEditOperation(); workspaceEdit.StopEditing(false); } System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } }
/// <summary> /// 由小区道路生成内部地块 /// </summary> /// <param name="getpolygon_fc"></param> /// <param name="fromline_fl"></param> private void createpolygonfromline(IFeatureClass getpolygon_fc, IFeatureLayer fromline_fl) { //判断getpolygon_fc是否为面 if (getpolygon_fc.ShapeType != esriGeometryType.esriGeometryPolygon) { MessageBox.Show("目标图层不是多边形图层!"); System.Console.WriteLine("目标图层不是多边形图层!"); return; } //得到选择的Feature的指针 IFeatureSelection pFeatureSelection = fromline_fl as IFeatureSelection; ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet; ICursor pCursor; pSelectionSet.Search(null, false, out pCursor); IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor; IGeoDataset pGeoDataset = getpolygon_fc as IGeoDataset; IEnvelope pEnvelope = pGeoDataset.Extent; IInvalidArea pInvalidArea = new InvalidAreaClass(); IFeatureConstruction pFeatureConstruction = new FeatureConstructionClass(); IDataset pDataset = getpolygon_fc as IDataset; IWorkspace pWorkspace = pDataset.Workspace; IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit; if (pWorkspaceEdit.IsBeingEdited() != true) { pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); } //开始 try { pFeatureConstruction.ConstructPolygonsFromFeaturesFromCursor(null, getpolygon_fc, pEnvelope, true, false, pFeatureCursor, pInvalidArea, -1, null); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); } catch { MessageBox.Show("构造多边形失败!"); System.Console.WriteLine("构造多边形失败!"); pWorkspaceEdit.AbortEditOperation(); } //获取FeatureClass IWorkspace editedWorkspace = pWorkspaceEdit as IWorkspace; IEnumDataset FeatureEnumDataset = editedWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass); if (FeatureEnumDataset == null) { return; } FeatureEnumDataset.Reset(); IDataset editedDataset = FeatureEnumDataset.Next(); IFeatureClass pFC = editedDataset as IFeatureClass; //错误写法 //IFeatureWorkspace pFeatureWorkspace = pWorkspaceEdit as IFeatureWorkspace; //IFeatureDataset pFeatureDataset = pFeatureWorkspace as IFeatureDataset; //IFeatureClass pFC = pFeatureDataset as IFeatureClass; //将生成面元素显示在图层中 IFeatureLayer pFLayer = new FeatureLayerClass(); pFLayer.FeatureClass = pFC; pFLayer.Name = pFC.AliasName;//保存为“生成地块.shp” ILayer pLayer = pFLayer as ILayer; Form1.mainForm.axMapControl1.Map.AddLayer(pLayer); Form1.mainForm.axMapControl1.ActiveView.Refresh(); }
private void CutSelectedPolygon() { bool isSuccess = false; if (m_selectedFeature == null) { MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); m_toolPhase = ToolPhase.SelectFeature; return; } //在屏幕上绘制用于分割的线要素 IScreenDisplay screenDisplay = m_activeView.ScreenDisplay; ISimpleLineSymbol sym = new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = 255; color.Green = 128; color.Blue = 128; sym.Color = color; sym.Style = esriSimpleLineStyle.esriSLSSolid; sym.Width = 2; IRubberBand cutBand = new RubberLineClass(); IGeometry reshaprGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol); screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); screenDisplay.SetSymbol(sym as ISymbol); screenDisplay.DrawPolyline(reshaprGeometry); screenDisplay.FinishDrawing(); IFeatureClass featureClass = m_selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } //分割选择的面要素 if (reshaprGeometry.IsEmpty == true) { return; } try { IPolyline reshapePolyline, sourcePolyline = null; IPolygon4 polygon = null; IRing ring = null, innerRing = null, outRing = null; IPath reshapePath = null; IGeometryCollection pathCollection = null; IGeometry geometry = m_selectedFeature.Shape; switch (geometry.GeometryType) { case esriGeometryType.esriGeometryPolygon: bool outerSuccess = false, innerSuccess = false; IGeometryBag innerRingGeometryBag = null; IGeometryCollection innerRingGeometryCollection = null; reshapePolyline = reshaprGeometry as IPolyline; pathCollection = reshapePolyline as IGeometryCollection; //只可能产生一条polyline,直接写死 reshapePath = pathCollection.Geometry[0] as IPath; polygon = geometry as IPolygon4; IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag; IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection; for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++) { outRing = exteriorRingGeometryCollection.Geometry[i] as IRing; bool a = outRing.Reshape(reshapePath); outerSuccess = outerSuccess || a; innerRingGeometryBag = polygon.get_InteriorRingBag(outRing); innerRingGeometryCollection = innerRingGeometryBag as IGeometryCollection; for (int j = 0; j < innerRingGeometryCollection.GeometryCount; j++) { innerRing = innerRingGeometryCollection.Geometry[j] as IRing; bool b = innerRing.Reshape(reshapePath); innerSuccess = innerSuccess || b; } } isSuccess = innerSuccess || outerSuccess; break; case esriGeometryType.esriGeometryPolyline: sourcePolyline = geometry as IPolyline; reshapePolyline = reshaprGeometry as IPolyline; pathCollection = reshapePolyline as IGeometryCollection; //只可能产生一条polyline,直接写死 reshapePath = pathCollection.Geometry[0] as IPath; isSuccess = sourcePolyline.Reshape(reshapePath); break; } if (isSuccess) { workspaceEdit.StartEditOperation(); m_selectedFeature.Shape = geometry;//如果没加这句gdb无法编辑 m_selectedFeature.Store(); m_activeView.Refresh(); workspaceEdit.StopEditOperation(); } else { throw new Exception("重塑要素失败!"); } m_activeView.Refresh(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); m_toolPhase = ToolPhase.SelectFeature; }
public void ConstructPointParallelToLine(IPolyline Path) { IWorkspaceEdit WorkspaceEdit = null; try { if (Path != null) { if (Path.GeometryType == esriGeometryType.esriGeometryPolyline) { firstLine = false; widthPointsMain = new List <IPoint>(); heigthPoints = new List <IPoint>(); widthPoints = new List <IPoint>(); IFeatureClass rectsFeatureClass = ((IFeatureLayer)lstLayers[cboLayers.SelectedIndex]).FeatureClass; IWorkspace workspace = ((IDataset)rectsFeatureClass).Workspace; WorkspaceEdit = (IWorkspaceEdit)workspace; if (!WorkspaceEdit.IsBeingEdited()) { WorkspaceEdit.StartEditing(true); } WorkspaceEdit.StartEditOperation(); IConstructPoint constructionPoint = (IConstructPoint) new ESRI.ArcGIS.Geometry.Point(); IGeometryCollection geometryCollection = Path as IGeometryCollection; ISegmentCollection segmentCollection = geometryCollection.get_Geometry(0) as ISegmentCollection; widthSegment = segmentCollection.get_Segment(0); heightSegment = segmentCollection.get_Segment(1); IPoint fromPoint = new ESRI.ArcGIS.Geometry.Point(); heightSegment.QueryFromPoint(fromPoint); widthPointsMain.Add(fromPoint); IRgbColor rgbColor = GetColor(255, 0, 0); //AddGraphicToMap((IMap)GetActiveView, fromPoint, rgbColor, rgbColor); //GetActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); widthSegment.ReverseOrientation(); double distanceAlongWidthBunderiesPoints = 0; double distanceAlongHeightBunderiesPoints = 0; for (int i = 0; i < NumberOfRectsinWidth; i++) { IPoint qpWidthSegment = GetQPWidthSegment(distanceAlongWidthBunderiesPoints + Widthofrects); if (qpWidthSegment == null) { return; } widthPointsMain.Add(qpWidthSegment); //AddGraphicToMap((IMap)GetActiveView, qpWidthSegment, rgbColor, rgbColor); if (i != NumberOfRectsinWidth - 1) { IPoint qpWidthSegmentWithDistance = GetQPWidthSegment(distanceAlongWidthBunderiesPoints + Widthofrects + distanceAlongWidth); //AddGraphicToMap((IMap)GetActiveView, qpWidthSegmentWithDistance, rgbColor, rgbColor); widthPointsMain.Add(qpWidthSegmentWithDistance); } distanceAlongWidthBunderiesPoints = (Widthofrects + distanceAlongWidth) * (i + 1); } for (int i = 0; i < NumberOfRectsinHeigth; i++) { IPoint qpHeightSegment = GetQPHeightSegment(distanceAlongHeightBunderiesPoints + Heigthofrects); if (qpHeightSegment == null) { return; } heigthPoints.Add(qpHeightSegment); //AddGraphicToMap((IMap)GetActiveView, qpHeightSegment, rgbColor, rgbColor); if (i != NumberOfRectsinHeigth - 1) { IPoint qpHeightSegmentWithDistance = GetQPHeightSegment(distanceAlongHeightBunderiesPoints + Heigthofrects + distanceAlongHeigth); //AddGraphicToMap((IMap)GetActiveView, qpHeightSegmentWithDistance, rgbColor, rgbColor); heigthPoints.Add(qpHeightSegmentWithDistance); } distanceAlongHeightBunderiesPoints = (Heigthofrects + distanceAlongHeigth) * (i + 1); } for (int j = 0; j < heigthPoints.Count; j++) { constructionPoint.ConstructParallel(widthSegment, esriSegmentExtension.esriExtendAtTo, heigthPoints[j], Widthofrects); IPoint outPutPoint = constructionPoint as IPoint; IPath newPath = (IPath) new ESRI.ArcGIS.Geometry.Path(); newPath.FromPoint = heigthPoints[j]; newPath.ToPoint = outPutPoint; if (!firstLine) { widthPoints.Add(heigthPoints[j]); } else { widthPointsMain.Add(heigthPoints[j]); } distanceAlongWidthBunderiesPoints = 0; for (int i = 0; i < NumberOfRectsinWidth; i++) { IPoint qpWidthSegment = GetQPWidthNewSegment(newPath, distanceAlongWidthBunderiesPoints + Widthofrects); if (qpWidthSegment == null) { return; } if (!firstLine) { widthPoints.Add(qpWidthSegment); } else { widthPointsMain.Add(qpWidthSegment); } //AddGraphicToMap((IMap)GetActiveView, qpWidthSegment, rgbColor, rgbColor); if (i != NumberOfRectsinWidth - 1) { IPoint qpWidthSegmentWithDistance = GetQPWidthNewSegment(newPath, distanceAlongWidthBunderiesPoints + Widthofrects + distanceAlongWidth); //AddGraphicToMap((IMap)GetActiveView, qpWidthSegmentWithDistance, rgbColor, rgbColor); if (!firstLine) { widthPoints.Add(qpWidthSegmentWithDistance); } else { widthPointsMain.Add(qpWidthSegmentWithDistance); } } //widthPoints.Add(qpWidthSegment); //widthPoints.Add(qpWidthSegmentWithDistance); distanceAlongWidthBunderiesPoints = (Widthofrects + distanceAlongWidth) * (i + 1); } //IRgbColor rgbColor1 = GetColor(0, 255, 0); if (widthPoints.Count > 0 && widthPointsMain.Count > 0) { //IFeatureClass rectsFeatureClass = getFeatureClass.GetFeatureClassFromShapefileOnDisk(shapefileLocation, out workspace); if (rectsFeatureClass == null) { return; } createRects.FeatureClass = rectsFeatureClass; createRects.SpatialReference = ((IGeoDataset)rectsFeatureClass).SpatialReference; createRects.WidthPoints = widthPoints; createRects.WidthPointsMain = widthPointsMain; createRects.CreateFeatures(); widthPoints.Clear(); widthPointsMain.Clear(); //if(!ShapefileIsAdded()) AddShapefile(GetActiveView, shapefileLocation); } firstLine = !firstLine; //AddGraphicToMap((IMap)GetActiveView, outPutPoint, rgbColor1, rgbColor1); } labelStatus.Text = "It's done."; WorkspaceEdit.StopEditOperation(); WorkspaceEdit.StopEditing(true); GetActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); GetActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } } catch (Exception ex) { Path = null; graphicsContainer.DeleteAllElements(); labelStatus.Text = ex.Message; if (WorkspaceEdit != null) { if (WorkspaceEdit.IsBeingEdited()) { WorkspaceEdit.AbortEditOperation(); WorkspaceEdit.StopEditing(false); } } GetActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
private void UnionFeatures(IEnumFeature selectedFeatures) { IFeature feature = null; IGeometry geometry = null; object missing = Type.Missing; selectedFeatures.Reset(); feature = selectedFeatures.Next(); if (feature == null) { return; } IFeatureClass featureClass = feature.Class as IFeatureClass; IGeometryCollection geometries = new GeometryBagClass(); while (feature != null) { geometry = feature.ShapeCopy; geometries.AddGeometry(geometry, ref missing, ref missing); feature = selectedFeatures.Next(); } ITopologicalOperator unionedGeometry = null; switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryMultipoint: unionedGeometry = new MultipointClass(); break; case esriGeometryType.esriGeometryPolyline: unionedGeometry = new PolylineClass(); break; case esriGeometryType.esriGeometryPolygon: unionedGeometry = new PolygonClass(); break; default: break; } unionedGeometry.ConstructUnion(geometries as IEnumGeometry); ITopologicalOperator2 topo = unionedGeometry as ITopologicalOperator2; topo.IsKnownSimple_2 = false; topo.Simplify(); IFeatureClass targetFeatureClass = currentLayer.FeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } try { workspaceEdit.StartEditOperation(); IFeature unionedFeature = targetFeatureClass.CreateFeature(); unionedFeature.Shape = unionedGeometry as IGeometry; unionedFeature.Store(); workspaceEdit.StopEditOperation(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); MessageBox.Show("要素合并失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnSubmit_Click(object sender, EventArgs e) { //1煤2碳化灰岩3粉砂质泥岩4泥岩5泥质粉砂岩 IWorkspaceEdit workspaceEdit = null; try { labelSC.Visible = true; Application.DoEvents(); //去除无用空行 for (int i = 0; i < dgrdvZhzzt.RowCount - 1; i++) { if (this.dgrdvZhzzt.Rows[i].Cells[0].Value == null && this.dgrdvZhzzt.Rows[i].Cells[1].Value == null && this.dgrdvZhzzt.Rows[i].Cells[2].Value == null) { this.dgrdvZhzzt.Rows.RemoveAt(i); } } //验证 if (!check()) { this.DialogResult = DialogResult.None; return; } this.DialogResult = DialogResult.OK; if (isadd) { bid = IDGenerator.NewBindingID(); } //实体赋值 Histogram historam = new Histogram(); historam.HistogramEntName = txtname.Text.Trim(); historam.BLC = Convert.ToDouble(txtBlc.Text.Trim()); historam.ID = bid; historam.listMY = new List <Historgramlist>(); double height = 0; for (int i = 0; i < dgrdvZhzzt.RowCount - 1; i++) { Historgramlist hisl = new Historgramlist(); hisl.BID = bid; hisl.Index = (i + 1); //煤岩名称 DataGridViewTextBoxCell cell = dgrdvZhzzt.Rows[i].Cells[0] as DataGridViewTextBoxCell; hisl.MYName = cell.Value.ToString(); cell = dgrdvZhzzt.Rows[i].Cells[1] as DataGridViewTextBoxCell; hisl.Height = Convert.ToDouble(cell.Value.ToString()); height += hisl.Height; hisl.SHeight = height; hisl.ZZType = ZZStrToCode(dgrdvZhzzt.Rows[i].Cells[2].Value.ToString()); cell = dgrdvZhzzt.Rows[i].Cells[3] as DataGridViewTextBoxCell; if (cell.Value != null) { hisl.Describe = cell.Value.ToString(); } historam.listMY.Add(hisl); } if (!isadd) { DataEditCommon.DeleteFeatureByWhereClause(frmZhzzt.pFeatureClass, "BID='" + bid + "'"); } progressBar1.Maximum = historam.listMY.Count * 6 + 9; progressBar1.Value = 0; IFeatureClass pFeatureClass = frmZhzzt.pFeatureClass; progressBar1.Value += 1; Application.DoEvents(); IDataset dataset = (IDataset)pFeatureClass; IWorkspace workspace = dataset.Workspace; workspaceEdit = workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); ISegmentCollection pSegmentCollection = new PolygonClass(); double xbasic = 100; double xmin = xbasic, ymin = 99.5, xmax = 110, ymax = 100; List <IGeometry> listgeo = new List <IGeometry>(); IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(xmin, ymin, xmax, ymax); List <ziduan> listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", historam.HistogramEntName)); listzd.Add(new ziduan("zztype", "6")); listzd.Add(new ziduan("strtype", "1")); listzd.Add(new ziduan("bilici", historam.BLC.ToString())); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); ymax = ymin; ymin -= 0.3; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "比例 1:" + historam.BLC.ToString() + " 单位:米")); listzd.Add(new ziduan("zztype", "6")); listzd.Add(new ziduan("strtype", "2")); listzd.Add(new ziduan("bilici", historam.BLC.ToString())); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); ymax = ymin; ymin -= 0.3; xmax = xmin + 0.6; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "序号")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1.8; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "煤 岩 名 称")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 0.8; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "真厚")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "累厚")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1.2; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "柱 状")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 4.6; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "岩 性 描 述")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); List <Historgramlist> list = historam.ListMY; for (int i = 0; i < list.Count; i++) { xmin = xbasic; double m_height = list[i].Height; if (m_height < 0.3) { m_height = 0.3; } pEnvelope = new EnvelopeClass(); ymax = ymin; ymin -= m_height; xmax = xmin + 0.6; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "1")); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1.8; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", list[i].MYName)); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "2")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 0.8; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", list[i].Height.ToString())); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "3")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", Math.Round(list[i].SHeight, 1).ToString())); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "4")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 1.2; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); listzd.Add(new ziduan("textstr", "")); listzd.Add(new ziduan("zztype", list[i].ZZType)); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "5")); listzd.Add(new ziduan("strtype", "0")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); pEnvelope = new EnvelopeClass(); xmin = xmax; xmax += 4.6; pEnvelope.PutCoords(xmin, ymin, xmax, ymax); listzd = new List <ziduan>(); string strms = list[i].Describe; string miaoshu = ""; if (strms != null && strms.Length > 0) { ASCIIEncoding ascii = new ASCIIEncoding(); int temLen = 0; byte[] s = ascii.GetBytes(strms); for (int j = 0; j < s.Length; j++) { if ((int)s[j] == 63) { temLen += 2; } else { temLen += 1; } miaoshu += strms[j]; if (temLen % 38 == 0 || (temLen + 1) % 38 == 0) { if (miaoshu.LastIndexOf('|') != miaoshu.Length - 1) { miaoshu += "|"; } } } } listzd.Add(new ziduan("textstr", miaoshu)); listzd.Add(new ziduan("zztype", "0")); listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString())); listzd.Add(new ziduan("xuhaoC", "6")); listzd.Add(new ziduan("strtype", "3")); listzd.Add(new ziduan("BID", historam.ID)); pSegmentCollection = new PolygonClass(); pSegmentCollection.SetRectangle(pEnvelope); DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd); listgeo.Add(pSegmentCollection as IGeometry); progressBar1.Value += 1; Application.DoEvents(); } workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); frmZhzzt.pGeometry = MyMapHelp.GetGeoFromGeos(listgeo); frmZhzzt.BID = historam.ID; frmZhzzt.blc = historam.BLC; DialogResult = DialogResult.OK; this.Close(); if (!isadd) { frmZhzzt.refresh(); } } catch (Exception ex) { labelSC.Visible = false; MessageBox.Show(ex.Message); if (workspaceEdit != null) { workspaceEdit.AbortEditOperation(); workspaceEdit.StopEditing(false); } } }
private void CutSelectedPolygon() { if (m_selectedFeature == null) { MessageBox.Show("请先选择要分割的面要素!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); m_toolPhase = ToolPhase.SelectFeature; return; } //在屏幕上绘制用于分割的线要素 IScreenDisplay screenDisplay = m_activeView.ScreenDisplay; ISimpleLineSymbol sym = new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass(); color.Red = 255; color.Green = 128; color.Blue = 128; sym.Color = color; sym.Style = esriSimpleLineStyle.esriSLSSolid; sym.Width = 2; IRubberBand cutBand = new RubberLineClass(); IGeometry cutGeometry = cutBand.TrackNew(screenDisplay, sym as ISymbol); screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache); screenDisplay.SetSymbol(sym as ISymbol); screenDisplay.DrawPolyline(cutGeometry); screenDisplay.FinishDrawing(); IFeatureClass featureClass = m_selectedFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } //分割选择的面要素 if (cutGeometry.IsEmpty == true) { return; } try { workspaceEdit.StartEditOperation(); IFeatureEdit featureEdit = m_selectedFeature as IFeatureEdit; //分割产生新的面要素 ISet newFeaturesSet = featureEdit.Split(cutGeometry); //亮闪新要素 if (newFeaturesSet != null) { newFeaturesSet.Reset(); for (int featureCount = 0; featureCount < newFeaturesSet.Count; featureCount++) { IFeature newFeature = newFeaturesSet.Next() as IFeature; FlashGeometry(newFeature.Shape, 3, 20); } } workspaceEdit.StopEditOperation(); } catch (Exception ex) { workspaceEdit.AbortEditOperation(); //SysLogHelper.WriteOperationLog("要素分割错误", ex.Source, "数据编辑"); MessageBox.Show("分割面要素失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); m_toolPhase = ToolPhase.SelectFeature; }
//分割要素 private bool splitFeature(IGeometry pGeometry) { IFeatureLayer curLayer = getEditLayer.isExistLayer(m_MapControl.Map) as IFeatureLayer; if (curLayer == null) { return(false); } IFeatureSelection curLayerSn = curLayer as IFeatureSelection; bool hasCut = false; //空间查询,找出被切割要素 ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = pGeometry; if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelRelation; spatialFilter.SpatialRelDescription = "TTTFFTTTT"; } else if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; } IFeatureClass featureClass = curLayer.FeatureClass; IWorkspaceEdit iWE = (featureClass as IDataset).Workspace as IWorkspaceEdit; if (!iWE.IsBeingEdited()) { iWE.StartEditing(false); } System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; try { IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false); IFeature origFeature = featureCursor.NextFeature(); if (origFeature != null) { //检查第一个要素是否Z敏感则将切割线设成Z敏感 IZAware zAware = origFeature.Shape as IZAware; if (zAware.ZAware) { zAware = pGeometry as IZAware; zAware.ZAware = true; } ArrayList comErrors = new ArrayList(); //开始操作 iWE.StartEditOperation(); //循环空间查询的要素,执行切割 while (origFeature != null) { try { //切割要素,IFeatureEdit.Split此方法可自动处理属性 IFeatureEdit featureEdit = origFeature as IFeatureEdit; ISet newFeaturesSet = null; //保存切割生成的新要素的集合 //若源要素是线,则切割图形是交点 if (curLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { ITopologicalOperator iTo = pGeometry as ITopologicalOperator; IGeometry pTmpG = iTo.Intersect(origFeature.ShapeCopy, esriGeometryDimension.esriGeometry0Dimension); IPointCollection pTmpPc = pTmpG as IPointCollection; for (int i = pTmpPc.PointCount - 1; i >= 0; i--) { //newFeaturesSet = featureEdit.Split(pTmpG); newFeaturesSet = featureEdit.Split(pTmpPc.get_Point(pTmpPc.PointCount - 1)); //新要素已经生成 if (newFeaturesSet != null) { newFeaturesSet.Reset(); IFeature pSplitFeature = null; pSplitFeature = newFeaturesSet.Next() as IFeature; //IFeatureEdit tmpFE = pSplitFeature as IFeatureEdit; while (pSplitFeature != null) { //闪烁新要素 m_MapControl.FlashShape(pSplitFeature.ShapeCopy, 1, 300, Type.Missing); pSplitFeature = newFeaturesSet.Next() as IFeature; } hasCut = true; } } } //如果是面,切割图形是线 else { newFeaturesSet = featureEdit.Split(pGeometry); //新要素已经生成 if (newFeaturesSet != null) { newFeaturesSet.Reset(); IFeature pSplitFeature = null; pSplitFeature = newFeaturesSet.Next() as IFeature; while (pSplitFeature != null) { //闪烁新要素 m_MapControl.FlashShape(pSplitFeature.ShapeCopy, 1, 300, Type.Missing); pSplitFeature = newFeaturesSet.Next() as IFeature; } hasCut = true; } } } catch (COMException comExc) { comErrors.Add(String.Format("OID: {0}, 错误: {1} , {2}", origFeature.OID.ToString(), comExc.ErrorCode, comExc.Message)); } finally { //当前的失败,则继续下一个 origFeature = featureCursor.NextFeature(); } } //如果有切割动作,则刷新视图并保存 if (hasCut) { //清除地图选择集 m_MapControl.Map.ClearSelection(); //刷新视图 m_MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, m_MapControl.ActiveView.Extent); //完成编辑操作 iWE.StopEditOperation(); } else { iWE.AbortEditOperation(); } //报告错误 if (comErrors.Count > 0) { StringBuilder stringBuilder = new StringBuilder("以下要素不能被切割: \n", 200); foreach (string comError in comErrors) { stringBuilder.AppendLine(comError); } MessageBox.Show(stringBuilder.ToString(), "切割错误"); } } } catch (Exception ex) { ErrorHandle.ShowFrmErrorHandle("提示", "切割失败!\r\n" + ex.Message); iWE.AbortEditOperation(); } finally { System.Windows.Forms.Cursor.Current = Cursors.Default; } return(hasCut); }