How to work with the snap environment

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

时间: 2024-11-05 12:30:05

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

Ieditor

Interfaces Description IActiveViewEvents (esriCarto) Provides access to events that occur when the state of the active view changes. IAttributeTransferType Provides access to members that control the behavior of the attribute transfer interfaces. IEd

helloworld Snap例程

我们在很多的语言开发中都少不了使用"Hello, the world!"来展示一个开发环境的成功与否,在今天的教程中,我们也毫不例外地利用这个例子来展示snap应用是如何构建的.虽然这个例子很简单,但是在我们进入例程的过程中,我们会慢慢地发现有关snap系统的一些特性,这样可以更好地帮助我们来了解这个系统.如果大家想了解16.04的桌面对snap的支持,请参阅文章"安装snap应用到Ubuntu 16.4桌面系统". 1)从Snap商店中安装hello-world应用 我们可以通过如下的命令在S

How to enable C development in a Windows 10 development environment VM

To enable C development in a Windows 10 development environment VM, follow these steps: Start VS in the Windows 10 development environment VM. Choose "File" -> "New" -> "Project", choose "Open Visual Studio Install

利用letsencrypte生成证书时,create virtual environment失败

./letsencrypt-auto certonly --standalone 利用letsencrypt生成证书时 ,出现下面错误提示 0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded. Creating virtual environment... Traceback (most recent call last): File "/usr/lib/python3/dist-packages/virtualenv.py

windows tomcat 启动报错TOMCAT JAVA_HOME or JRE_HOME environment variable is not defined correctly

问题描述: TOMCAT JAVA_HOME or JRE_HOME environment variable is not defined correctly 报错信息如下:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program;提示找不到java_home各jre

-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.chan

第一次使用Maven ,在eclipse中执行pom.xml文件的时候报错. -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match. 参考网上的解决方案: 设一个环境变量M2_HOME指向你的maven安装目录 M2_HOME=D:\Apps\apache-maven-3.3.1 然后在Window->Prefe

ubuntu 修改environment导致无法启动

给ubuntu安装idk maven时修改了environment,想在此配置jdk maven.但是到用户输入密码界面输入密码后无法进入桌面. 解决方法: 1.按ctrl+alt+f1进入命令提示符界面 在此界面会发现常用命令 如 ls vi sudo等都无法使用,这是因为environment出错导致它配置的环境变量失效,想要使用得使用全路径 如:/usr/bin/sudo 2.删除添加的内容 /usr/bin/sudo /usr/bin/vi /etc/environment 3.重启后便

There is insufficient memory for the Java Runtime Environment to continue问题解决

在linux系统下长时间进行性能测试,连续几次发生服务器假死无法连接上的情况,无奈只能重启服务器.在测试路径下发现hs_err_pid17285.log文件,打开文件查看其主要内容如下: # There is insufficient memory for the Java Runtime Environment to continue.# Cannot create GC thread. Out of system resources.# Possible reasons:#   The sy

Coursera compiler Set up environment and Run first program

Environment, Ubuntu 14.04 set up guide Set up cool compiler 1. sudo apt-get install flex bison build-essential csh openjdk-6-jdk libxaw7-dev libc6-i386 2. Make the /usr/class directory sudo mkdir /usr/class 3. Make the directory owned by you sudo cho