使用 ArcEngine 实现多边形的自动化填充功能
最编程
2024-01-22 07:00:21
...
ArcEngine 开发自动完成多边形功能
using System;
using System.Collections.Generic;
using System.Text;
using GIS.ArcGIS.Commands.SelEx;
using ESRI.ArcGIS.Controls;
using Net.Resource;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Display;
using GIS.ArcGIS.Common;
using GIS.ArcGIS.Carto;
using GIS.ArcGIS.EditEx;
using System.Windows.Forms;
namespace GIS.ArcGIS.Commands.EditEx
{
/// <summary>
/// ArcEngine 开发自动完成多边形功能
/// vp:hsg
/// create date:2012-07-20
/// modify date:2013-03-12
/// </summary>
public class EditAutoCompletePolygonTool : EditGisBaseTool, ILineSelect
{
private EngineEditorClass eedit = new EngineEditorClass();
public EditAutoCompletePolygonTool()
{
}
~EditAutoCompletePolygonTool()
{
try
{
m_Cursor = null;
}
catch (Exception ee)
{
}
}
#region ICommand 成员
public override int Bitmap
{
get
{
return 0;
}
}
public string Description
{
get { return "自动完成多边形功能"; }
}
public override string Caption
{
get { return this.Description; }
}
public override string Category
{
get { return "AutoCompletePolygon"; }
}
public override bool Checked
{
get { return false; }
}
public override bool Enabled
{
get
{
if (eedit.TargetLayer != null)
{
return true;
}
return false;
}
}
public override int HelpContextID
{
get { return 0; }
}
public override string HelpFile
{
get { return ""; }
}
public override string Message
{
get { return this.Description; }
}
public override string Name
{
get { return this.Description; }
}
public override void OnClick()
{
if (m_Cursor == null)
{
m_Cursor = ResourceLib.getInstance().GetCursorResource("Net.Resource.Select.PointSelect.cur");
}
this.Step = 0;
this.IsUsed = false;
this.LineFeedback = null;
}
public override string Tooltip
{
get { return this.Description; }
}
#endregion
#region ITool 成员
private System.Windows.Forms.Cursor m_Cursor = null;
public override int Cursor
{
get
{
if (m_Cursor != null)
{
return m_Cursor.Handle.ToInt32();
}
else
{
return 0;
}
}
}
public override bool Deactivate()
{
return true;
}
public override bool OnContextMenu(int x, int y)
{
return false;
}
private void CreatePolygonsFromFeatures(IFeatureClass getpolygon_fc)
{
IDataset pDataset = getpolygon_fc as IDataset;
IWorkspace pWorkspace = pDataset.Workspace;
IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit;
if (pWorkspaceEdit.IsBeingEdited() != true)
{
pWorkspaceEdit.StartEditing(true);
if (pWorkspaceEdit.IsBeingEdited() != true)
{
return;
}
pWorkspaceEdit.StartEditOperation();
}
IFeatureConstruction pFeatureConstruction = new FeatureConstructionClass();
IMap pMap = this.HookHelper.FocusMap;// axMapControl1.Map;
IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
IFeature pFeature = pEnumFeature.Next();
if (pFeature == null)
{
MessageBox.Show("pEnumFeature为空");
return;
}
pFeatureConstruction.ConstructPolygonsFromFeatures(null, getpolygon_fc, null, false, false, pEnumFeature, null, 0.01, null);
MessageBox.Show("转化结束");
}
/// <summary>
/// 双击 结束画
/// </summary>
public override void OnDblClick()
{
try
{
object objMiss = Type.Missing;
//
if (this.IsUsed == false) return;
if (this.LineFeedback == null) return;
if (this.Step > 1)
{
IPolyline tpPolyline = this.LineFeedback.Stop();
if (tpPolyline == null)
{
this.Step = 0;
this.IsUsed = false;
this.LineFeedback = null;
return;
}
IGeometry tpLine = tpPolyline;
//获取构面的线集合
GeometryBagClass enumGeoLines = new GeometryBagClass();
enumGeoLines.AddGeometry(tpLine, ref objMiss, ref objMiss);
//
if (eedit.TargetLayer != null && eedit.TargetLayer is IFeatureLayer)
{
IFeatureLayer FeatLayer = eedit.TargetLayer as IFeatureLayer;
FeatLayer.Selectable = true;
IFeatureClass fc = FeatLayer.FeatureClass;
IDataset pDataset = fc as IDataset;
IWorkspace pWorkspace = pDataset.Workspace;
//
IGeoDataset geoDS = fc as IGeoDataset;
IEnvelope processingBounds = geoDS.Extent;
//
IInvalidArea invalidArea = new InvalidAreaClass();
//要素构造类
IFeatureConstruction pfeatBuild = new FeatureConstructionClass();
//从enumGeoLines集合中构面并保存到fc面图层中
//pfeatBuild.ConstructPolygonsFromGeometries(null, fc, null, false, enumGeoLines, null, 0.0001);
//开始自动完成构面并保存到fc面图层中
IFeatureSelection featsel = FeatLayer as IFeatureSelection;
ISelectionSet selSet = featsel.SelectionSet;
pfeatBuild.AutoCompleteFromGeometries(fc, processingBounds, enumGeoLines, invalidArea, 0.0001, pWorkspace, out selSet);
if (selSet != null)
{
MessageBox.Show(selSet.Count.ToString());
}
//
this.HookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, this.HookHelper.ActiveView.Extent);
//
}
else
{
System.Windows.Forms.MessageBox.Show("目标图层为空,请开启编辑会话", "提示");
}
this.Step = 0;
this.IsUsed = false;
this.LineFeedback = null;
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "提示");
}
}
public virtual IGeometry Erase(IGeometry source, IGeometry other)
{
ITopologicalOperator topoOper = source as ITopologicalOperator;
if (!topoOper.IsSimple)
{
topoOper.Simplify();
}
IGeometry geo = topoOper.Difference(other);
topoOper = geo as ITopologicalOperator;
if (!topoOper.IsSimple)
{
topoOper.Simplify();
}
return geo;
}
public override void OnKeyDown(int keyCode, int shift)
{
}
public override void OnKeyUp(int keyCode, int shift)
{
}
public override void OnMouseDown(int button, int shift, int x, int y)
{
if (this.HookHelper.ActiveView == null) return;
if (button == 1) //MouseDown左键 开始画点/连续画点
{
IPoint tpPoint = null;
if (this.Step <= 0)
{
//开始画点
tpPoint = this.HookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
this.LineFeedback = new NewLineFeedbackClass();
this.LineFeedback.Start(tpPoint);
this.Step += 1;
this.LineFeedback.Display = this.HookHelper.ActiveView.ScreenDisplay;
this.IsUsed = true;
}
else
{
//连续画点
tpPoint = this.HookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
this.Step += 1;
this.LineFeedback.AddPoint(tpPoint);
}
} //--
else //MouseDown右键
{
}
}
public override void OnMouseMove(int button, int shift, int x, int y)
{
if (this.IsUsed == true)
{
IPoint mappoint = this.HookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
this.LineFeedback.MoveTo(mappoint);
}
}
public override void OnMouseUp(int button, int shift, int x, int y)
{
}
public override void Refresh(int hdc)
{
}
#endregion
#region ILineSelect 成员
public esriSpatialRelEnum getSpatialRel(esriGeometryType geoType)
{
//System.Windows.Forms.MessageBox.Show(geoType.ToString());
esriSpatialRelEnum SpatialRelEnum = esriSpatialRelEnum.esriSpatialRelIntersects;
switch (geoType)
{
case esriGeometryType.esriGeometryPolygon: //面对面Polygon
SpatialRelEnum = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
case esriGeometryType.esriGeometryPoint: //面对点Point
SpatialRelEnum = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
case esriGeometryType.esriGeometryPolyline: //面对线Polyline
SpatialRelEnum = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
case esriGeometryType.esriGeometryLine: //面对线Line
SpatialRelEnum = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
default:
SpatialRelEnum = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
}
return SpatialRelEnum;
}
public ISymbol getSelectionSymbol(esriGeometryType geoType)
{
ISymbol symbol = null;
switch (geoType)
{
case esriGeometryType.esriGeometryPolygon: //点对面Polygon
symbol = new SimpleFillSymbolClass();
ISimpleFillSymbol fs = symbol as ISimpleFillSymbol;
fs.Color = EnvironmentSelectionClass.getInstance.DefaultColor;
fs.Outline.Color = EnvironmentSelectionClass.getInstance.DefaultColor;
fs.Outline.Width = 1;
fs.Style = esriSimpleFillStyle.esriSFSSolid;
break;
case esriGeometryType.esriGeometryPoint: //点对点Point
symbol = new SimpleMarkerSymbolClass();
(symbol as ISimpleMarkerSymbol).OutlineColor = EnvironmentSelectionClass.getInstance.DefaultColor;
(symbol as ISimpleMarkerSymbol).Outline = true;
(symbol as ISimpleMarkerSymbol).OutlineSize = 5;
(symbol as ISimpleMarkerSymbol).Style = esriSimpleMarkerStyle.esriSMSCircle;
break;
case esriGeometryType.esriGeometryPolyline: //点对线Polyline //点作Buffer容差值
symbol = new SimpleLineSymbolClass();
(symbol as ISimpleLineSymbol).Color = EnvironmentSelectionClass.getInstance.DefaultColor;
(symbol as ISimpleLineSymbol).Width = 1;
(symbol as ISimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSSolid;
break;
case esriGeometryType.esriGeometryLine: //点对线Line
symbol = new SimpleLineSymbolClass();
(symbol as ISimpleLineSymbol).Color = EnvironmentSelectionClass.getInstance.DefaultColor;
(symbol as ISimpleLineSymbol).Width = 1;
(symbol as ISimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSSolid;
break;
default:
symbol = new SimpleLineSymbolClass();
(symbol as ISimpleLineSymbol).Color = EnvironmentSelectionClass.getInstance.DefaultColor;
(symbol as ISimpleLineSymbol).Width = 1;
(symbol as ISimpleLineSymbol).Style = esriSimpleLineStyle.esriSLSSolid;
break;
}
return symbol;
}
private INewLineFeedback m_LineFeedback = null;
public INewLineFeedback LineFeedback
{
get { return m_LineFeedback; }
set { m_LineFeedback = value; }
}
private bool m_IsUsed = false;
public bool IsUsed
{
get
{
return m_IsUsed;
}
set
{
m_IsUsed = value;
}
}
private int m_Step = 0;
public int Step
{
get { return m_Step; }
set { m_Step = value; }
}
#endregion
}
}
推荐阅读
-
Adobe国际认证中文官方网站】Adobe中国摄影计划,免费安装正版激活--Adobe Creative Cloud中国摄影计划。与此同时,Adobe宣布天猫为Adobe Creative Cloud中国摄影计划的电商战略合作伙伴,并将与其合作上线Adobe天猫官方旗舰店。 此举无疑一方面扩大了Adobe在中国的影响力,另一方面也有助于国内用户更好地培养正版软件意识,推动Adobe软件在中国的正版化进程。 网络异常,图片无法显示 ||网络异常 Adobe Creative Cloud中国摄影计划包括Photoshop和Lightroom Classic两大桌面创意工具,以及iOS版Photoshop Express。 其中,Adobe Lightroom Classic和Adobe Photoshop作为两款常用的图像处理软件,对于那些玩摄影、后期修图的创意设计人群无疑有着巨大的帮助,而LR+PS套装对于摄影领域用户的重要性自不必说,正版产品的性能实时更新也可以放心!体验最新功能,对于新镜头(补偿)和机身(RAW 读取)都能第一时间适应。不信你看: Photoshop 图像合成 裁剪、移除对象、润饰合成照片、玩转色彩和特效,创建精美图片和艺术品! Lightroom Classic 照片编辑 轻松批量管理和编辑照片,内置专业创意控件和摄影师预设,让你的照片大放异彩。 手机 PS 便捷编辑 Photoshop Express 支持多种滤镜、贴纸,手机即可完成抠图、除雾等任务 人工智能编辑工具 神经滤镜、快速点击选区、自动选择主题等人工智能功能让图像编辑更轻松 创意画笔内容识别 定制艺术画笔工具,实现个性化效果;内容识别填充,智能去除无用物体。 Adobe Creative Cloud 中国摄影计划的推出,为中国的专业摄影师、摄影爱好者、后期修图和其他创意设计人员带来了全方位的内容和体验。 网络异常,图片无法显示 ||网络异常 当然,不可否认的是,"由于盗版软件缺乏开发、维护和升级成本,销售价格远低于正版软件。再加上很多普通人并不需要使用正版软件的复杂功能,版权观念较淡,还是有大量的创意设计人员会选择盗版软件"。 但事实上,当所有的软件都不再是单一的软件,而是变成一种服务时,单机版盗版的存在就逐渐成为鸡肋。因为有太多的服务让你即使是所谓的 "完美破解",也无法享受,Adobe Cloud 就是一个很好的例子,所谓的完美破解,你只能使用 "Adobe "的一半,对于更精彩的 "云",只能望云兴叹。更何况,越来越多的设计工具从免费走向付费,越来越多的设计师和企业已经接受了付费使用的模式。 其次,对于互联网时代的企业数字化转型而言,数字化合规至关重要。21年来,使用盗版PS和未经授权的方正字体被指侵权的事情闹得沸沸扬扬,虽然新闻真假难辨,但也给使用盗版工具的用户敲响了警钟。 付费使用正版工具,可以更放心地进行设计,不用担心版权风险!
-
在Halcon中使用Qt5实现可交互的矩形、圆形和多边形ROI区域的ListView列表视图功能
-
使用 ArcEngine 实现多边形的自动化填充功能