原文 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. Zabbix监控解决方案

    思通运维监控主要用来监控IT 基础设施组件的可用性和性能.监控项目是不受限制的,并且可以对IT 基础设施健康状态进行复杂分析.通过确定IT 系统问题的“来源”,使用户快速响应故障来降低宕机成本. 网络 ...

  2. iOS开发--成员变量与属性

    属性变量 @interface MyClass:NSObject{ MyObjecct *_object; } @property(nonamtic, retain) MyObjecct *objec ...

  3. Jenkins 构建JavaHelloWorld

    原文:http://www.cnblogs.com/itech/archive/2011/11/03/2234662.html 注意:我们知道Jenkins通过master/slave来支持分布式的j ...

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

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

  5. java实现给图片添加水印

    package michael.io.image; import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.aw ...

  6. Asterisk的配置详解

    Asterisk的配置文件都在/etc/asterisk目录下,重要的配置文件有: sip.conf                      sip电话基本配置 extensions.conf    ...

  7. spring3定时器简单配置

    最近在做oa项目中写到一个功能,就是员工每天的签到和签退.当时想了很久都没有想出来,后来自己上网查了一下spring的定时器,然后就有了思路. 下面我贴上自己用到的这个定时器的配置.希望能够和大家一起 ...

  8. PCB阻抗调节

    在PCB厂家调节的阻抗指的是:传输线的“特征阻抗”,反映传输线上所走“行波”某点的电压和电流的比值,与线长无关.传输线本身的特性. 线宽:反比 介质厚度:正比

  9. 51nod 1050 循环数组最大子段和 (dp)

    http://www.51nod.com/onlineJudge/questionCode.html#problemId=1050&noticeId=13385 参考:http://blog. ...

  10. Model Browser

    http://www.entityframeworktutorial.net/model-browser-in-entity-framework.aspx We have created our fi ...