年度变更建库软件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.

349 lines
13 KiB

6 months ago
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.EngineEditor;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using KGIS.Framework.AE;
using KGIS.Framework.Platform;
using System.Runtime.InteropServices;
using KGIS.Framework.Maps;
namespace Kingo.Plugin.EngineEditor.Commands.Tools
{
public class CmdExtractZZBGFeatureTool : BaseToolCmd
{
public event EventHandler<object> ExtComplete;
IFeatureLayer m_SourceJCDLTBLayer;
IFeatureLayer m_TargetLayer;
private IElement tempElement = null;
List<DataDicTionary> dlbmDic = null;
IPoint MousePoint = null;
ITextElement beforeEl = null;
public string JCBH { get; set; }
public override void OnCreate(object hook)
{
base.OnCreate(hook);
//if (mapService != null)
//{
m_SourceJCDLTBLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JC_DLTB");
//}
maxXH = 0;
}
public override bool Deactivate()
{
if (tempElement != null)
{
try
{
m_pHookHelper.ActiveView.GraphicsContainer.DeleteElement(tempElement);
m_pHookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pHookHelper.ActiveView.Extent);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
tempElement = null;
base.Deactivate();
this.m_deactivate = true;
return this.m_deactivate;
}
public override void OnClick()
{
base.OnClick();
m_TargetLayer = (m_pEditor as EngineEditorClass).TargetLayer as IFeatureLayer;
dlbmDic = Platform.Instance.DicHelper.GetDic(DicTypeEnum.DLBM);
//if (mapService == null)
// mapService = MapsManager.Instance.MapService;
//if (mapService != null)
//{
m_SourceJCDLTBLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
//}
}
public override bool Enabled
{
get
{
if (m_pEditor == null)
{
return false;
}
if (m_pEditor.EditState != esriEngineEditState.esriEngineStateEditing)
{ return false; }
if ((m_pEditor as EngineEditorClass).TargetLayer == null)
{ return false; }
return true;
}
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
if (Button == 2)//鼠标右键
{
MapsManager.Instance.MapService.getAxMapControl().CurrentTool = null;
}
}
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
IPoint point = m_pHookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
List<IFeature> SourceFeatures = FeatureAPI.Identify(point, m_SourceJCDLTBLayer);
if (SourceFeatures.Count == 0) return;
DrawFeature(SourceFeatures[0]);
}
public override void Refresh(int hDC)
{
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
IPoint point = m_pHookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
MousePoint = point;
List<IFeature> TargetFeatures = FeatureAPI.Identify2(point, m_TargetLayer);
m_pEditor.StartOperation();
if (TargetFeatures.Count != 0)
{
if (MessageHelper.ShowYesNoAndTips("是否要删除已提取图斑?") != System.Windows.Forms.DialogResult.Yes)
{
return;
}
foreach (var item in TargetFeatures)
{
item.Delete();
}
return;
}
else
{
List<IFeature> SourceJCDLTBFeatures = FeatureAPI.Identify2(point, m_SourceJCDLTBLayer);
if (SourceJCDLTBFeatures.Count == 0)
{
return;
}
IFeatureClass m_TargetFC = m_TargetLayer.FeatureClass;
IFeatureCursor InsertCursor = m_TargetFC.Insert(true);
IFeatureBuffer buffer = m_TargetFC.CreateFeatureBuffer();
if (SourceJCDLTBFeatures.Count != 0)
{
//未获取到监测图斑,图形从基础地类图斑获取
buffer.Shape = SourceJCDLTBFeatures[0].ShapeCopy;
//属性从基础地类图斑获取
for (int i = 0; i < m_TargetFC.Fields.FieldCount; i++)
{
IField field = m_TargetFC.Fields.Field[i];
if (field.Name.ToUpper() == "OBJECTID" || !field.Editable || field.Name.ToUpper().Contains("SHAPE"))
{
continue;
}
int tarfieldIndex = m_TargetFC.FindField(field.Name);
int sourfieldindex = m_SourceJCDLTBLayer.FeatureClass.FindField(field.Name);
if (tarfieldIndex != -1 && sourfieldindex != -1)
{
buffer.Value[tarfieldIndex] = SourceJCDLTBFeatures[0].Value[sourfieldindex];
}
}
string qsdwdm = SourceJCDLTBFeatures[0].Value[m_SourceJCDLTBLayer.FeatureClass.FindField("ZLDWDM")].ToString();
string xzqdm = qsdwdm.Substring(0, 6);
int index = m_TargetFC.FindField("XZQDM");
if (index != -1)
{
buffer.Value[index] = xzqdm;
}
index = m_TargetFC.FindField("SJLY");
if (index != -1)
{
buffer.Value[index] = "2";
}
index = m_TargetFC.FindField("SFJZ");//是否外业举证
if (index != -1)
{
buffer.Value[index] = "1";
}
index = m_TargetFC.FindField("JCBH");
if (index != -1)
{
buffer.Value[index] = GetMaxJCBH(m_TargetFC, xzqdm);
}
InsertCursor.InsertFeature(buffer);
InsertCursor.Flush();
//KGIS.Framework.Platform.Platform.Instance.SendMsg(new Framework.Utils.Interface.NotifyMsgPackage() { Content = "RefreshTBBGDetail", MsgType = "RefreshTBBGDetail" });
}
}
m_pEditor.StopOperation("提取图形");
}
private int maxXH = 0;
/// <summary>
/// 生成JCBH
/// </summary>
/// <param name="fc"></param>
/// <param name="xzqdm"></param>
/// <returns></returns>
private string GetMaxJCBH(IFeatureClass fc, string xzqdm)
{
string JCBH = "";
string start_jcbh = xzqdm + "DF";
if (maxXH > 0)
{
maxXH++;
}
else
{
IQueryFilter QueryFilter = new QueryFilterClass();
QueryFilter.WhereClause = "SJLY='2'";
if (fc.FeatureCount(QueryFilter) == 0)
{
maxXH = 1;
}
else
{
int JCBHIndex = fc.FindField("JCBH");
ITable table = (ITable)fc;
// 创建一个ITableSort接口对象
ITableSort tableSort = new TableSortClass();
tableSort.Table = table;
tableSort.QueryFilter = QueryFilter;
tableSort.Fields = "JCBH";
tableSort.set_Ascending("JCBH", false);
tableSort.Sort(null);
ICursor cursor = tableSort.Rows;
IRow row = cursor.NextRow();
if (row != null)
{
int maxBSM = 0;
int currBSM = 0;
string BSMStr = row.Value[JCBHIndex].ToString();
string subBSMStr = BSMStr.Substring(8);
try
{
currBSM = Convert.ToInt32(subBSMStr);
}
catch (Exception)
{
return JCBH;
}
if (currBSM > maxBSM) maxBSM = currBSM;
maxBSM++;
maxXH = maxBSM;
}
}
}
int zeroNum = 5 - maxXH.ToString().Length;
string maxStr = maxXH.ToString();
for (int i = 0; i < zeroNum; i++)
{
maxStr = 0 + maxStr;
}
JCBH = start_jcbh + maxStr;
return JCBH;
}
public override void OnKeyDown(int keyCode, int Shift)
{
}
public override void OnKeyUp(int keyCode, int Shift)
{
}
public override void OnDblClick()
{
}
private void DrawFeature(IFeature pFeature)
{
try
{
// 获取IRGBColor接口
IRgbColor color = new RgbColor();
// 设置颜色属性
color.Red = 255;
color.Green = 0;
color.Blue = 0;
if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
{
IMarkerElement e = new MarkerElementClass();
IMarkerSymbol symbol = new SimpleMarkerSymbolClass();
symbol.Color = color;
symbol.Size = 5;
e.Symbol = symbol;
(e as IElement).Geometry = pFeature.Shape;
m_pHookHelper.ActiveView.GraphicsContainer.AddElement(e as IElement, 0);
tempElement = e as IElement;
}
else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
{
// 获取ILine符号接口
ILineSymbol outline = new SimpleLineSymbol();
// 设置线符号属
outline.Width = 2;
outline.Color = color;
(outline as SimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSSolid;
ILineElement pLineElement = new LineElementClass();
pLineElement.Symbol = outline;
(pLineElement as IElement).Geometry = pFeature.Shape;
m_pHookHelper.ActiveView.GraphicsContainer.AddElement(pLineElement as IElement, 0);
tempElement = pLineElement as IElement;
}
else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
{
if (tempElement == null)
{
// 获取ILine符号接口
ILineSymbol outline = new SimpleLineSymbol();
// 设置线符号属
outline.Width = 3;
outline.Color = color;
(outline as SimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSDot;
//ESRI.ArcGIS.Display.ILineSymbol
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
// 设置填充符号属性
simpleFillSymbol.Outline = outline;
simpleFillSymbol.Color = color;
simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
IFillShapeElement pFillShapeElement = new PolygonElementClass();
pFillShapeElement.Symbol = simpleFillSymbol;
IElement pElement = pFillShapeElement as IElement;
pElement.Geometry = pFeature.Shape;
m_pHookHelper.ActiveView.GraphicsContainer.AddElement(pElement, 0);
tempElement = pElement;
}
else
{
tempElement.Geometry = pFeature.Shape;
}
}
ITextSymbol pTextSymbol = new TextSymbolClass()
{
Color = color,
//Font = pFont,
Size = 12
};
m_pHookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pHookHelper.ActiveView.Extent);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
}
}