//撤销 public static void UndoEdit(AxMapControl axmap, ILayer player) { // Check that editing is possible m_CurrentLayer = player; m_MapControl = axmap; if (m_CurrentLayer == null) { return; } IFeatureLayer pFeatureLayer = (IFeatureLayer)m_CurrentLayer; IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass; if (pDataset == null) { return; } /// If edits have taken place then roll-back the last one IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; bool bHasUndos = false; pWorkspaceEdit.HasUndos(ref bHasUndos); if (bHasUndos) { pWorkspaceEdit.UndoEditOperation(); } IActiveView pActiveView = (IActiveView)m_MapControl.Map; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent); pActiveView.Refresh(); }
/// <summary> /// 撤消以前所做的编辑 /// </summary> public void UndoEdit() { bool bHasUndos = false; try { if (m_pCurrentLayer == null) { return; } IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass; if (pDataset == null) { return; } IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; pWorkspaceEdit.HasUndos(ref bHasUndos); if (bHasUndos) { pWorkspaceEdit.UndoEditOperation(); } IActiveView pActiveView = (IActiveView)m_pMap; pActiveView.Refresh(); } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } }
/// <summary> /// 撤销编辑 /// </summary> /// <param name="workspaceEdit">编辑</param> private static void UndoEdit(IWorkspaceEdit workspaceEdit) { if (!workspaceEdit.IsBeingEdited()) { return; } //撤销编辑 workspaceEdit.UndoEditOperation(); workspaceEdit.StopEditing(false); }
/// <summary> /// 撤销操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void m_undotool_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (pEngineEditor != null && pEngineEditor.EditState == esriEngineEditState.esriEngineStateEditing) { m_redotool.Enabled = true; IWorkspaceEdit workspaceedit = (IWorkspaceEdit)pEngineEditor.EditWorkspace; bool bHasUndo = true; workspaceedit.HasUndos(ref bHasUndo); if (bHasUndo) { workspaceedit.UndoEditOperation(); ((IActiveView)m_mapControl.Map).Refresh(); } } }
public void OnClick() { try { m_Map = m_hookHelper.FocusMap; m_activeView = m_Map as IActiveView; m_EngineEditor = MapManager.EngineEditor; EditVertexClass.ClearResource(); if (m_EngineEditor == null) { return; } if (m_EngineEditor.EditState != esriEngineEditState.esriEngineStateEditing) { return; } //此处应为IWorkspaceEdit,若为IWorkspaceEdit2无法强制转换 IWorkspaceEdit pWSEdit = m_EngineEditor.EditWorkspace as IWorkspaceEdit; IWorkspace pWorkspace = m_EngineEditor.EditWorkspace; if (pWSEdit == null) { return; } Boolean bHasUndo = true; if (pWorkspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { m_EngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeNonVersioned; } //m_EngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; pWSEdit.HasUndos(ref bHasUndo); if (bHasUndo) { pWSEdit.UndoEditOperation(); } m_activeView.Refresh(); } catch (Exception ex) { //SysLogHelper.WriteOperationLog("编辑恢复错误", ex.Source, "数据编辑"); } }
public void UndoEdit() { if (MyselectedLayer == null) { return; } IFeatureLayer featLayer = MyselectedLayer as IFeatureLayer; IDataset dataset = featLayer.FeatureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; bool bHasUndos = false; workspaceEdit.HasUndos(ref bHasUndos); if (bHasUndos) { workspaceEdit.UndoEditOperation(); } ClearSelection(); }
public override void OnClick() { if (m_Hook == null) { return; } //LogFile log = new LogFile(m_Hook.tipRichBox, m_Hook.strLogFilePath); //if (log != null) //{ // log.Writelog("鹰眼图设置"); //} if (m_Hook.ArcGisMapControl.Map.LayerCount == 0) { MessageBox.Show("当前没有调阅数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { IWorkspaceEdit iWE = ((getEditLayer.isExistLayer(m_Hook.ArcGisMapControl.Map) as IFeatureLayer).FeatureClass as IDataset).Workspace as IWorkspaceEdit; if (iWE.IsBeingEdited()) { bool hasEdits = false; iWE.HasUndos(ref hasEdits); if (hasEdits && MessageBox.Show("是否撤销编辑?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { iWE.UndoEditOperation(); } } m_Hook.ArcGisMapControl.ActiveView.Refresh(); iWE = null; } catch { } }
public void DeleteFeature(string featureClass, string whereClause) { Exception methodException = null; bool bError = false; IFeatureClass fc = GetFeatureClass(featureClass); if (fc == null) { return; } IWorkspaceEdit ipWksEdit = ((IDataset)fc).Workspace as IWorkspaceEdit; if (null != ipWksEdit) { try { ipWksEdit.StartEditing(true); ipWksEdit.StartEditOperation(); } catch { bError = true; return; } } try { IQueryFilter query = (IQueryFilter)_serverContext.CreateObject("esriGeoDatabase.QueryFilter"); query.WhereClause = whereClause; IFeatureCursor fcur = fc.Search(query, false); // Delete them all IFeature currentFeature = fcur.NextFeature(); while (currentFeature != null) { currentFeature.Delete(); currentFeature = fcur.NextFeature(); } query = null; } catch (Exception e) { methodException = e; bError = true; } if (null != ipWksEdit) { try { if (bError) { //rollback ipWksEdit.UndoEditOperation(); ipWksEdit.StopEditing(false); } else { //commit ipWksEdit.StopEditOperation(); ipWksEdit.StopEditing(true); } } catch { } finally { ipWksEdit = null; } } if (methodException != null) { throw methodException; } }
public void UpdateFeature(string featureClasses, List <FeatureValues> featureValues, double[] Coordinates, string sID, string sFieldName) { bool bError = false; IFeatureClass fc = GetFeatureClass(featureClasses); IWorkspaceEdit ipWksEdit = ((IDataset)fc).Workspace as IWorkspaceEdit; if (null != ipWksEdit) { try { ipWksEdit.StartEditing(true); ipWksEdit.StartEditOperation(); } catch { bError = true; return; } } // the meat to update the feature foreach (FeatureValues featureValue in featureValues) { featureValue.Index = fc.Fields.FindField(featureValue.Name); } IQueryFilter pQueryFilter = (IQueryFilter)_serverContext.CreateObject("esriGeoDatabase.QueryFilter"); pQueryFilter.WhereClause = sFieldName + "='" + sID + "'"; IFeatureCursor cursor = fc.Update(pQueryFilter, false); IFeature pFeature; while ((pFeature = cursor.NextFeature()) != null) { if (Coordinates != null && Coordinates.Length == 2) { double[] points = Coordinates; ESRI.ArcGIS.Geometry.IPoint pt = (ESRI.ArcGIS.Geometry.IPoint)_serverContext.CreateObject("esriGeometry.Point"); pt.PutCoords(points[0], points[1]); pFeature.Shape = pt as ESRI.ArcGIS.Geometry.IPoint; } else if (Coordinates != null && Coordinates.Length > 2) { ESRI.ArcGIS.Geometry.IPointCollection pPointCol = _serverContext.CreateObject("esriGeometry.Polygon") as ESRI.ArcGIS.Geometry.IPointCollection; for (int i = 0; i < Coordinates.Length; i += 2) { ESRI.ArcGIS.Geometry.IPoint pt = (ESRI.ArcGIS.Geometry.IPoint)_serverContext.CreateObject("esriGeometry.Point"); pt.PutCoords(Coordinates[i], Coordinates[i + 1]); pPointCol.AddPoints(1, ref pt); } pFeature.Shape = pPointCol as ESRI.ArcGIS.Geometry.IPolygon; } break; } pFeature.Store(); if (null != ipWksEdit) { try { if (bError) { //rollback ipWksEdit.UndoEditOperation(); ipWksEdit.StopEditing(false); } else { //commit ipWksEdit.StopEditOperation(); ipWksEdit.StopEditing(true); } } catch { } finally { Marshal.ReleaseComObject(ipWksEdit); ipWksEdit = null; } } }
/// <summary> /// Occurs when this tool is clicked /// </summary> public override void OnClick() { //1 Getting data that needs lossy compression (Data is stored in the form of feature class) IFeatureLayer feaLyr = TargetLayerSelector.OperateLyr as IFeatureLayer; IFeatureClass targetFeaClass = feaLyr.FeatureClass; IDataset dataSet = targetFeaClass as IDataset; workspaceEdit = dataSet.Workspace as IWorkspaceEdit; int elementIdIndex = targetFeaClass.FindField("id"); //Get attribute address int encodingIndex = targetFeaClass.FindField("GosperId"); //If lossy compression of row encoding is carried out, replace "GosperId" here with "RowId" int typeIndex = targetFeaClass.FindField("type"); //2 Information statistics before fusion // Get the element Id set List <int> idList = new List <int>(); IFeatureCursor feaCursor = targetFeaClass.Search(null, false); IFeature fea = null; while ((fea = feaCursor.NextFeature()) != null) { string feaIdStr = fea.get_Value(elementIdIndex).ToString(); if (feaIdStr == "") { continue; } int feaId = int.Parse(feaIdStr); //Store the Id set using the list if (!idList.Contains(feaId)) { idList.Add(feaId); } } //2.1 Number statistics of adjacent sequences before fusion List <int> beforeElementAdjSeqNumList = new List <int>(); //Number of adjacency sequences in element regions before fusion List <int> afterElementAdjSeqNumList = new List <int>(); //Number of adjacency sequences in element regions after fusion List <int> elementStraightforwardEncAmtList = new List <int>(); //Total straightforward encoding amount of element regions IQueryFilter qf1 = new QueryFilterClass(); //Element querier for (int i = 0; i < idList.Count; i++) { int adjSeqNum = 0; //Adjacency sequences counting variable List <int> elementEncodingList = new List <int>(); //Storage element encoding set (Gosper encoding or Row encoding based on specific task type) // Get the set of element encoding qf1.WhereClause = "id = " + idList[i]; IFeatureCursor feaCursor1 = targetFeaClass.Search(qf1, false); IFeature unitFea = null; while ((unitFea = feaCursor1.NextFeature()) != null) { elementEncodingList.Add(int.Parse(unitFea.get_Value(encodingIndex).ToString())); } elementEncodingList.Sort(); // Statistical number of adjacency sequences int tempEncoding = elementEncodingList[0]; int currentEncoding = tempEncoding; for (int j = 1; j < elementEncodingList.Count; j++) { tempEncoding = elementEncodingList[j]; //Encoding breaks, update the number of adjacency sequences if (tempEncoding != currentEncoding + 1) { adjSeqNum++; } currentEncoding = tempEncoding; } //Add the last adjacency sequence adjSeqNum++; //Store the adjacency sequences amount and straightforward encoding amount of the region before fusion beforeElementAdjSeqNumList.Add(adjSeqNum); elementStraightforwardEncAmtList.Add(elementEncodingList.Count); } //3 Fusion process //Output address settings for experimental results string filePath = System.IO.Directory.GetCurrentDirectory() + "\\FolderName"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string txtPath = filePath + "\\FileName" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; StreamWriter sw = new StreamWriter(txtPath, true); //Turn on editing control StartEdit(); int FusionThreshold = 1;//Setting fusion threshold (In this experiment, set 1,2,3 respectively.) //3.1 Intermediate absorption fusion for (int i = 0; i < idList.Count; i++) { //Store element encoding set List <int> elementEncodingList = new List <int>(); // Get the set of element encoding qf1.WhereClause = "id =" + idList[i]; IFeatureCursor feaCursor1 = targetFeaClass.Search(qf1, false); IFeature unitFea = null; while ((unitFea = feaCursor1.NextFeature()) != null) { elementEncodingList.Add(int.Parse(unitFea.get_Value(encodingIndex).ToString())); } elementEncodingList.Sort(); // Fusion of adjacency sequences according to thresholds int tempEncoding = elementEncodingList[0]; int currentEncoding = tempEncoding; IQueryFilter qf = new QueryFilterClass(); for (int j = 1; j < elementEncodingList.Count; j++) { tempEncoding = elementEncodingList[j]; //Adjacent encoding if (tempEncoding == currentEncoding + 1) { currentEncoding = tempEncoding; continue; } //Fusion within the threshold range else if (currentEncoding + FusionThreshold >= tempEncoding) { bool isBreak = false;//Indicators for judging whether regional breaks occur //Open editing operation workspaceEdit.StartEditOperation(); //Change the belonging attribution of the fused unit for (int k = currentEncoding + 1; k < tempEncoding; k++) { qf.WhereClause = "GosperId =" + k; IFeature searchFea = targetFeaClass.Search(qf, false).NextFeature(); string FusionElementId = searchFea.get_Value(elementIdIndex).ToString(); searchFea.set_Value(elementIdIndex, idList[i]); //Change the belonging attribution searchFea.set_Value(typeIndex, 1); //Set the change type 1:absorption fusion -1:release fusion searchFea.Store(); //Check whether regional break occurs after fusion in the element region corresponding to the unit if (FusionElementId == "") { continue; } isBreak = isRegionalBreak(targetFeaClass, int.Parse(FusionElementId.ToString())); if (isBreak) { break; } } //Close editing operation workspaceEdit.StopEditOperation(); //As long as there is a break in one element region, the fusion will be cancelled and recover to its original state. if (isBreak) { workspaceEdit.UndoEditOperation(); } } currentEncoding = tempEncoding; } } //3.2 Terminal fusion for (int i = 0; i < idList.Count; i++) { //Store element encoding set List <int> elementEncodingList = new List <int>(); // Get the set of element encoding qf1.WhereClause = "id =" + idList[i]; // '" + idList[i] + "'"; IFeatureCursor feaCursor1 = targetFeaClass.Search(qf1, false); IFeature unitFea = null; while ((unitFea = feaCursor1.NextFeature()) != null) { elementEncodingList.Add(int.Parse(unitFea.get_Value(encodingIndex).ToString())); } elementEncodingList.Sort(); //Extraction of short adjacency sequences satisfying threshold constraints List <int> shortAdjSeq = new List <int>(); int tempEncoding = elementEncodingList[0]; int currentEncoding = tempEncoding; shortAdjSeq.Add(tempEncoding); IQueryFilter qf = new QueryFilterClass(); for (int j = 1; j < elementEncodingList.Count; j++) { tempEncoding = elementEncodingList[j]; //When encoding discontinuity occurs, the adjacency sequence length is judged. if (tempEncoding != currentEncoding + 1) { //Fusion of short adjacency sequences satisfying threshold constraints if (shortAdjSeq.Count <= FusionThreshold) { //Random search for element region adjacent to short adjacent sequence int shortHead = shortAdjSeq[0]; int shortTail = shortAdjSeq[shortAdjSeq.Count - 1]; qf = new QueryFilterClass(); qf.WhereClause = "GosperId =" + (shortHead - 1) + "OR GosperId =" + (shortTail + 1); IFeatureCursor feaCursorNeighbour = targetFeaClass.Search(qf, false); IFeature neighbourElement = feaCursorNeighbour.NextFeature(); if (neighbourElement != null) { bool isBreak = false; //Open editing operation workspaceEdit.StartEditOperation(); //Modifying the belonging attribution of units corresponding to short adjacency sequences for (int k = 0; k < shortAdjSeq.Count; k++) { qf.WhereClause = "GosperId =" + shortAdjSeq[k]; IFeature shortFea = targetFeaClass.Search(qf, false).NextFeature(); shortFea.set_Value(elementIdIndex, neighbourElement.get_Value(elementIdIndex)); //Change the belonging attribution shortFea.set_Value(typeIndex, -1); //Set the change type 1:absorption fusion -1:release fusion shortFea.Store(); } //Check whether regional break occurs after fusion in the element region isBreak = isRegionalBreak(targetFeaClass, idList[i]); workspaceEdit.StopEditOperation(); //If there is a break in element region, the fusion will be cancelled and recover to its original state. if (isBreak) { workspaceEdit.UndoEditOperation(); } } } shortAdjSeq = new List <int>(); shortAdjSeq.Add(tempEncoding); currentEncoding = tempEncoding; } else { shortAdjSeq.Add(tempEncoding); currentEncoding = tempEncoding; } } //Last adjacency sequence processing if (shortAdjSeq.Count <= FusionThreshold) { int shortHead = shortAdjSeq[0]; int shortTail = shortAdjSeq[shortAdjSeq.Count - 1]; qf = new QueryFilterClass(); qf.WhereClause = "GosperId =" + (shortHead - 1) + "OR GosperId =" + (shortTail + 1); IFeatureCursor feaCursorNeighbour = targetFeaClass.Search(qf, false); IFeature neighbourElement = feaCursorNeighbour.NextFeature(); if (neighbourElement != null) { bool isBreak = false; workspaceEdit.StartEditOperation(); for (int k = 0; k < shortAdjSeq.Count; k++) { qf.WhereClause = "GosperId =" + shortAdjSeq[k]; IFeature shortFea = targetFeaClass.Search(qf, false).NextFeature(); shortFea.set_Value(elementIdIndex, neighbourElement.get_Value(elementIdIndex)); shortFea.set_Value(typeIndex, -1); shortFea.Store(); } isBreak = isRegionalBreak(targetFeaClass, idList[i]); workspaceEdit.StopEditOperation(); if (isBreak) { workspaceEdit.UndoEditOperation(); } } shortAdjSeq = null; } } //Turn off editing control, save results StopAndCommitEdit(); //4 Information statistics after fusion qf1 = new QueryFilterClass(); for (int i = 0; i < idList.Count; i++) { int adjSeqNum = 0; //Adjacency sequences counting variable List <int> elementEncodingList = new List <int>(); //Storage element encoding set (Gosper encoding or Row encoding based on specific task type) // Get the set of element encoding qf1.WhereClause = "id =" + idList[i]; IFeatureCursor feaCursor1 = targetFeaClass.Search(qf1, false); IFeature unitFea = null; while ((unitFea = feaCursor1.NextFeature()) != null) { elementEncodingList.Add(int.Parse(unitFea.get_Value(encodingIndex).ToString())); } elementEncodingList.Sort(); // Statistical number of adjacency sequences int tempEncoding = elementEncodingList[0]; int currentEncoding = tempEncoding; for (int j = 1; j < elementEncodingList.Count; j++) { tempEncoding = elementEncodingList[j]; //Encoding breaks, update the number of adjacency sequences if (tempEncoding != currentEncoding + 1) { adjSeqNum++; } currentEncoding = tempEncoding; } //Add the last adjacency sequence adjSeqNum++; //Store the adjacency sequences amount of the region after fusion afterElementAdjSeqNumList.Add(adjSeqNum); } //5 Output statistics double beforeAdjSeqNumSum = 0; //Total number of adjacency sequences before fusion double afterAdjSeqNumSum = 0; //Total number of adjacency sequences after fusion double straightforwardEncAmtSum = 0; //Total straightforward encoding amount for (int i = 0; i < idList.Count; i++) { double beforeAdjSeqNum = beforeElementAdjSeqNumList[i]; double afterAdjSeqNum = afterElementAdjSeqNumList[i]; double straightforwardEncAmt = elementStraightforwardEncAmtList[i]; //Output statistical information of element region sw.WriteLine("Element Id," + idList[i] + ",Number of adjacency sequences before fusion," + beforeAdjSeqNum + ",Number of adjacency sequences after fusion," + afterAdjSeqNum + ",Fusion rate," + (1 - afterAdjSeqNum / beforeAdjSeqNum) + ",compression rate," + (afterAdjSeqNum * 2) / straightforwardEncAmt); //Update the overall information beforeAdjSeqNumSum += beforeAdjSeqNum; afterAdjSeqNumSum += afterAdjSeqNum; straightforwardEncAmtSum += straightforwardEncAmt; } //Output overall statistical information sw.WriteLine(targetFeaClass.AliasName + "综合统计融合前总段数," + beforeAdjSeqNumSum + ",融合后总段数," + afterAdjSeqNumSum + ",总融合率," + (1 - afterAdjSeqNumSum / beforeAdjSeqNumSum) + ",总压缩率," + (afterAdjSeqNumSum * 2) / straightforwardEncAmtSum); sw.Flush(); sw.Close(); MessageBox.Show("OK"); }