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:\data\saltlake.gdb");
// Set the output coordinate system environment.
gp.SetEnvironmentValue("outputCoordinateSystem", @
"C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\UTM\Nad 1983\NAD 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:\data\saltlake.gdb")
'Set the output coordinate system environment.
gp.SetEnvironmentValue("outputCoordinateSystem", "C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\UTM\Nad 1983\NAD 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:\sdk\MyCustomSettings.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:\sdk\MyCustomSettings.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和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2013-11-16 arcgis10.2中文补丁包下载地址
2013-11-16 Arcengine10下载地址
2013-11-16 python <type 'exceptions.UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128)解决
2013-11-16 arcgis 绝对、相对、UNC 和 URL