• arcgis arcengine Using environment settings


    In this topic


    About using environment settings

    Each tool has a set of parameters it uses to execute an operation. Some of these parameters are common among all tools, such as a tolerance or output location. These parameters can obtain their default values from a geoprocessing environment that all tools utilize during their operation.
    When a tool is executed, the current environment settings can also be used as global input parameter values. Settings, such as an area of interest (extent), the coordinate system of the output dataset, and the cell size of a new raster dataset, can all be specified in the geoprocessing environments.
    In a program, the geoprocessor object possesses all default environment values. You can get the default value or change it. The environment values remain in effect within the current geoprocessing session. The following table shows the environment methods the geoprocessor has to work with:
    Method Description
    GetEnvironmentValue(envName) Retrieves the value of an environment by name.
    SetEnvironmentValue(envName, envValue) Updates the value of an environment by name.
    ResetEnvironments() Resets the environments to their default state.
    ListEnvironments("*") Returns the list of environments (properties).
    SaveSettings(sFileName) Saves the current settings (toolboxes, environments, and so on) to a file on disk in Extensible Markup Language (XML) format.
    LoadSettings(sFileName) Loads the current settings from the saved file.
    All environment names are passed as strings. Environment names are not case sensitive; therefore, it does not matter if "workspace" or "Workspace" is used.
    The following is a code example to set environment values. By default, the output of Copy Features geoprocessing tool gets the coordinate system of the input. By setting a different value, you override the default coordinate system.
    [C#]
    public void setCoordinateSystem(IGeoProcessor2 gp)
    {
        // Set overwrite option to true.
        gp.OverwriteOutput = true;
    
        // Set workspace environment.
        gp.SetEnvironmentValue("workspace", @"C:datasaltlake.gdb");
    
        // Set the output coordinate system environment.            
        gp.SetEnvironmentValue("outputCoordinateSystem", @
            "C:Program FilesArcGISDesktop10.0Coordinate SystemsProjected Coordinate SystemsUTMNad 1983NAD 1983 UTM Zone 12N.prj");
    
        IVariantArray parameters = new VarArrayClass();
        parameters.Add("roads");
        parameters.Add("roads_copy");
    
        gp.Execute("CopyFeatures_management", parameters, null);
    }
    [VB.NET]
    Public Sub setCoordinateSystem(ByVal gp As IGeoProcessor2)
        
        'Set overwrite option to true.
        gp.OverwriteOutput = True
        
        'Set workspace environment.
        gp.SetEnvironmentValue("workspace", "C:datasaltlake.gdb")
        
        'Set the output coordinate system environment.
        gp.SetEnvironmentValue("outputCoordinateSystem", "C:Program FilesArcGISDesktop10.0Coordinate SystemsProjected Coordinate SystemsUTMNad 1983NAD 1983 UTM Zone 12N.prj")
        
        Dim parameters As IVariantArray = New VarArray
        parameters.Add("roads")
        parameters.Add("roads_copy")
        
        gp.Execute("CopyFeatures_management", parameters, Nothing)
        
    End Sub
    The following code example shows how to retrieve and reset environment values:
    [C#]
    // Get the cell size environment value.
    object env = gp.GetEnvironmentValue("cellsize");
    
    // Reset the environment values to their defaults.
    gp.ResetEnvironments();
    [VB.NET]
    ' Get the cell size environment value.
    Dim env As Object = GP.GetEnvironmentValue("cellsize")
    
    ' Reset the environment values to their defaults.
    GP.ResetEnvironments()
    The ListEnvironments method returns a list of environments. This method has a wildcard option, and returns an IGpEnumList of strings that can be looped through. The following code example shows how to list environments. The method returns all environments that start with the letter "q" (for example, qualifedFieldNames).
    [C#]
    public void ListGeoprocessingEnvironments(IGeoprocessor2 gp)
    {
        // List all environments that start with the letter q.
        IGpEnumList environments = gp.ListEnvironments("q*");
    
        // Only one environment starts with q (qualifiedFieldNames).
        string env = environments.Next();
        Console.WriteLine(env);
    
    }
    [VB.NET]
    Public Sub ListGeoprocessingEnvironments(ByVal gp As IGeoProcessor2)
        
        'List all environments that start with the letter q.
        Dim environments As IGpEnumList = gp.ListEnvironments("q*")
        
        Dim env As String = environments.Next()
        
        'Only one environment starts with q (qualifiedFieldNames).
        Console.WriteLine(env)
        env = environments.Next()
        
    End Sub
    After setting several environments using the SetEnvironmentValue method, you can save them to an XML file, then use them later by loading the settings with the LoadSettings method as shown in the following code example:
    [C#]
    public void SaveLoadSettings(IGeoProcessor2 gp)
    {
        gp.SetEnvironmentValue("workspace", @"C:/data/mydata.gdb");
        gp.SetEnvironmentValue("extent", "-3532000, -911000, -3515000, -890000");
        gp.SetEnvironmentValue("outputCoordinateSystem", 
            "PROJCS['NAD_1983_UTM_Zone_11N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-117.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]");
    
        // Save environment settings to an XML file.
        string settingsFile = @"C:sdkMyCustomSettings.xml";
        gp.SaveSettings(settingsFile);
    
        // Load previously saved environment settings.
        gp.LoadSettings(settingsFile);
        object sExtent = gp.GetEnvironmentValue("workspace");
    }
    [VB.NET]
    Public Sub SaveLoadSettings(ByVal gp As IGeoProcessor2)
        
        gp.SetEnvironmentValue("workspace", "C:/data/mydata.gdb")
        gp.SetEnvironmentValue("extent", "-3532000, -911000, -3515000, -890000")
        gp.SetEnvironmentValue("outputCoordinateSystem", "PROJCS['NAD_1983_UTM_Zone_11N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-117.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]")
        
        ' Save environment settings to an XML file.
        Dim settingsFile As String = "C:sdkMyCustomSettings.xml"
        gp.SaveSettings(settingsFile)
        
        ' Load previously saved environment settings.
        gp.LoadSettings(settingsFile)
        Dim sExtent As Object = gp.GetEnvironmentValue("workspace")
        
    End Sub

    Environment settings summary table

    The following table shows the geoprocessing environments in alphabetical order. The first column in the table is the name of the environment. You must pass this name as a string to the geoprocessor's GetEnvironmentValue and SetEnvironmentValue methods. The second column is the display name as shown on the Environment Settings dialog box.
    Each environment display name in the table links to the reference page of that environment, which explains what the environment is for and what values can be set for it.
    Environment names are not case-sensitive in .NET.
    Environment name
    Display name
    autoCommit
    cartographicCoordinateSystem
    cellSize
    coincidentPoints
    compression
    configKeyword
    derivedPrecision
    extent
    geographicTransformations
    maintainSpatialIndex
    mask
    MDomain
    MResolution
    MTolerance
    newPrecision
    outputCoordinateSystem
    outputMFlag
    outputZFlag
    outputZValue
    projectCompare
    pyramid
    qualifiedFieldNames
    randomGenerator
    rasterStatistics
    referenceScale
    scratchWorkspace
    snapRaster
    spatialGrid1, 2, 3
    terrainMemoryUsage
    tileSize
    tinSaveVersion
    workspace
    XYDomain
    XYResolution
    XYTolerance
    ZDomain
    ZResolution
    ZTolerance


    See Also:

    What is a geoprocessing environment?
    A quick tour of geoprocessing environments




     
     
    作者: cglnet
    本文版权归cglNet和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    DevExpress控件开发常用要点(项目总结版)
    DevExpress BarManager 部分用法
    DevExpress LookUpEdit和ComboBoxEdit部分用法
    DevExpress GridControl 部分用法
    DevExpress 中 WaitForm 使用
    DevExpress汉化(WinForm)
    DevExpress 使用 XtraTabbedMdiManager 控件以 Tab样式加载 Mdi窗体并合并 RibbonControl 解决方案
    DevExpress 关于 GridView 表格编辑中 点击其他按钮里导致 值未取到处理
    DevExpress 中 在做全选的全消功能的时候 加快效率
    DevExpress后置代码中初始化SQL数据源的方法
  • 原文地址:https://www.cnblogs.com/gisoracle/p/6070208.html
Copyright © 2020-2023  润新知