How to work with the snap environment

SummaryThe snap environment manages snap agents and snap tolerance and is responsible for attempting to snap vertices and points using the snap environment settings. This topic includes code examples and methods to best manage snapping programmatically.

In this topic


Working with the snap environment

The ArcGIS Engine editor's snap environment (IEngineSnapEnvironment) controls each snap agent (IEngineSnapAgent), hit type settings, and snapping tolerance. The hit type of each feature snap agent is managed through the IEngineFeatureSnapAgent interface. All settings can be manually modified or verified on the Snapping Settings dialog box. See the following screen shot:

The ArcGIS Engine editor's snap environment also controls the snap tolerance. If required, you can provide an interface to allow the end user to manage the snap tolerance.
See the following code example to set up basic snap environment settings and turn on snap tips:

[C#]

publicvoid SnapEnvirSettings(IEngineEditor editor)
{
//Get the snap environment from the editor.
IEngineSnapEnvironment snapEnvironment = editor as IEngineSnapEnvironment; //Ensure there is a snap agent turned on in the snap environment.if (snapEnvironment.SnapAgentCount == 0)
{
System.Windows.Forms.MessageBox.Show(
"You need to turn on at least one snapping agent!!!");
return ;
} //Code to display the snap tolerance in a message box. double tolerance = snapEnvironment.SnapTolerance;
System.Windows.Forms.MessageBox.Show(Convert.ToString(tolerance)); //Set the snap tolerance.
snapEnvironment.SnapToleranceUnits =
esriEngineSnapToleranceUnits.esriEngineSnapToleranceMapUnits;
snapEnvironment.SnapTolerance = 15; //Turn on snap tips.
((IEngineEditProperties2)editor).SnapTips = true;
}

[VB.NET]

PublicSub SnapEnvirSettings(ByVal editor As IEngineEditor)
'Get the snap environment from the editor.Dim snapEnvironment As IEngineSnapEnvironment = editor As IEngineSnapEnvironment 'Ensure there is a snap agent turned on in the snap environment.If snapEnvironment.SnapAgentCount = 0 Then
System.Windows.Forms.MessageBox.Show("You need to turn on at least one snapping agent!!!")
ReturnEndIf'Code to display the snap tolerance in a message box.Dim tolerance AsDouble = snapEnvironment.SnapTolerance
System.Windows.Forms.MessageBox.Show(Convert.ToString(tolerance)) 'Set the snap tolerance.
snapEnvironment.SnapToleranceUnits = esriEngineSnapToleranceUnits.esriEngineSnapToleranceMapUnits
snapEnvironment.SnapTolerance = 15 'Turn on snap tips.
((IEngineEditProperties2)editor).SnapTips = TrueEndSub
This method checks the snap environment for selected snap agents. Feature snap agents are checked if the HitPartType is not equal to esriGeometryPartNone. The other snap agents are only registered if they are checked; therefore, if the number of snap agents is greater than the number of feature snap agents, a snap agent (sketch snap agent) is checked.
See the following code example:

[C#]

privatebool CheckIsAnySnapAgentSelected(IEngineSnapEnvironment snapEnvironment)
{
int snapAgentCount = snapEnvironment.SnapAgentCount;
int checkedFeatureSnapAgentCount = 0;
int featureSnapAgentCount = 0; //Loop through all registered snap agents in the snap environment. Count feature snap agents,//checked feature snap agents, and nonfeature snap agents.for (int i = 0; i < snapAgentCount; i++)
{
IEngineSnapAgent currentSnapAgent = snapEnvironment.get_SnapAgent(i);
if (currentSnapAgent is IEngineFeatureSnapAgent)
{
IEngineFeatureSnapAgent featureSnapAgent = currentSnapAgent as
IEngineFeatureSnapAgent;
featureSnapAgentCount++; //Determine if the feature snap agent is checked.if (featureSnapAgent.HitType !=
esriGeometryHitPartType.esriGeometryPartNone)
{
checkedFeatureSnapAgentCount++;
}
}
}
if (checkedFeatureSnapAgentCount > 0 || snapAgentCount > featureSnapAgentCount)
{
returntrue;
}
else
{
returnfalse;
}
}

[VB.NET]

PrivateFunction CheckIsAnySnapAgentSelected(ByVal snapEnvironment As IEngineSnapEnvironment) AsBooleanDim snapAgentCount AsInteger = snapEnvironment.SnapAgentCount
Dim checkedFeatureSnapAgentCount AsInteger = 0
Dim featureSnapAgentCount AsInteger = 0 'Loop through all registered snap agents in the snap environment. Count feature snap agents,'checked feature snap agents, and nonfeature snap agents.Dim i AsIntegerFor i = 0 To snapAgentCount - 1 Step i + 1
Dim currentSnapAgent As IEngineSnapAgent = snapEnvironment.get_SnapAgent(i)
IfTypeOf currentSnapAgent Is IEngineFeatureSnapAgent ThenDim featureSnapAgent As IEngineFeatureSnapAgent = currentSnapAgent As IEngineFeatureSnapAgent
featureSnapAgentCount = featureSnapAgentCount + 1 'Determine if the feature snap agent is checked.If featureSnapAgent.HitType <> esriGeomeTryHitPartType.esriGeomeTryPartNone Then
checkedFeatureSnapAgentCount = checkedFeatureSnapAgentCount + 1
EndIfEndIfNextIf checkedFeatureSnapAgentCount > 0 Or snapAgentCount > featureSnapAgentCount ThenReturnTrueElseReturnFalseEndIfEndFunction

Snap agents

Snap agents implement the IEngineSnapAgent interface and, when registered as a component category, are inserted into the ESRI snap agents component category. However, the feature snap agent (IEngineFeatureSnapAgent) is a more detailed class of snap agent, and each feature class has a feature snap agent instantiated when the snap environment window is first opened, if it hasn’t already been created programmatically.
See the following code example showing how to create a feature snap agent programmatically:

[C#]

publicvoid AddNewSnapAgent()
{
IEngineEditor editor = new EngineEditorClass();
IEngineEditLayers editLayers = editor as IEngineEditLayers;
IEngineSnapEnvironment snapEnvironment = editor as IEngineSnapEnvironment; //Check that the user is editing; otherwise, there will be no snap agent loaded.if (editLayers.TargetLayer == null)
{
System.Windows.Forms.MessageBox.Show("Please start an edit session");
return ;
} //Clear all existing snap agents.
snapEnvironment.ClearSnapAgents(); //Create a feature snap agent.
IEngineFeatureSnapAgent featureSnapAgent = new EngineFeatureSnap();
IFeatureClass layerFeatureClass = editLayers.TargetLayer.FeatureClass;
featureSnapAgent.FeatureClass = layerFeatureClass;
featureSnapAgent.HitType = esriGeometryHitPartType.esriGeometryPartBoundary; //Activate only the snap agent for the target layer.
snapEnvironment.AddSnapAgent(featureSnapAgent);
}

[VB.NET]

PublicSub AddNewSnapAgent()
Dim editor As IEngineEditor = New EngineEditorClass()
Dim editLayers As IEngineEditLayers = editor As IEngineEditLayers
Dim snapEnvironment As IEngineSnapEnvironment = editor As IEngineSnapEnvironment 'Check that the user is editing; otherwise, there will be no snap agent loaded.If editLayers.TargetLayer IsNothingThen
System.Windows.Forms.MessageBox.Show("Please start an edit session")
ReturnEndIf'Clear all existing snap agents.
snapEnvironment.ClearSnapAgents() 'Create a feature snap agent.Dim featureSnapAgent As IEngineFeatureSnapAgent = New EngineFeatureSnap()
Dim layerFeatureClass As IFeatureClass = editLayers.TargetLayer.FeatureClass
featureSnapAgent.FeatureClass = layerFeatureClass
featureSnapAgent.HitType = esriGeomeTryHitPartType.esriGeomeTryPartBoundary 'Activate only the snap agent for the target layer.
snapEnvironment.AddSnapAgent(featureSnapAgent)
EndSub
Programmatically changing the snap environment parameters does not require opening the snap window to change the settings. In ArcGIS Engine, the snap window reflects the snap environment settings while it is open. All IEngineSnapAgents, such as the edit sketch vertices snap agent, are visible on the snap window even if they have been programmatically removed; this allows the end user to turn them on and off as needed.

Snapping in z-dimension

ArcGIS Engine does not currently support snapping in z-dimension.

Snap point method

To use the SnapPoint method from the IEngineSnapEnvironment interface, an IPoint is passed to the method and used to find the closest feature to snap to. Using SnapPoint calls the IEngineSnapAgent.Snap method to then call each snap agent in priority order until it finds one that returns true. This results in new coordinates that are then assigned to the original point.
The order in which snap agents are added to the snap environment determines the priority of snap agents. This priority order is reflected in the snap environment window and can be changed using the window.

See Also:

IEngineEditProperties2.SnapTips Property

How to work with the snap environment的更多相关文章

  1. Ieditor

    Interfaces Description IActiveViewEvents (esriCarto) Provides access to events that occur when the s ...

  2. arcgis arcengine Using environment settings

    In this topic About using environment settings Environment settings summary table About using enviro ...

  3. 重新想象 Windows 8 Store Apps (56) - 系统 UI: Scale, Snap, Orientation, High Contrast 等

    [源码下载] 重新想象 Windows 8 Store Apps (56) - 系统 UI: Scale, Snap, Orientation, High Contrast 等 作者:webabcd ...

  4. 关于Ubuntu中snap安装软件太慢解决办法

    两种方法,一是下载好包手动安装,二设置snap的代理. 下载安装包方式 到 https://uappexplorer.com/snaps 搜索需要的 snap 包,然后下载 下载的时候选择对应的平台. ...

  5. deepin20使用snap并设置代理

    snap下载 $ sudo apt update $ sudo apt install snapd https://snapcraft.io/docs/installing-snap-on-ubunt ...

  6. OpenCloudOS使用snap安装.NET 6

    开源操作系统社区 OpenCloudOS 由腾讯与合作伙伴共同倡议发起,是完全中立.全面开放.安全稳定.高性能的操作系统及生态.OpenCloudOS 沉淀了多家厂商在软件和开源生态的优势,继承了腾讯 ...

  7. IEEE 802.11p (WAVE,Wireless Access in the Vehicular Environment)

    IEEE 802.11p(又称WAVE,Wireless Access in the Vehicular Environment)是一个由IEEE 802.11标准扩充的通讯协定.这个通讯协定主要用在 ...

  8. 修改/etc/profile和/etc/environment导致图形界面无法登陆的问题

    在使用ubuntu开发时,往往要修改PATH变量,有时会通过修改/etc/profile和/etc/environment来修改默认的PATH变量,但是一旦出错,很容易造成无法登陆进入图形界面的问题. ...

  9. System.Environment.CurrentDirectory和Application.StartupPath

    System.Environment.CurrentDirectory的含义是获取或设置当前工作路径,而Application.StartupPath是获取程序启动路径,表面上看二者没什么区别,但实际 ...

随机推荐

  1. 解决git commit 遇到datached HEAD问题

    git detached HEAD 你可以认为 HEAD(大写)是”current branch”(当下的分支).当你用git checkout切换分支的时候,HEAD 修订版本重新指向新的分支. 有 ...

  2. OS之内存管理 ---基本的内存管理策略(二)

    分段 基本方法 分段就是基于用户视图的内存管理方案.逻辑地址空间是由一组段构成的,每个段都有名称和长度.地址指定了段名称和段内偏移.因此用户通过两个量来指定地址:段名称和段偏移. 为了简单,进行对段的 ...

  3. (转)MySQL详解--锁

    原文:http://blog.csdn.net/xifeijian/article/details/20313977 锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源( ...

  4. php如何使用rabbitmq实现发布消息和消费消息(tp框架)(第一篇)

    1,默认已经安装好了rabbitmq: 参考 http://www.cnblogs.com/spicy/p/7017603.html 2,安装rabbitmq客户端: 方法1: pecl 扩展安装  ...

  5. linux安装扩展总结

    ---恢复内容开始--- 1.安装php 模块安装命令. wget http://pear.php.net/go-pear 执行 php go_pear 如果是php7 wget http://pea ...

  6. Android Studio打开项目提示找不到sdk路径的问题。

    问题如图: 这是由于所打开的项目不是本机创建的,所使用的sdk路径不一致所导致. 解决方案: 打开项目所在目录,找到local.properties文件并打开,发现sdk.dir=D\:\\Andro ...

  7. 一个非常好用的图片切割工具(c# winform开发)

    本人业余时间开发了一个图片切割工具,非常好用,也很灵活! 特别对大型图片切割,更能体现出该软件的优势! 功能说明 可以设定切割的高度和宽度.切割线可以上下拖动,可以增加一个切割区域,可设定某个区域不参 ...

  8. 2013年8月12日Python的5个最有价值问题

    问:Python怎么在字典里删除值但保留相应的键 答: 假设3都在值里,而非键>>> for v in D1.values():...     if 3 in v:...       ...

  9. centos6安装docker,先升级系统内核

    安装docker,其他的源可能导致你的内核和docker的版本不一致,需要将系统内核升级至3.x 查看当前系统版本 cat /etc/issue 查看当前内核版本 uname -r #uname -a ...

  10. [转]Sql Server Report Service 的部署问题

    本文转自:https://www.cnblogs.com/syfblog/p/4651621.html 近期在研究SSRS部署问题,因为以前也用到过SSRS报表,但当时开发的报表是有专门的集成系统的, ...