I am writing some ArcGIS Server Geoprocessing tools in .Net but have posted a quick and dirty VB6 Desktop command example below in order to demonstrate the issue I am having.
I set a number of environment settings on my GP object using the GP.SetEnvironmentValue(environmentName as String, Value) method and then create a random raster. The environemnt variables I set work correctly and the Raster is created as I would expect.
Once this is complete, I persist the GP settings to disk as XML using the GP.Savesettings(FileName) method.
I then reload the settings using the GP.LoadSettings(FileName) method and create a second random raster. The second raster is different from the first and is blissfully unaware of the original environment settings.
The XML file is being written and does contain a bunch of XML tags and information, but on visually inspecting the contents of the file does not contain any of the environment settings I defined prior to writing the file. The GP.LoadSettings(FileName) method runs without error and overwrites my initial settings with the blanks contained in the file.
Is this a bug or am doing something stupid.
Thanks in advance for any help.
Ryan Gandy
Private Sub ENTEMP_Click()
Dim GP As IGeoProcessor
Set GP = New GeoProcessor
'Set up the GP Environment
'--------------------------
GP.OverwriteOutput = True 'GP Overwrite Flag
GP.SetEnvironmentValue "CellSize", 105 'Load the cell size into the environment
GP.SetEnvironmentValue "Extent", "394023, 4978637, 493773, 5083532" 'Set GP Extent
'Set up the storage locations for output
'----------------------------------------
'Define Directory to store the output rasters and environment settings file
Dim TempStorage As String
TempStorage = "D:\Temp"
'Define a path for the first output raster
Dim OutputRaster1 As String
OutputRaster1 = TempStorage & "\" & "OutRas1"
'Define a path for the Second output raster
Dim OutputRaster2 As String
OutputRaster2 = TempStorage & "\" & "OutRas2"
'Define a settings file path
Dim SettingsPath As String
SettingsPath = TempStorage & "\Settings.xml"
'Set up the GP Parameters and create the first random raster
'--------------------------------------------------
'Create an array to store GP parameters
Dim Params As IVariantArray
Set Params = New VarArray
'Set the parameters for the first Raster
Params.Add (OutputRaster1) 'Output Path
Params.Add ("1") 'Seed
GP.Execute "CreateRandomRaster_sa", Params, Nothing
'Store, Verify and Reload the Environment Settings to and from an XML file
'---------------------------------------------
GP.SaveSettings SettingsPath
'Remove Parameters from the Geoprocessor
Params.RemoveAll
'Verify the Settings file exists
If Not (GetAttr(SettingsPath) And vbDirectory) = 0 Then
MsgBox "Settings File does not exist"
End
End If
'Load the environment settings from a file
GP.LoadSettings SettingsPath
'Set up the GP Parameters and create the Second random raster
'--------------------------------------------------
'Set the parameters for the second raster
Params.Add (OutputRaster2) 'Output Path
Params.Add ("1") 'Seed
GP.Execute "CreateRandomRaster_sa", Params, Nothing
End Sub