ArcGIS Engine 捕捉
bool bCreateElement = true;
int internalTime = ;//时间间隔
int snapTime = ;//初始值
IElement m_element = null; //界面绘制点元素
IPoint currentPoint = new PointClass(); //当前鼠标点
IPoint snapPoint = null; //捕捉到的点
IMovePointFeedback pFeedback = new MovePointFeedbackClass(); public void DoMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
AxMapControl axMapControl1 = sender as AxMapControl;
currentPoint.PutCoords(e.mapX, e.mapY);
if (action == ActionType.CreateFeature)
{
snapTime++;
snapTime = snapTime%internalTime ;
ILayer layer = GetLayerByName(snapLayer, axMapControl1);
IFeatureLayer m_iFeatureLyr = layer as IFeatureLayer;
if (bCreateElement)
{
CreateMarkerElement(currentPoint,axMapControl1);
bCreateElement = false;
}
if (snapPoint == null)
ElementMoveTo(currentPoint, axMapControl1);
//鼠标自动扑获顶点
if (snapTime == )
snapPoint = Snapping(e.mapX, e.mapY, m_iFeatureLyr, axMapControl1);
if (snapPoint != null && snapTime == )
ElementMoveTo(snapPoint, axMapControl1);
}
} /// <summary>
/// 捕捉
/// </summary>
/// <param name=”x”></param>
/// <param name=”y”></param>
/// <param name=”iFeatureLyr”></param>
/// <param name=”axMapControl1″></param>
/// <returns></returns>
public IPoint Snapping(double x, double y, IFeatureLayer iFeatureLyr, AxMapControl axMapControl1)
{
IPoint iHitPoint = null;
IMap iMap = axMapControl1.Map;
IActiveView iView = axMapControl1.ActiveView;
IFeatureClass iFClss = iFeatureLyr.FeatureClass;
IPoint point = new PointClass();
point.PutCoords(x,y);
double length = ConvertPixelsToMapUnits(axMapControl1.ActiveView, );
ITopologicalOperator pTopo = point as ITopologicalOperator;
IGeometry pGeometry = pTopo.Buffer(length).Envelope as IGeometry;
ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.GeometryField = iFeatureLyr.FeatureClass.ShapeFieldName;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
spatialFilter.Geometry = pGeometry; IFeatureCursor cursor = iFClss.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;
// Tolerance in pixels for line hits
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;
} /// <summary>
/// 创建新的element用于显示
/// </summary>
/// <param name=”point”></param>
/// <param name=”axMapControl1″></param>
public void CreateMarkerElement(IPoint point, AxMapControl axMapControl1)
{
IActiveView iView = axMapControl1.ActiveView;
IGraphicsContainer iGraphContainer = axMapControl1.Map as IGraphicsContainer;
//建立一个marker元素
IMarkerElement iMarkerElement = new MarkerElement() as IMarkerElement;
ISimpleMarkerSymbol iSym = new SimpleMarkerSymbol();
//符号化元素
IRgbColor iColor = new RgbColor();
iColor.Red = ;
iColor.Blue = ;
iColor.Green = ;
iSym.Color = iColor;
IRgbColor iColor2 = new RgbColor();
iColor2.Red = ;
iColor2.Blue = ;
iColor2.Green = ;
iSym.Outline = true;
iSym.OutlineColor = iColor2 as IColor;
iSym.OutlineSize = ;
iSym.Size = ;
iSym.Style. = esriSimpleMarkerStyle.esriSMSCircle;
ISymbol symbol = iSym as ISymbol;
symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
iMarkerElement.Symbol = iSym;
m_element = iMarkerElement as IElement;
m_element.Geometry = point as IGeometry;
iGraphContainer.AddElement(m_element, );
iView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, m_element, null);
IGeometry iGeo = m_element.Geometry;
pFeedback.Display = iView.ScreenDisplay;
pFeedback.Symbol = iSym as ISymbol;
pFeedback.Start(iGeo as IPoint, point);
}
/// <summary>
/// 移动元素
/// </summary>
/// <param name=”iPt”></param>
/// <param name=”axMapControl1″></param>
public void ElementMoveTo(IPoint iPt, AxMapControl axMapControl1)
{
//移动元素
pFeedback.MoveTo(iPt);
IGeometry iGeo1 = null;
IGeometry iGeoResult;
if (m_element != null)
{
iGeo1 = m_element.Geometry;
iGeoResult = pFeedback.Stop();
//map.ActiveView.Refresh();
m_element.Geometry = iGeoResult;
//更新该元素的位置
axMapControl1.ActiveView.GraphicsContainer.UpdateElement(m_element);
//重新移动元素
pFeedback.Start(iGeo1 as IPoint, iPt);
//map.ActiveView.Refresh();
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
} public ILayer GetLayerByName(string layerName, AxMapControl axMapControl1)
{
for (int i = ; i < axMapControl1.LayerCount; i++)
{
if (axMapControl1.get_Layer(i).Name.Equals(layerName))
return axMapControl1.get_Layer(i);
}
return null;
} public double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
{
double realWorldDisplayExtent;
int pixelExtent;
double sizeOfOnePixel;
pixelExtent = pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame().right – pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame().left;
realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
return pixelUnits * sizeOfOnePixel;
}
ArcGIS Engine 捕捉的更多相关文章
- C# Arcgis Engine 捕捉功能实现
namespace 捕捉 { public partial class Form1 : Form { private bool bCreateElement=true; ; ; private IEl ...
- 利用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开发鹰眼图的功能(基础篇)
鹰眼是用于调节全视域范围内主地图显示范围情况的副地图.它体现了地图整体与详细局部的关系. 用户可以通过鼠标单击或者画框等动作实现鹰眼与主地图的交互情况. 鹰眼功能的原理是通过主地图窗口的地图控件和鹰眼 ...
- ArcGIS Engine开发之图形查询
图形查询是以用户通过鼠标操作生成的图形几何体为输入条件进行查询的查询,其查询结果为该几何体空间范围内的所有要素.常用的查询方式包括点选.线选.多边形选择.圆形选择和矩形选择等. 相关类与接口 图像查询 ...
- ArcGIS Engine开发之属性查询
属性查询即基于空间数据的属性数据的查询,通过用户提交SQL语言中的where语句定义的查询条件,对属性数据进行搜索,从而得到查询结果的操作. 相关的类与接口 与属性查询功能相关的类主要有QureyFi ...
- ArcGIS Engine开发之地图基本操作(4)
ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...
- ArcGIS Engine开发之地图基本操作(3)
地图数据的加载 一.加载Shapefile数据 Shapefile文件是目前主流的一种空间数据的文件存储方式,也是不同GIS软件进行数据格式转换常用的中间格式.加载Shapefile数据的方式有两种: ...
- ArcGIS Engine开发之地图基本操作(2)
地图数据的加载 1.加载地图文档 ArcGIS Engine支持加载多种类型的数据,有矢量数据的Coverage.Shapefile.dwg/dxf文件,栅格数据的BMP.GRID.控件数据库等.很多 ...
随机推荐
- 8 Types Of Friends You Need To Have in Your Life
8 Types Of Friends You Need To Have in Your Life一生中应该有的8种类型的朋友Did you know that people without frien ...
- jq 幻灯片插件制作
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- [iOS]ARC和MRC下混编
1.在MRC工程中使用ARC的文件(例如AFNetworking,SDWebImage,MJRefresh等)在Build Phases里找到对应.m 在后面添加-fobjc-arc(代表这个文件使用 ...
- Android APP安全评估工具 Drozer - 使用介绍
一.列出drozer当前可用的所有模块dz> list dz> list app.activity.forintent Find activities that can handle th ...
- 基于webpivottable做的透视表
1.绑定数据和配置: var wptConfig=<%= wptConfig%>; webPivotTable.setCsvData(<%=dataFields %>, < ...
- 文件相关操作工具类——FileUtils.java
文件相关操作的工具类,创建文件.删除文件.删除目录.复制.移动文件.获取文件路径.获取目录下文件个数等,满足大多数系统需求. 源码如下:(点击下载 FileUtils.java) import jav ...
- Newtonsoft.Json高级用法 1.忽略某些属性 2.默认值的处理 3.空值的处理 4.支持非公共成员 5.日期处理 6.自定义序列化的字段名称
手机端应用讲究速度快,体验好.刚好手头上的一个项目服务端接口有性能问题,需要进行优化.在接口多次修改中,实体添加了很多字段用于中间计算或者存储,然后最终用Newtonsoft.Json进行序列化返回数 ...
- 《OD学hadoop》第一周0625 LINUX作业一:Linux系统基本命令(一)
1. 1) vim /etc/udev/rules.d/-persistent-net.rules vi /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE= ...
- oracle创建表空间、创建用户、授权、夺权、删除用户、删除表空间
表空间定义 表空间是为了统一ORACLE物理和逻辑上的结构而专门建立的,从物理上来说,一个表空间是由具体的一个或多个磁盘上数据文件构成的(至少1对1,可以1对多),从逻辑上来说一个表空间是由具体的一个 ...
- java.io.EOFException java.io.ObjectInputStream$PeekInputStream.readFully 错误
Tomcat 启动时 java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully 错误 这 个错误 碰到好几 ...