年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

140 lines
5.6 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.AE;
using KGIS.Framework.EngineEditor;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kingo.Plugin.EngineEditor.Commands.Tools
{
/// <summary>
/// 提取地类图斑到变更范围
/// </summary>
public class CmdWithDrawBGFW : BaseToolCmd
{
private EngineEditorClass editor = new EngineEditorClass();
private IHookHelper m_hookHelper;
private IFeatureLayer TargetLayer = null;
public override void OnCreate(object hook)
{
try
{
base.OnCreate(hook);
if (this.m_hookHelper == null)
{
this.m_hookHelper = base.m_pHookHelper;
}
editor.OnStopEditing += Editor_OnStopEditing;
base.OnCreate(hook);
}
catch (Exception ex)
{
LogAPI.Debug("提取图斑初始化OnCreate异常:" + ex.Message);
}
}
public override void OnClick()
{
base.OnClick();
if (editor != null && (editor as EngineEditorClass).TargetLayer != null)
TargetLayer = (editor as EngineEditorClass).TargetLayer as IFeatureLayer;
if (TargetLayer == null || ((IDataset)TargetLayer.FeatureClass).Name != "DLTBBG") return;//获取任务图斑图层
(editor as EngineEditorClass).StartOperation();
try
{
IFeature selectedFeature = null;
if (m_hookHelper.FocusMap.FeatureSelection is IEnumFeature)
{
IEnumFeature enumFeature = m_hookHelper.FocusMap.FeatureSelection as IEnumFeature;
while ((selectedFeature = enumFeature.Next()) != null)
{
if (((IDataset)selectedFeature.Class).Name != "DLTB") continue;
if (MessageHelper.ShowYesNoAndTips($"是否从“{((IDataset)selectedFeature.Class).Name}”图层中,提取图斑?") == System.Windows.Forms.DialogResult.Yes)
{
break;
}
else
selectedFeature = null;
}
if (selectedFeature == null)
{
MessageHelper.ShowTips("请选择地类图斑提取!");
return;
}
List<IFeature> features = FeatureAPI.Identify2(selectedFeature.ShapeCopy, TargetLayer);
if (features == null || features.Count == 0)
{
MessageHelper.ShowTips("当前提取地类图斑并未压盖到变更范围!");
return;
}
// 结束事务(可选)
(editor as EngineEditorClass).StopOperation("提取变更范围");
(editor as EngineEditorClass).StopEditing(true);
Platform.Instance.SendMsg(new NotifyMsgPackage() { MsgType = "WithDrawTBToTreeNode", Content = selectedFeature.OID });
(m_hookHelper.FocusMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, TargetLayer, null);
// 释放资源
if (selectedFeature != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(selectedFeature);
//重新开启编辑,不受保存编辑影响
(editor as EngineEditorClass).StartEditing((TargetLayer.FeatureClass as FeatureClass).Workspace, MapsManager.Instance.MapService.getAxMapControl().Map);
IEngineEditLayers pEditLayer = editor as IEngineEditLayers;
pEditLayer.SetTargetLayer(TargetLayer, 0);
MessageHelper.ShowTips("提取变更范围成功!");
}
}
catch (Exception ex)
{
(editor as EngineEditorClass).AbortOperation();
(editor as EngineEditorClass).StopOperation("提取任务图斑出现异常!");
LogAPI.Debug("提取任务图斑失败:" + ex);
MessageHelper.ShowError("提取任务图斑失败" + ex.Message);
}
finally
{
if (TargetLayer != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(TargetLayer);
}
}
public override bool Enabled
{
get
{
ILayer layer = (editor as EngineEditorClass).TargetLayer;
if (editor.EditState == esriEngineEditState.esriEngineStateEditing && layer != null && (layer as IFeatureLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
{
return true;
}
else
{
return false;
}
}
}
private void Editor_OnStopEditing(bool saveChanges)
{
try
{
(m_hookHelper.Hook as IMapControl2).CurrentTool = null;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
}
}