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)进行空间数据 ...
随机推荐
- cocos2dx下的A星算法
这是我依据这篇博文http://hi.baidu.com/wsapyoemdfacmqr/item/bdfb5c0a74c904d01ef0466d.来在cocos2dx上编写.这是终于的效果图: 红 ...
- 英语音乐---二、Burning
英语音乐---二.Burning 一.总结 一句话总结:Burning - Maria Arredondo 玛丽亚·亚瑞唐多(Maria Arredondo),1985年7月6日出生于文内斯拉小镇,挪 ...
- BZOJ 1024 SCOI2009 生日快乐 暴搜
思路:eng...按照题意搜就好了 (一定要注意题面的n<=10--) 枚举断点...反正n<=10不怂 //By SiriusRen #include <cstdio> #i ...
- k-meas非监督聚类分析
实验名称: k-meas非监督聚类分析 一.实验目的和要求 目的: 加深对非监督学习的理解和认识 掌握聚类方法K-Means算法的设计方法 要求: 根据聚类数据,采用k-Means聚类 ...
- 以下三种下载方式有什么不同?如何用python模拟下载器下载?
问题始于一个链接https://i1.pixiv.net/img-zip-...这个链接在浏览器打开,会直接下载一个不完整的zip文件 但是,使用下载器下载却是完整文件 而当我尝试使用python下载 ...
- 三分钟明白 Activiti工作流 -- java运用_转载
一. 什么是工作流 以请假为例,现在大多数公司的请假流程是这样的 员工打电话(或网聊)向上级提出请假申请——上级口头同意——上级将请假记录下来——月底将请假记录上交公司——公司将请假录入电脑 采用工作 ...
- codeforces 540 B School Marks【贪心】
题意:一共n个数,给出其中k个数,要求这n个数的中位数为y,这n个数的和不超过x,补全剩下的n-k个数 先统计给出的k个数里面比中位数小的数, 如果cnt<=n/2,说明中位数还没有出现,把这n ...
- iOS开发——导入c文件引起的 Unknown type name 'NSString' 错误
一般情况下出现“Unknown type name”是头文件互相引用出现的,这里不是这个,由于源码使用是c\c++与oc混编,下面三种可以解决问题方案. 解决方案一: 选择所有.c文件,将属性的 id ...
- MySql系列之表的数据类型
存储引擎介绍 存储引擎即表类型,mysql根据不同的表类型会有不同的处理机制 什么是存储引擎 mysql中建立的库===>文件夹 库中建立的表===>文件 现实生活中我们用来存储数据的文件 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...