Select to view content in your preferred language

IGeoprocessor.SaveSettings and IGeoprocessor.LoadSettings not persisting settings

662
4
06-28-2010 10:21 AM
RyanGandy
Emerging Contributor
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
0 Kudos
4 Replies
GabrielHuot-Vézina
Emerging Contributor
Hi !

I just had the same problem but with Python and the new arcpy lib.

When I set my environments parameters, let's say refrenceScale, and save that into an XML with:
arcpy.SaveSettings(MyXML) and then load it with arcpy.LoadSettings(MyXML), the new referenceScale returns to "None"...

Somebody could try it on their computer to know if it is the same for everyone?

I have a W7 station with ArcGIS 10.0.

------------------------
In Pywin or Idle
------------------------
import arcpy

arcpy.env.referenceScale = "250000"

arcpy.SaveSettings(r'C:\Temp\Dummy.xml')

#Reset scale to none
arcpy.env.referenceScale = "0"

#Load the previous one
arcpy.LoadSettings(r'C:\Temp\Dummy.xml')

#Print out the results
print arcpy.env.referenceScale
-------------------------------------------
The print will show None but should show 250000.0

Gab
0 Kudos
GabrielHuot-Vézina
Emerging Contributor
Me again!

I just tried it out with the old way, arcgisscripting library, it doesn't work either, and I tried it out with 2 types of station, one 32bits and one 64 bits....

--------------
In pywin or Idle
--------------
import arcgisscripting
GP = arcgisscripting.create(10.0) #or 9.3, result is the same...

GP.LoadSettings(r'C:\Temp\Dummy.xml')
print GP.referenceScale
---------------
Gives me "None" again, when it should show 250000.0

Gab
0 Kudos
RyanGandy
Emerging Contributor
A quick update.
I have verified that this is a bug and logged it with ESRI. The defect number is NIM058729.

ESRI Redlands suggest the following workarounds...

1) have several collective groups of common settings for each particular tool or process where you would then call the appropriate set environment function prior to running that process.

2) The other this you could do is create your own python environment module, which would essentially be a more organized version of the above method.

I ended up implementing my own system by writing and reading XML to a text file.
Hope this helps,
Ryan
0 Kudos
GabrielHuot-Vézina
Emerging Contributor
Perfect !

I ended up implementing the same thing as you.

Hopefully it will be corrected in the next version of arc.

Gab
0 Kudos