C# Arcgis Engine 捕捉功能实现
namespace 捕捉
{
public partial class Form1 : Form
{
private bool bCreateElement=true;
private int internalTime = ;
private int snapTime = ;
private IElement m_element = null;
IPoint currentPoint=new PointClass();
private IPoint snapPoint = null;
IMovePointFeedback movePointFeedback=new MovePointFeedbackClass();
private string snapLayer = ""; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
currentPoint.PutCoords(e.mapX,e.mapY);
snapTime++;
snapTime = snapTime%internalTime;
ILayer layer=GetLayerByName(snapLayer,axMapControl1);
if (layer==null)
{
return;
}
IFeatureLayer featureLayer = layer as IFeatureLayer;
if (bCreateElement)
{
CreateMarkerElement(currentPoint);
bCreateElement = false;
}
if (snapPoint==null)
{
ElementMoveTo(currentPoint);
}
if (snapTime==)
{ #region 第一种捕捉方式 IPoint temPoint = new PointClass();
temPoint.X = e.mapX;
temPoint.Y = e.mapY;
snapPoint = GetNearestVertex(axMapControl1.ActiveView, temPoint, ); #endregion #region 第二种方式 //snapPoint = Snapping(e.mapX, e.mapY, featureLayer); #endregion }
if (snapPoint!=null&&snapTime==)
{
ElementMoveTo(snapPoint);
}
} public double ConvertPixelsToMapUnits(IActiveView activeView, double pixelUnits)
{
double realDisplayExtent;
int pixelExtent;
double sizeOfOnePixel;
pixelExtent = activeView.ScreenDisplay.DisplayTransformation.get_DeviceFrame().right -
activeView.ScreenDisplay.DisplayTransformation.get_DeviceFrame().left;
realDisplayExtent = activeView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
sizeOfOnePixel = realDisplayExtent/pixelExtent;
return pixelUnits*sizeOfOnePixel;
}
public IPoint Snapping(double x,double y,IFeatureLayer featureLayer)
{
#region 这种捕捉有问题,无法捕捉点和面图层
IPoint iHitPoint = null;
IMap iMap = axMapControl1.Map;
IActiveView iView = axMapControl1.ActiveView;
IFeatureClass iFClass = featureLayer.FeatureClass;
IPoint point=new PointClass();
point.PutCoords(x,y);
double length = ConvertPixelsToMapUnits(iView, );
ITopologicalOperator pTopo = point as ITopologicalOperator;
IGeometry pGeometry = pTopo.Buffer(length).Envelope as IGeometry;
ISpatialFilter spatialFilter=new SpatialFilterClass();
spatialFilter.GeometryField = featureLayer.FeatureClass.ShapeFieldName;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
spatialFilter.Geometry = pGeometry; IFeatureCursor cursor = iFClass.Search(spatialFilter, false);
IFeature iF = cursor.NextFeature();
if (iF==null)
{
return null;
}
IPoint iHitPt = new ESRI.ArcGIS.Geometry.Point();
IHitTest iHitTest = iF.Shape as IHitTest;
double hitDist = ;
int partIndex = ;
int vertexIndex = ;
bool bVertexHit = false; double tol = ConvertPixelsToMapUnits(iView, );
if (iHitTest.HitTest(point,tol,esriGeometryHitPartType.esriGeometryPartBoundary,iHitPt,ref hitDist,ref partIndex,ref vertexIndex,ref bVertexHit))
{
iHitPoint = iHitPt;
}
axMapControl1.ActiveView.Refresh();
return iHitPoint;
#endregion
}
public void ElementMoveTo(IPoint point)
{
movePointFeedback.MoveTo(point);
IGeometry geometry1 = null;
IGeometry geometry2 = null;
if (m_element!=null)
{
geometry1 = m_element.Geometry;
geometry2 = movePointFeedback.Stop();
m_element.Geometry = geometry2;
this.axMapControl1.ActiveView.GraphicsContainer.UpdateElement(m_element);
movePointFeedback.Start(geometry1 as IPoint,point);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null); }
}
public IPoint GetNearestVertex(IActiveView actview, IPoint pnt, double mapSize)
{
IPoint vetex = null;
IPoint hitPnt = new PointClass();
IHitTest hitTest = null;
IPointCollection pntColl = new MultipointClass();
IProximityOperator prox = null;
double hitdis = ;
int hitpartindex = ;
int hitsegindex = ;
Boolean rside = false;
IFeatureCache2 featCache = new FeatureCacheClass();
double pixelSize = ConvertPixelsToMapUnits(actview, mapSize); //将地理范围转化为像素
featCache.Initialize(pnt, pixelSize); //初始化缓存
for (int i = ; i < actview.FocusMap.LayerCount; i++)
{
//只有点、线、面并且可视的图层才加入缓存
IFeatureLayer featLayer = (IFeatureLayer)actview.FocusMap.get_Layer(i);
if (featLayer != null && featLayer.Visible == true &&
(featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline ||
featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon ||
featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint))
{
featCache.AddFeatures(featLayer.FeatureClass, null);
for (int j = ; j < featCache.Count; j++)
{
IFeature feat = featCache.get_Feature(j);
hitTest = (IHitTest)feat.Shape;
//捕捉节点,另外可以设置esriGeometryHitPartType,捕捉边线点,中间点等。
if (hitTest.HitTest(pnt, mapSize, esriGeometryHitPartType.esriGeometryPartVertex, hitPnt, ref hitdis, ref hitpartindex, ref hitsegindex, ref rside))
{
object obj = Type.Missing;
pntColl.AddPoint(hitPnt, ref obj, ref obj);
break;
}
}
}
}
prox = (IProximityOperator)pnt;
double minDis = , dis = ;
for (int i = ; i < pntColl.PointCount; i++)
{
IPoint tmpPnt = pntColl.get_Point(i);
dis = prox.ReturnDistance(tmpPnt);
if (i == )
{
minDis = dis;
vetex = tmpPnt;
}
else
{
if (dis < minDis)
{
minDis = dis;
vetex = tmpPnt;
}
}
}
return vetex;
}
public ILayer GetLayerByName(string layerName, AxMapControl axMap)
{
for (int i = ; i < axMap.LayerCount; i++)
{
if (axMap.get_Layer(i).Name.EndsWith(layerName))
{
return axMap.get_Layer(i);
}
}
return null;
} public void CreateMarkerElement(IPoint point)
{
IActiveView activeView = this.axMapControl1.ActiveView;
IGraphicsContainer graphicsContainer = axMapControl1.Map as IGraphicsContainer;
IMarkerElement markerElement = new MarkerElement() as IMarkerElement;
ISimpleMarkerSymbol simpleMarkerSymbol=new SimpleMarkerSymbol(); IRgbColor rgbColor1=new RgbColor();
rgbColor1.Red = ;
rgbColor1.Blue = ;
rgbColor1.Green = ;
simpleMarkerSymbol.Color = rgbColor1; IRgbColor iRgbColor2=new RgbColor();
iRgbColor2.Red = ;
iRgbColor2.Blue = ;
iRgbColor2.Green = ; simpleMarkerSymbol.Outline = true;
simpleMarkerSymbol.OutlineColor = iRgbColor2 as IColor;
simpleMarkerSymbol.OutlineSize = ;
simpleMarkerSymbol.Size = ;
simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
ISymbol symbol = simpleMarkerSymbol as ISymbol;
symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
markerElement.Symbol = simpleMarkerSymbol;
m_element = markerElement as IElement;
m_element.Geometry = point as IGeometry;
graphicsContainer.AddElement(m_element,);
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,m_element,null);
IGeometry geometry = m_element.Geometry;
movePointFeedback.Display = activeView.ScreenDisplay;
movePointFeedback.Symbol = simpleMarkerSymbol as ISymbol;
movePointFeedback.Start(geometry as IPoint,point); } private void cbLayerName_SelectedIndexChanged(object sender, EventArgs e)
{
snapLayer = cbLayerName.Text;
} private void Form1_DoubleClick(object sender, EventArgs e)
{ } private void splitContainer1_Panel2_DoubleClick(object sender, EventArgs e)
{
for (int i = ; i < axMapControl1.Map.LayerCount; i++)
{
cbLayerName.Items.Add(axMapControl1.get_Layer(i).Name);
}
cbLayerName.Text = cbLayerName.Items[].ToString();
snapLayer = cbLayerName.Text;
} }
}
源码:http://pan.baidu.com/s/1gdzP8QJ
提取密码:dlpn
visual studio 2008
AE9.3
C# Arcgis Engine 捕捉功能实现的更多相关文章
- ArcGIS Engine 捕捉
原文 ArcGIS Engine 捕捉 bool bCreateElement = true; ;//时间间隔 ;//初始值 IElement m_element = null; //界面绘制点元素 ...
- ArcGIS Engine开发鹰眼图的功能(基础篇)
鹰眼是用于调节全视域范围内主地图显示范围情况的副地图.它体现了地图整体与详细局部的关系. 用户可以通过鼠标单击或者画框等动作实现鹰眼与主地图的交互情况. 鹰眼功能的原理是通过主地图窗口的地图控件和鹰眼 ...
- ArcGIS Engine开发的ArcGIS 版本管理的功能
原文:ArcGIS Engine开发的ArcGIS 版本管理的功能 转自:http://blog.csdn.net/linghe301/article/details/7965901 这是以前的Arc ...
- ArcGIS Engine开发鹰眼图的功能(代码优化篇)
在上一篇,ArcGIS Engine开发鹰眼图的功能(基础篇) 上一篇的实现效果图如下, 如果仔细观察,会发现一个问题,即在“鹰眼”的区域,只要在红色线框内的注记会被覆盖. 如果红色框包括整张图的话, ...
- ArcGIS AddIn 图斑比例分割工具,调用捕捉功能
最近做一个图斑按比例分割的工具,需要绘制一条用以切割的方向线,通过Tool的方式实现 绘制时希望能够使用捕捉功能,查阅相关资料如下: 使用该文章,第Implementing snapping in a ...
- 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
Dixon 原文 用ArcGIS Engine.VS .NET和Windows控件开发GIS应用 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...
- C#,ArcGIS Engine开发入门教程
C#,ArcGIS Engine开发入门教程 转自:http://blog.csdn.net/yanleigis/article/details/2233674 目录(?)[+] 五实现 一 加载A ...
- ArcGIS Engine开发之属性查询
属性查询即基于空间数据的属性数据的查询,通过用户提交SQL语言中的where语句定义的查询条件,对属性数据进行搜索,从而得到查询结果的操作. 相关的类与接口 与属性查询功能相关的类主要有QureyFi ...
- ArcGIS Engine开发之地图基本操作(4)
ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...
随机推荐
- Datazen图表创建和公布
Datazen是被微软收购的移动端全平台的数据展现解决方式.此篇主要介绍怎样创建和公布图表. 如前面介绍,Datazen图表的创建和公布是通过Publisher的应用,它是Windows 8应用 ...
- STL源代码学习(vector篇)
#include <concept_checks.h> #include<stl_allocate.h> /// The vector base class's constru ...
- EL表达式获取参数值${param.name}等
转自:http://www.html580.com/study/83.html EL表达式获取参数值${param.name}等 (1).${pageContext} 获取到 pageContext ...
- VS C/C++ 调用lua库(编译出错)
导入 lua.h 之类的头文件后,编译含有Lua函数的时候,可能会出现如下错误: 1>main.obj : error LNK2019: 无法解析的外部符号_luaL_checkinteger, ...
- POJ 3668 枚举?
枚举两点,算一下斜率 sort一遍 判个重 输出解 25行 搞定- //By SiriusRen #include <cmath> #include <cstdio> #inc ...
- SSRS 报表 如何匿名查看
SSRS 报表 如何匿名查看 昨晚一直研究怎么能匿名访问报表然后给客户看呢? 研究了好几种办法 我试过的分为三种,其中推荐我认为相对可控一点. .修改SSRS配置文件来禁止他验证登陆用户权限 操作过的 ...
- AngularJs轻松入门(九)与服务器交互
AngularJs从Web服务器请求资源都是通过Ajax来完成,所有的操作封装在$http服务中,$http服务是只能接收一个参数的函数,这个参数是一个对象,用来完成HTTP请求的一些配置,函数返回一 ...
- rails 开发随手记 9
ruby 根据名称确定类Object.const_get 一个简单的应用,在header中的,个人信息链应该链接到对应的用户类型的页面上. <%= link_to "个人信息" ...
- PostgreSQL Replication之第七章 理解Linux高可用(4)
7.4 术语与概念 一组计算机被称为集群.集群内的一台计算机被称为一个节点. 当集群内的节点数量是 N (2,,3,等.) ,那么我们讨论一个N节点的集群. 高可用性软件,传输层和集群管理层都运行于每 ...
- c# 的类成员
1 字段和变量的区别 字段是在类中定义的数据成员 由访问修饰符+数据类型+字段名(public string name) 字段就像类的一个小数据库,用来存放和类相关的数据; 而变量是没有修饰符的(in ...