原文 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 捕捉的更多相关文章

  1. C# Arcgis Engine 捕捉功能实现

    namespace 捕捉 { public partial class Form1 : Form { private bool bCreateElement=true; ; ; private IEl ...

  2. 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用

    Dixon 原文  用ArcGIS Engine.VS .NET和Windows控件开发GIS应用     此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...

  3. C#,ArcGIS Engine开发入门教程

    C#,ArcGIS Engine开发入门教程 转自:http://blog.csdn.net/yanleigis/article/details/2233674  目录(?)[+] 五实现 一 加载A ...

  4. ArcGIS Engine开发鹰眼图的功能(基础篇)

    鹰眼是用于调节全视域范围内主地图显示范围情况的副地图.它体现了地图整体与详细局部的关系. 用户可以通过鼠标单击或者画框等动作实现鹰眼与主地图的交互情况. 鹰眼功能的原理是通过主地图窗口的地图控件和鹰眼 ...

  5. ArcGIS Engine开发之图形查询

    图形查询是以用户通过鼠标操作生成的图形几何体为输入条件进行查询的查询,其查询结果为该几何体空间范围内的所有要素.常用的查询方式包括点选.线选.多边形选择.圆形选择和矩形选择等. 相关类与接口 图像查询 ...

  6. ArcGIS Engine开发之属性查询

    属性查询即基于空间数据的属性数据的查询,通过用户提交SQL语言中的where语句定义的查询条件,对属性数据进行搜索,从而得到查询结果的操作. 相关的类与接口 与属性查询功能相关的类主要有QureyFi ...

  7. ArcGIS Engine开发之地图基本操作(4)

    ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...

  8. ArcGIS Engine开发之地图基本操作(3)

    地图数据的加载 一.加载Shapefile数据 Shapefile文件是目前主流的一种空间数据的文件存储方式,也是不同GIS软件进行数据格式转换常用的中间格式.加载Shapefile数据的方式有两种: ...

  9. ArcGIS Engine开发之地图基本操作(2)

    地图数据的加载 1.加载地图文档 ArcGIS Engine支持加载多种类型的数据,有矢量数据的Coverage.Shapefile.dwg/dxf文件,栅格数据的BMP.GRID.控件数据库等.很多 ...

随机推荐

  1. activity 的四种启动方式

    Activity启动模式设置: <activity android:name=".MainActivity" android:launchMode="standar ...

  2. java 哪些情况下会使对象锁释放

    Java_多线程_锁释放 问:Java多线程运行环境中,在哪些情况下会使对象锁释放?答:由于等待一个锁的线程只有在获得这把锁之后,才能恢复运行,所以让持有锁的线程在不再需要锁的时候及时释放锁是很重要的 ...

  3. C语言运算符优先级表

    优先级 运算符 名称或含义 使用形式 结合方向 说明 1 [] 数组下标 数组名[常量表达式] 左到右   () 圆括号 (表达式)/函数名(形参表)   . 成员选择(对象) 对象.成员名   -& ...

  4. Swift 使用CollectionView 实现图片轮播封装就是这样简单

    前言: 这篇你可以学会自定义视图,创建collectionView,协议的使用,定时器; 自制图片 先上Demo:Github上封装好的下载即用, 好用请Star Thanks首先新建一个继承于UIV ...

  5. iOS开发--沙盒路径与操作文件

    获取应用沙盒根路径: -(void)dirHome{ NSString *dirHome=NSHomeDirectory(); NSLog(@"app_home: %@",dirH ...

  6. Java-马士兵设计模式学习笔记-桥接模式

    一.概述 1.桥接模式的应用情况:(1)两个维度扩展(2)排列组合 二.代码 1.Gift.java public class Gift { protected GiftImpl giftImpl; ...

  7. Jlink更新新固件USB连接不上的问题

    采购新买了一个jlink,在调试过程中发现不能使用.拿到手后对jink上电以后,发现灯不亮,到网上查了一下估计是固件损坏的原因,经过一番摸索从新更新了固件,然后可以正常使用了,下面说一下步骤: 新版的 ...

  8. hbase 学习笔记二----shell

          Hbase 是一个分布式的.面向列的开源数据库,其实现是建立在google 的bigTable 理论之上,并基于hadoop HDFS文件系统.     Hbase不同于一般的关系型数据库 ...

  9. C# 获取打印机状态

    public static string GetPrinterStatus(string PrinterName)    {    int intValue = GetPrinterStatusInt ...

  10. selenium支付高版本的FireFox

    http://blog.csdn.net/pw_windgod/article/details/6537409 15:22:12.031 WARN - GET /selenium-server/dri ...