ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Core.Geoprocessing Namespace / Geoprocessing Class / MakeEnvironmentArray Method
Example

In This Topic
    MakeEnvironmentArray Method
    In This Topic
    Helper function to create environment array, use named argument to set individual value.
    Syntax
    public static IReadOnlyList<KeyValuePair<string,string>> MakeEnvironmentArray( 
       object workspace,
       object packageWorkspace,
       object scratchFolder,
       object scratchGDB,
       object scratchWorkspace,
       object outputCoordinateSystem,
       object geographicTransformations,
       object extent,
       Nullable<int> retryOnFailures,
       object parallelProcessingFactor,
       Nullable<int> recycleProcessingWorkers,
       object cellAlignment,
       object cellSize,
       object cellSizeProjectionMethod,
       object mask,
       object snapRaster,
       object configKeyword,
       Nullable<int> autoCommit,
       Nullable<bool> maintainAttachments,
       Nullable<bool> maintainSpatialIndex,
       Nullable<bool> preserveGlobalIds,
       Nullable<bool> transferGDBAttributeProperties,
       Nullable<bool> qualifiedFieldNames,
       Nullable<bool> transferDomains,
       object XYDomain,
       object XYResolution,
       object XYTolerance,
       object MDomain,
       object outputMFlag,
       Nullable<double> MTolerance,
       Nullable<double> MResolution,
       object ZDomain,
       Nullable<double> outputZValue,
       object outputZFlag,
       object ZResolution,
       object ZTolerance,
       object randomGenerator,
       object cartographicCoordinateSystem,
       Nullable<double> referenceScale,
       object cartographicPartitions,
       Nullable<int> annotationTextStringFieldLength,
       object pyramid,
       object rasterStatistics,
       object compression,
       object tileSize,
       object resamplingMethod,
       object nodata,
       Nullable<bool> terrainMemoryUsage,
       object tinSaveVersion,
       object coincidentPoints,
       object S100FeatureCatalogueFile,
       object processorType,
       Nullable<int> gpuId,
       string processingServer,
       string processingServerUser,
       object processingServerPassword,
       Nullable<bool> matchMultidimensionalVariable,
       Nullable<bool> unionDimension,
       object baDataSource,
       object baNetworkSource,
       Nullable<bool> baUseDetailedAggregation,
       Nullable<bool> maintainCurveSegments,
       Nullable<bool> overwriteoutput
    )
    Public Shared Function MakeEnvironmentArray( _
       Optional ByVal workspace As Object, _
       Optional ByVal packageWorkspace As Object, _
       Optional ByVal scratchFolder As Object, _
       Optional ByVal scratchGDB As Object, _
       Optional ByVal scratchWorkspace As Object, _
       Optional ByVal outputCoordinateSystem As Object, _
       Optional ByVal geographicTransformations As Object, _
       Optional ByVal extent As Object, _
       Optional ByVal retryOnFailures As Nullable(Of Integer), _
       Optional ByVal parallelProcessingFactor As Object, _
       Optional ByVal recycleProcessingWorkers As Nullable(Of Integer), _
       Optional ByVal cellAlignment As Object, _
       Optional ByVal cellSize As Object, _
       Optional ByVal cellSizeProjectionMethod As Object, _
       Optional ByVal mask As Object, _
       Optional ByVal snapRaster As Object, _
       Optional ByVal configKeyword As Object, _
       Optional ByVal autoCommit As Nullable(Of Integer), _
       Optional ByVal maintainAttachments As Nullable(Of Boolean), _
       Optional ByVal maintainSpatialIndex As Nullable(Of Boolean), _
       Optional ByVal preserveGlobalIds As Nullable(Of Boolean), _
       Optional ByVal transferGDBAttributeProperties As Nullable(Of Boolean), _
       Optional ByVal qualifiedFieldNames As Nullable(Of Boolean), _
       Optional ByVal transferDomains As Nullable(Of Boolean), _
       Optional ByVal XYDomain As Object, _
       Optional ByVal XYResolution As Object, _
       Optional ByVal XYTolerance As Object, _
       Optional ByVal MDomain As Object, _
       Optional ByVal outputMFlag As Object, _
       Optional ByVal MTolerance As Nullable(Of Double), _
       Optional ByVal MResolution As Nullable(Of Double), _
       Optional ByVal ZDomain As Object, _
       Optional ByVal outputZValue As Nullable(Of Double), _
       Optional ByVal outputZFlag As Object, _
       Optional ByVal ZResolution As Object, _
       Optional ByVal ZTolerance As Object, _
       Optional ByVal randomGenerator As Object, _
       Optional ByVal cartographicCoordinateSystem As Object, _
       Optional ByVal referenceScale As Nullable(Of Double), _
       Optional ByVal cartographicPartitions As Object, _
       Optional ByVal annotationTextStringFieldLength As Nullable(Of Integer), _
       Optional ByVal pyramid As Object, _
       Optional ByVal rasterStatistics As Object, _
       Optional ByVal compression As Object, _
       Optional ByVal tileSize As Object, _
       Optional ByVal resamplingMethod As Object, _
       Optional ByVal nodata As Object, _
       Optional ByVal terrainMemoryUsage As Nullable(Of Boolean), _
       Optional ByVal tinSaveVersion As Object, _
       Optional ByVal coincidentPoints As Object, _
       Optional ByVal S100FeatureCatalogueFile As Object, _
       Optional ByVal processorType As Object, _
       Optional ByVal gpuId As Nullable(Of Integer), _
       Optional ByVal processingServer As String, _
       Optional ByVal processingServerUser As String, _
       Optional ByVal processingServerPassword As Object, _
       Optional ByVal matchMultidimensionalVariable As Nullable(Of Boolean), _
       Optional ByVal unionDimension As Nullable(Of Boolean), _
       Optional ByVal baDataSource As Object, _
       Optional ByVal baNetworkSource As Object, _
       Optional ByVal baUseDetailedAggregation As Nullable(Of Boolean), _
       Optional ByVal maintainCurveSegments As Nullable(Of Boolean), _
       Optional ByVal overwriteoutput As Nullable(Of Boolean) _
    ) As IReadOnlyList(Of KeyValuePair(Of String,String))

    Parameters

    workspace
    packageWorkspace
    scratchFolder
    scratchGDB
    scratchWorkspace
    outputCoordinateSystem
    geographicTransformations
    extent
    retryOnFailures
    parallelProcessingFactor
    recycleProcessingWorkers
    cellAlignment
    cellSize
    cellSizeProjectionMethod
    mask
    snapRaster
    configKeyword
    autoCommit
    maintainAttachments
    maintainSpatialIndex
    preserveGlobalIds
    transferGDBAttributeProperties
    qualifiedFieldNames
    transferDomains
    XYDomain
    XYResolution
    XYTolerance
    MDomain
    outputMFlag
    MTolerance
    MResolution
    ZDomain
    outputZValue
    outputZFlag
    ZResolution
    ZTolerance
    randomGenerator
    cartographicCoordinateSystem
    referenceScale
    cartographicPartitions
    annotationTextStringFieldLength
    pyramid
    rasterStatistics
    compression
    tileSize
    resamplingMethod
    nodata
    terrainMemoryUsage
    tinSaveVersion
    coincidentPoints
    S100FeatureCatalogueFile
    processorType
    gpuId
    processingServer
    processingServerUser
    processingServerPassword
    matchMultidimensionalVariable
    unionDimension
    baDataSource
    baNetworkSource
    baUseDetailedAggregation
    maintainCurveSegments
    overwriteoutput

    Return Value

    An IEnumerable of key-value pairs of type strings.
    Example
    FieldMappings
    var environment = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
    
          var prj = Project.Current;
          var map = MapView.Active;
    
          var defaultGDB = Project.Current.DefaultGeodatabasePath;
    
          var featLayers = map.Map.Layers.OfType<FeatureLayer>();
    
          var targetLayer = featLayers.ElementAt(0);  // First layer in TOC
          var joinLayer = featLayers.ElementAt(1);    // Second layer in TOC
    
          var outputFeatureClass = @"C:/temp/outputFC3.shp";
    
          // Specify the field map in Spatial Join with target and join feature class/layers in the App
          // Run Spatial Join manually - then Copy the fieldmap string from the result in Geoprocessing history and paste it for the fieldmap parameter. 
          // in this example of fieldmap, FireStations is the name of join layer
          // FireStations layer has two numeric fileds (used in Fieldmap): TYPE and NUMBER - these two fields are used in the FiedlMap
          //
          var joinLayerName = joinLayer.Name;
          var fieldMap = "TYPE 'TYPE' true true false 4 Long 0 0,Count,#,{joinLayerName},TYPE,-1,-1;NUMBER 'NUMBER' true true false 4 Long 0 0,Max,#,{joinLayerName},NUMBER,-1,-1";
    
          var toolParameters = Geoprocessing.MakeValueArray(targetLayer, joinLayer, outputFeatureClass, "JOIN_ONE_TO_ONE", "KEEP_COMMON", fieldMap, "INTERSECT");
    
          GPExecuteToolFlags executeFlags = GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory | GPExecuteToolFlags.RefreshProjectItems;
    
          IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("analysis.SpatialJoin", toolParameters, environment, null, null, executeFlags);
    
          Geoprocessing.ShowMessageBox(gpResult.Messages, "GP Messages", gpResult.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);
    gp_environments
    // get the syntax of the tool from Python window or from tool help page
    string in_features = @"C:\data\data.gdb\HighwaysWeb84";
          string out_features = @"C:\data\data.gdb\HighwaysUTM";
          var param_values = Geoprocessing.MakeValueArray(in_features, out_features);
    
          // crate the spatial reference object to pass as an argument to management.CopyFeatures tool
          var sp_ref = await QueuedTask.Run(() => {
              return SpatialReferenceBuilder.CreateSpatialReference(26911);    // UTM 83 11N: 26911
          });
    
          // set output coordinate system environment           
          var environments = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: sp_ref);
          // set environments in the 3rd parameter
          var gp_result = await Geoprocessing.ExecuteToolAsync("management.CopyFeatures", param_values, environments, null, null, GPExecuteToolFlags.AddOutputsToMap);
          
          Geoprocessing.ShowMessageBox(gp_result.Messages, "Contents", GPMessageBoxStyle.Default, "Window Title");
    
          //return gp_result;
    
    Set Geoprocessing extent environment
    var parameters = Geoprocessing.MakeValueArray(@"C:\data\data.gdb\HighwaysUTM11", @"C:\data\data.gdb\Highways_extent");
          var ext = Geoprocessing.MakeEnvironmentArray(extent: "460532 3773964 525111 3827494");
          var gp_result = await Geoprocessing.ExecuteToolAsync("management.CopyFeatures", parameters, ext);
    How to pass parameter with multiple or complex input values
    var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
    
          string toolName = "Snap_edit";  // or use edit.Snap
    
          // Snap tool takes multiple inputs each of which has
          // Three (3) parts: a feature class or layer, a string value and a distance
          // Each part is separated by a semicolon - you can get example of sytax from the tool documentation page
          var snapEnv = @"'C:/SnapProject/fgdb.gdb/line_1' END '2 Meters';'C:/SnapProject/fgdb.gdb/points_1' VERTEX '1 Meters';'C:/SnapProject/fgdb.gdb/otherline_1' END '20 Meters'";
    
          var infc = @"C:/SnapProject/fgdb.gdb/poly_1";
    
          var snapParams = Geoprocessing.MakeValueArray(infc, snapEnv);
    
          GPExecuteToolFlags tokens = GPExecuteToolFlags.RefreshProjectItems | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory;
    
          IGPResult snapResult = await Geoprocessing.ExecuteToolAsync(toolName, parameters, environments, null, null, tokens);
    
          //return gpResult;
    
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also