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.
171 lines
5.6 KiB
171 lines
5.6 KiB
using ESRI.ArcGIS.Controls; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using System.Windows; |
|
using System.Windows.Controls; |
|
using System.Windows.Data; |
|
using System.Windows.Documents; |
|
using System.Windows.Input; |
|
using System.Windows.Media; |
|
using System.Windows.Media.Imaging; |
|
using System.Windows.Navigation; |
|
using System.Windows.Shapes; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Utils; |
|
using ESRI.ArcGIS.Carto; |
|
using System.Text.RegularExpressions; |
|
using ESRI.ArcGIS.Geometry; |
|
using Kingo.PluginServiceInterface.Helper; |
|
|
|
namespace Kingo.Plugin.EngineEditor.Views.EditingEdit |
|
{ |
|
/// <summary> |
|
/// FrmClip.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class FrmClip : Window |
|
{ |
|
public IHookHelper m_hookHelper; |
|
private EngineEditorClass m_editor = null; |
|
public FrmClip() |
|
{ |
|
InitializeComponent(); |
|
} |
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
this.Close(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("关闭裁减窗口异常:" + ex); |
|
} |
|
} |
|
|
|
private void btnOK_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
double buffer = 0.0001; |
|
if (!double.TryParse(txtBuffer.Text, out buffer)) |
|
{ |
|
MessageHelper.Show("缓冲距离输入不合法!"); |
|
return; |
|
} |
|
Dictionary<string, List<IFeature>> SelectedFeature = LayerHelper.GetSelectedFeaturesDic(m_hookHelper.FocusMap); |
|
if (SelectedFeature.Count <= 0) |
|
{ |
|
MessageHelper.Show("请选择用于裁减的要素!"); |
|
return; |
|
} |
|
if (SelectedFeature.Keys.Count > 1) |
|
{ |
|
MessageHelper.Show("请选择单图层的要素进行裁减!"); |
|
return; |
|
} |
|
foreach (var item in SelectedFeature) |
|
{ |
|
if (item.Value.Count != 1) |
|
{ |
|
MessageHelper.Show("请选择单个裁减要素!"); |
|
return; |
|
} |
|
Clip(item.Value[0], buffer); |
|
break; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("裁减异常:" + ex); |
|
MessageHelper.Show("裁减异常:" + ex.Message); |
|
} |
|
} |
|
|
|
private void Clip(IFeature feature, double buffer) |
|
{ |
|
try |
|
{ |
|
if (m_editor == null) |
|
{ |
|
m_editor = new EngineEditorClass(); |
|
} |
|
IFeatureLayer featureLayer = m_editor.TargetLayer as IFeatureLayer; |
|
if (featureLayer == null) |
|
{ |
|
MessageHelper.Show("未找到编辑的目标图层!"); |
|
return; |
|
} |
|
IGeometry clipGeometry = feature.ShapeCopy; |
|
if (buffer > 0) |
|
{ |
|
ITopologicalOperator pTopo = clipGeometry as ITopologicalOperator; |
|
clipGeometry = pTopo.Buffer(buffer); |
|
} |
|
|
|
List<IFeature> lstFeature = KGIS.Framework.AE.FeatureAPI.Identify(clipGeometry, featureLayer); |
|
if (lstFeature.Count < 1) |
|
{ |
|
MessageHelper.Show("所选裁减要素与编辑目标图层不存在相交,跳过裁减!"); |
|
return; |
|
} |
|
foreach (IFeature item in lstFeature) |
|
{ |
|
m_editor.StartOperation(); |
|
if (radioSaveIntersect.IsChecked == true) |
|
{ |
|
item.Shape = KGIS.Framework.AE.FeatureAPI.InterSect(item.ShapeCopy, clipGeometry); |
|
} |
|
else |
|
{ |
|
item.Shape = KGIS.Framework.AE.FeatureAPI.Difference(item.ShapeCopy, clipGeometry); |
|
} |
|
item.Store(); |
|
m_editor.StopOperation("裁减要素"); |
|
} |
|
this.Close(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
m_hookHelper.ActiveView.Refresh(); |
|
} |
|
} |
|
|
|
private void TxtBuffer_PreviewTextInput(object sender, TextCompositionEventArgs e) |
|
{ |
|
// 只允许输入数字和小数点 |
|
Regex regex = new Regex("[^0-9.]"); |
|
e.Handled = regex.IsMatch(e.Text); |
|
if (!e.Handled) |
|
{ |
|
// 获取TextBox当前的文本内容和新输入的字符 |
|
string text = txtBuffer.Text.Insert(txtBuffer.SelectionStart, e.Text); |
|
|
|
// 判断文本是否符合最多四位小数点的格式 |
|
decimal value; |
|
if (decimal.TryParse(text, out value)) |
|
{ |
|
int decimalPlaces = BitConverter.GetBytes(decimal.GetBits(value)[3])[2]; |
|
|
|
// 最多四位小数点 |
|
if (decimalPlaces > 4) |
|
{ |
|
e.Handled = true; |
|
} |
|
} |
|
else |
|
{ |
|
e.Handled = true; |
|
} |
|
} |
|
} |
|
} |
|
}
|
|
|