ArcGIS Engine 捕捉

原文 ArcGIS Engine 捕捉

bool bCreateElement = true;
int internalTime = 5;//时间间隔
int snapTime = 10;//初始值
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 == 0)
    snapPoint = Snapping(e.mapX, e.mapY, m_iFeatureLyr,     axMapControl1);
    if (snapPoint != null && snapTime == 0)
    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, 8);
    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 = 0;
    int partIndex = 0;
    int vertexIndex = 0;
    bool bVertexHit = false;
    // Tolerance in pixels for line hits
    double tol = ConvertPixelsToMapUnits(iView, 8);

    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 = 0;
    iColor.Blue = 100;
    iColor.Green = 255;
    iSym.Color = iColor;
    IRgbColor iColor2 = new RgbColor();
    iColor2.Red = 0;
    iColor2.Blue = 0;
    iColor2.Green = 0;
    iSym.Outline = true;
    iSym.OutlineColor = iColor2 as IColor;
    iSym.OutlineSize = 1;
    iSym.Size = 5;
    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, 0);
    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 = 0; 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;
}
时间: 2024-08-03 16:16:45

ArcGIS Engine 捕捉的相关文章

C# Arcgis Engine 捕捉功能实现

namespace 捕捉 { public partial class Form1 : Form { private bool bCreateElement=true; private int internalTime = 5; private int snapTime = 10; private IElement m_element = null; IPoint currentPoint=new PointClass(); private IPoint snapPoint = null; IM

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

原文:利用ArcGIS Engine.VS .NET和Windows控件开发GIS应用 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署应用的方法和步骤. 你可以在下面的目录下找到相应的样例程序: <安装目录>\DeveloperKit\Samples\Developer_Guide_Scenarios\ ArcGIS_Engine\Building_an_ArcGIS_Control_Application\Map_Viewer 注:ArcGIS样

Arcgis Engine 10.2安装过程

安装顺序 : VS2010-->Arcgis 10.2-->Arcgis engine 10.2-->ArcObjects SDK for Microsoft.NET Framework. vs2010安装方式略 一.Arcgis10.2安装 选择ArcGIS10.2 解压后的安装包中ESRI.exe文件 第一步安装ArcGIS License Manager (选择合适路径,基本一路回车) 安装好以后,启动License Manager,选择停止 第二步安装ArcGIS for  De

ArcGIS Engine开发前基础知识(4)

ArcGIS不同开发方式的比较 关于GIS应用软件的开发,通常有三种方式:C/S架构.网络GIS和移动GIS.ArcGIS平台提供了对三种开发方式的支持,对于采用从C/S架构的大多数开发者来讲,首先想到的是ArcGIS Engine进行开发.实际上,并不是所有的系统都必须采用这种方式,上述的三种开发方式(VBA.DLL和Add-in)在很多的时候也可以考虑. 作为VB的子集,VBA方式采用Visual Basic语言规范,简单易学,开发者只需要关注自己需要而ArcGIS没有直接提供的功能.对于广

ArcGIS Engine中正确释放打开资源

转自原文 ArcGIS Engine中正确释放打开资源 AE中对MDB,SDE等数据库操作时,打开后却往往不能及时释放资源,导致别人操作提示对象被锁定. 很多帖子说了很多原理,看的也烦且不实用,比如一句话概括的用System.Runtime.InteropServices.Marshal.ReleaseComObject(object o)释放,说的很不清楚,很多人试过觉的释放不掉. 事实上,的确是用该方法,但释放的技巧在于,新建几个AE对象就要逐步释放几个,例如: IWorkspaceFact

ArcGIS 9.3下载,包含ArcGIS Desktop、ArcGIS Engine、ArcGIS Server、ArcSDE、workstation

KeyWord:ESRI ArcGIS 9.3 Desktop Server Engine ArcEngine ArcIMS ArcSDE Workstation ECP Lisence Crack 破解 许可 下载 新增ArcGIS 9.3的电驴下载地址(都是windows版本的),具体的使用与设置或者版本问题请自行Google.感谢三脚猫群友提供地址. ArcGIS_Server_Java_Editioned2k://|file|ArcGIS_Server_Java_Edition.rar|

ArcGIS Engine开发模板及代码

以下为AE开发软件自带的模板及代码,开发工具为VS 2012+ArcGIS Engine 10.2. using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Runtime.InteropServices; using

J2EE(java)后台调用ArcGIS Engine(AE)的部署和代码

arcgis的BS开发解决方案一直是个坑,主推的地图服务查询速度慢,需要异步,功能少.相对来说主要用于CS的AE功能更强大全面,只是部署有点复杂 本文软件环境: win7 sp1 64位 MyEclipse 10,jdk 1.6.45 32位,tomcat 6.0.41 32位,ArcGIS Desktop 10.0(或ArcGIS Engine) 1.1.1.   安装软件 ArcGIS Desktop或ArcGIS Engine Runtime 建议装desktop,因为AE Runtime

ArcGIS Engine 编辑- ITask

转自原文ArcGIS Engine 编辑- ITask 下面的代码是我们定制的一个工作流-给等高线赋值 namespace EngineApplication { [Guid("5b0c0692-eaf7-4d64-9cee-c8c1afaf06f4")] [ClassInterface(ClassInterfaceType.None)] [ProgId("EditeTest.ContourTask")] public class CalculateContour