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

201 lines
7.8 KiB

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.Plugin.EngineEditor.helper;
namespace Kingo.Plugin.EngineEditor.Views
{
/// <summary>
/// FrmAttribureEdit.xaml 的交互逻辑
/// </summary>
public partial class FrmMerge :Window
{
public FrmMerge()
{
InitializeComponent();
}
List<DataSource> groupList;
IEnumFeature features = null;
public IHookHelper m_hookHelper;
public bool IsPromptAgain = true;
public void BindData()
{
gridData.ItemsSource = null;
IMap map = MapsManager.Instance.MapService.getAxMapControl().ActiveView.FocusMap;
Dictionary<string, List<IFeature>> SelectedFeature = GetSelectedFeaturesDic(map);
groupList = new List<DataSource>();
if (SelectedFeature.Keys.Count > 1)
{
MessageHelper.ShowTips("请选择单图层的要素进行合并操作!");
return;
}
else
{
foreach (string key in SelectedFeature.Keys)
{
txtConten.Text = SelectedFeature[key].Count + "个要素";
foreach (IFeature f in SelectedFeature[key])
{
DataSource datasource = new DataSource();
datasource.FID = f.get_Value(f.Fields.FindField(f.Class.OIDFieldName)).ToString();
datasource.feature = f;
groupList.Add(datasource);
}
}
gridData.ItemsSource = groupList;
}
}
public static Dictionary<string, List<IFeature>> GetSelectedFeaturesDic(IMap map, esriGeometryType geoType = esriGeometryType.esriGeometryAny)
{
if (map == null)
return null;
IEnumFeature enumFeature = map.FeatureSelection as IEnumFeature;
if (enumFeature == null)
return null;
Dictionary<string, List<IFeature>> geoList = new Dictionary<string, List<IFeature>>();
IFeature feart = enumFeature.Next();
while (feart != null)
{
if (feart.Shape != null && !feart.Shape.IsEmpty && (geoType == esriGeometryType.esriGeometryAny || feart.Shape.GeometryType == geoType))
{
IDataset dataset = feart.Table as IDataset;
if (dataset != null)
{
if (geoList.ContainsKey(dataset.BrowseName))
{
geoList[dataset.BrowseName].Add(feart);
}
else
{
geoList.Add(dataset.BrowseName, new List<IFeature>() { feart });
}
}
}
feart = enumFeature.Next();
}
return geoList;
}
/// <summary>
/// 点击定位
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridFileInfo_MouseDown(object sender, MouseButtonEventArgs e)
{
DataSource item = gridData.SelectedItem as DataSource;
if (item != null && item.feature != null)
{
IFeature f = item.feature as IFeature;
IFillSymbol fillSymbol = new SimpleFillSymbolClass();
fillSymbol.Color = new ESRI.ArcGIS.Display.RgbColorClass() { Red = 0, Green = 0, Blue = 255 };
MapsManager.Instance.MapService.FlashShape((m_hookHelper.Hook as IMapControlDefault),f.ShapeCopy, 2);
}
}
/// <summary>
/// 合并
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOK_Click(object sender, RoutedEventArgs e)
{
if (groupList == null || groupList.Count < 2)
{
MessageHelper.ShowTips("请选择合并的要素!");
return;
}
IEngineEditor m_editor = new EngineEditorClass();
m_editor.StartOperation();
try
{
IFeatureLayer featureLayer = (m_editor as EngineEditorClass).TargetLayer as IFeatureLayer;
IDataset dataset = featureLayer.FeatureClass as IDataset;
string areapath = SysAppPath.GetAreaUpdateConfigPath();
string mjField = string.Empty;
if(!string.IsNullOrWhiteSpace(areapath) && System.IO.File.Exists(areapath))
mjField = AreaConfigHelper.GetAreaPropertyByLayerName(dataset.Name);
DataSource item = gridData.SelectedItem as DataSource;
IGeometry geo = null;
foreach (DataSource data in groupList)
{
if (geo == null)
{
geo = data.feature.ShapeCopy;
}
else
{
if (geo.GeometryType == esriGeometryType.esriGeometryPoint)
{
MessageHelper.ShowTips("点要素不能进行合并!");
throw new Exception("点要素不能进行合并");
}
if (!geo.IsEmpty && !data.feature.ShapeCopy.IsEmpty && geo.GeometryType == data.feature.ShapeCopy.GeometryType)
{
ITopologicalOperator topOp = geo as ITopologicalOperator;
topOp.Simplify();
IGeometry geometry = data.feature.ShapeCopy;
(geometry as ITopologicalOperator).Simplify();
geo = topOp.Union(geometry);
}
}
}
//增加提示框原因,如果提示框选择否,再继续点合并会导致删除异常,所以原删除操作移至此处
foreach (DataSource data in groupList)
{
if (data.feature.OID != item.feature.OID)
{
data.feature.Delete();
}
}
item.feature.Shape = geo;
if (!string.IsNullOrWhiteSpace(mjField))
{
int mjIndex = item.feature.Fields.FindField(mjField);
if (mjIndex > -1) {
IArea area = item.feature.ShapeCopy as IArea;
double mj = area.Area;
if (dataset.Name == "LSYD")
{
mj = mj * 0.0001;
}
mj = Math.Round(mj, 2);
item.feature.Value[mjIndex] = mj;
}
}
item.feature.Store();
if (m_editor.Map.SelectionCount > 0)
{
m_editor.Map.ClearSelection();
}
m_editor.StopOperation("合并要素");
m_hookHelper.ActiveView.Refresh();
this.Close();
}
catch (Exception ex)
{
m_editor.AbortOperation();
LogAPI.Debug(ex);
}
}
public class DataSource
{
public string FID { get; set; }
public IFeature feature { get; set; }
}
}
}