原文 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. Spring学习总结(2)——Spring IOC的前世今生

    前些天,参与了公司内部小组的一次技术交流,主要是针对<IOC与AOP>,本着学而时习之的态度及积极分享的精神,我就结合一个小故事来初浅地剖析一下我眼中的“IOC前世今生”,以方便初学者能更 ...

  2. Java-J2SE学习笔记-字符串转化为二维数组

    1.字符串转化为二维Double数组 2.代码: package Test; public class TestDouble { public static void main(String[] ar ...

  3. WordPress定位当前使用模版

    把下面代码插入到wp-includes/template-loader.php,66行 if($_GET[tpl]=='die'){ die($template); } 浏览任意页面,在网址后加上&a ...

  4. iOS:UIView的block函数实现转场动画---双视图

    使用UIView动画函数实现转场动画——双视图 + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView durati ...

  5. Linux命令-mkdir

    mkdir用于创建空白文件夹 参数-p用于连续创建多层目录 参数-m用于创建自定义的目录权限 [root@localhost test]# mkdir a/b/c/d mkdir: 无法创建目录&qu ...

  6. mysql 日期

    数据类型 数据类型 格式 date YYYY-MM-DD datetime YYYY-MM-DD HH:MM:SS timestamp YYYY-MM-DD HH:MM:SS year YYYY 或 ...

  7. VMware VMware各版本

    VMware各版本 一.VMware  vSphere5: VMware vSphere5 取代原 VMware ESX 二.VMware ESXI/VMware Citrix/VMware XenS ...

  8. Android 代码监控apk安装,卸载,替换

    public class GetBroadcast extends BroadcastReceiver { private static GetBroadcast mReceiver = new Ge ...

  9. hihoCoder 1039字符消除 (字符串处理)

    http://hihocoder.com/problemset/problem/1039 因为字符串只由3种字母组成,并且插入的字符也只能是这三种字符的其中一个,那么可以考虑枚举这三个字符其中一个字符 ...

  10. [HDOJ3466]Proud Merchants(贪心+01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3466 n个商人,每个商人有一个物品,物品有价格p.价值v还有一个交易限制q.q的意义是假如你现在拥有的 ...