原文 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. Winsock IOCP模型(四篇)

    http://blog.csdn.net/visualeleven/article/details/6041893 http://blog.csdn.net/visualeleven/article/ ...

  2. 改变dijit的长度的心得

    改变dijit的长度要进入到里面改 如dijit/form/Select   (以table的方式来组合控件) 改变的时候,先找到dijitButtonContent 然后在后面样式文件里写就可以了 ...

  3. Mysql日期和时间函数不求人

    这里是一个使用日期函数的例子.下面的查询选择了所有记录,其date_col的值是在最后30天以内: mysql> SELECT something FROM table  WHERE TO_DA ...

  4. 305. Number of Islands II

    题目: A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand  ...

  5. Java:网络编程之IP、URL

    java.net  类 InetAddress 此类表示互联网协议 (IP) 地址. 会抛出异常 UnknownHostException   直接已知子类:         Inet4Address ...

  6. Android ScaleAnimation类:尺寸变化动画类

    ScaleAnimation类是Android系统中的尺寸变化动画类,用于控制View对象的尺寸变化,该类继承于Animation类. ScaleAnimation类中的很多方法都与Animation ...

  7. 【python爬虫】根据查询词爬取网站返回结果

    最近在做语义方面的问题,需要反义词.就在网上找反义词大全之类的,但是大多不全,没有我想要的.然后就找相关的网站,发现了http://fanyici.xpcha.com/5f7x868lizu.html ...

  8. Eclipse中遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误

    原因:某个项目需要的jar包没有导入 参考文章:http://www.blogjava.net/zJun/archive/2007/10/16/153374.html

  9. hive报错 Another instance of Derby may have already booted the database

    刚装好hive后,启动之后showtables;等正常,退出之后再进入,就发现会报错 Caused by: ERROR XSDB6: Another instance ofDerbymay have ...

  10. c++ 在客户端的GCC使用

    c++ 在客户端的GCC使用 翻译自: GCC是GNU工具箱的一个功能,GNU还包括如下功能: GNU compiler collection (GCC) GNU make GNU Debugger ...