arcpy.sa.Spline issues in BETA2

3504
18
Jump to solution
02-27-2012 09:22 AM
Labels (1)
BKuiper
Occasional Contributor III
the arcpy.sa.Spline function in BETA 2 has some issues:

- the %scratchworkspace% variable is not populated. The %scratchworkspace% value is not replaced with the actual location of your scratchworkspace.
- A temporary file is created (spline_selecXX) in the parent directory of the specified input file.

Not sure if the later can be really considered a bug, but i was surprised to see this behavior.

Can you confirm these issues ? I can send you an example, but this should be really easy to replicate.

ps: I'm running arcpy.sa.Spline through a python script, in ArcCatalog.
0 Kudos
1 Solution

Accepted Solutions
MichaelBranscomb
Esri Frequent Contributor
Hi,

Sorry for the delay in getting back to you on this. Thanks for the excellent reproducer. I have tested with the latest ArcGIS Runtime local server and the latest WPF client assemblies and (without modification) your app produces the output below and [I think] a valid spline result (see attached screenshot of the result back in ArcMap). I believe this indicates you should be able to retest successfully in pre-release. You may just need to play around with the script to get the right output parameter (GPRasterData / GPDataFile) - or better would be a map server result which would then allow you to add the raster directly to the map as a dynamic map service layer. Alternatively, the dynamic layers functionality you were testing previously could be used to dynamically add rasters to an existing map service at runtime.

Submitted.
Executing...
Executing (Script): Script C:\WORK\PROJECTS\ArcGISRuntimeCRs\SplineTest\PoCSplineRuntime\shapefile\selection\selection0.shp
Start Time: Tue Mar 13 14:54:47 2012
Executing (Script): Script C:\WORK\PROJECTS\ArcGISRuntimeCRs\SplineTest\PoCSplineRuntime\shapefile\selection\selection0.shp
Start Time: Tue Mar 13 14:54:47 2012
Executing (Script): Script C:\WORK\PROJECTS\ArcGISRuntimeCRs\SplineTest\PoCSplineRuntime\shapefile\selection\selection0.shp
Start Time: Tue Mar 13 14:54:47 2012
Running script Script...
Workspace: c:\users\mbrans~1\appdata\local\temp\arcgisruntime_5020\script\jobs\script_gpserver\j38850bacf654422babed8dc177344f58\scratch
Output file: c:\users\mbrans~1\appdata\local\temp\arcgisruntime_5020\script\jobs\script_gpserver\j38850bacf654422babed8dc177344f58\scratch\result
Completed script Script...
Succeeded at Tue Mar 13 14:54:48 2012 (Elapsed Time: 1.00 seconds)
Succeeded at Tue Mar 13 14:54:48 2012 (Elapsed Time: 1.00 seconds)
Succeeded at Tue Mar 13 14:54:48 2012 (Elapsed Time: 1.00 seconds)
Invalid return value: c:\users\mbrans~1\appdata\local\temp\arcgisruntime_5020\script\jobs\script_gpserver\j38850bacf654422babed8dc177344f58\scratch\result
Failed.


Cheers

Mike

View solution in original post

0 Kudos
18 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

If you can send an example that would be much appreciated. Either attach to this thread or send to mbranscomb@esri.com.


Cheers

Mike
0 Kudos
BKuiper
Occasional Contributor III
I'm running the following script

--- SplineExample.py
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# SplineExampleScript.py
# Created on: 2012-02-28 10:11:31.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
selection0 = "selection0"
Z_value_field = "inmval"
Weight = "0.1"
Number_of_points = "12"
Output_raster = "C:\\YourDirectory\\Spline_selec3"
dstfile = "%scratchworkspace%\\Spline_selec3"

outSpline = Spline(selection0, "inmval", weight="0.1", number_points=24, spline_type="REGULARIZED")
outSpline.save(dstfile)
---

Just save it somewhere and include it in a Toolbox.

I use the attached shapefile and run it from ArcMap or ArcCatalog to demonstrate the problem.

The problem is that the %scratchworkspace% will not be populated with the value as specified in Geoprocessing->Environments->Workspace
0 Kudos
BKuiper
Occasional Contributor III
Here is an example what goes wrong:


Executing: Spline
Start Time: Tue Feb 28 10:14:00 2012
Running script Spline...

Traceback (most recent call last):
  File "C:\MyDirectory\Toolbox\SplineExampleScript.py", line 28, in <module>
    outSpline = Spline(selection0, "inmval", weight="0.1", number_points=24, spline_type="REGULARIZED")
RuntimeError: ERROR 000875: Output raster: c:\windows\system32\%scratchworkspace%\Spline_selec3's workspace is an invalid output workspace.

Failed to execute (Spline).
Failed at Tue Feb 28 10:14:02 2012 (Elapsed Time: 2.00 seconds)


normally %scratchworkspace% should be replaced with the directory specified in the geoprocessing environment and the c:\windows\system32 shouldn't be there.
0 Kudos
KevinHibma
Esri Regular Contributor
(I'm coming at this from the GP side - not so much the Runtime side)

Can you try replacing the %scratchworkspace% variable with %scratchFolder% and re-creating your gpk?

We've had issues (and I dont recall when we've fixed them exactly) where inline variables, like scratchworkspace were not being evaluated.
Even though scratchFolder is derived from scratchworkspace, they are handled in slightly different ways during the package creation process, thus might be behave differently on consumption.
0 Kudos
BKuiper
Occasional Contributor III
Hi Kevin,

You are right, this is not really a ArcGIS Runtime problem i guess. You mention changing the scratchworkspace to scratchFolder and then recreating the GPK, but actually i didn't create a GPK yet. I'm experiencing this problem when just running the Script from a Toolbox within ArcMap and/or ArcCatalog.

Changing it to scratchFolder doesn't solve the issue.


Executing: Spline
Start Time: Tue Feb 28 11:50:21 2012
Running script Spline...

Traceback (most recent call last):
  File "C:\AEDT_Repository\Developers\Foliage\ATMP\INMWeb\MAIN\Toolbox\SplineExampleScript.py", line 22, in <module>
    outSpline = Spline(selection0, "inmval", weight="0.1", number_points=24, spline_type="REGULARIZED")
RuntimeError: ERROR 000875: Output raster: c:\windows\system32\%scratchFolder%\Spline_selec3's workspace is an invalid output workspace.

Failed to execute (Spline).
Failed at Tue Feb 28 11:50:22 2012 (Elapsed Time: 1.00 seconds)


Note that i'm still running BETA 2 as i'm waiting for Runtime to hit Pre-release.

Here is the script that i tried:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# SplineExampleScript.py
# Created on: 2012-02-28 10:11:31.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
selection0 = "selection0"
dstfile = "%scratchFolder%\\Spline_selec3"

outSpline = Spline(selection0, "inmval", weight="0.1", number_points=24, spline_type="REGULARIZED")
outSpline.save(dstfile)
0 Kudos
KevinHibma
Esri Regular Contributor
Its obvious I havent had enough coffee yet... I just assumed this was on the consumption of the GPK.
My machine is updating, so I cant test your exact scenario right now, but the following code should work.
Notice the line I commented out and replaced with "almost" the same thing.


# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
selection0 = "selection0"
dstfile = arcpy.env.scratchFolder + "Spline_selec3"
#dstfile = "%scratchFolder%\\Spline_selec3"

outSpline = Spline(selection0, "inmval", weight="0.1", number_points=24, spline_type="REGULARIZED")
outSpline.save(dstfile) 


0 Kudos
KevinHibma
Esri Regular Contributor
Actually, this would be better than constructing paths with "+"

dstfile = os.path.join(arcpy.env.scratchFolder, "Spline_selec3")
0 Kudos
BKuiper
Occasional Contributor III
Great, that works. Both scratchWorkspace and scratchFolder can be used.

Nice workaround/trick for now.

here is the final example script:

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# SplineExampleScript.py
# Created on: 2012-02-28 10:11:31.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy, os
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
selection0 = "selection0"
Z_value_field = "inmval"
Weight = "0.1"
Number_of_points = "12"
Output_raster = "C:\\YourDirectory\\Spline_selec3"
#dstfile = "%scratchFolder%\\Spline_selec3"
#dstfile = os.path.join(arcpy.env.scratchFolder, "Spline_selec3")
dstfile = os.path.join(arcpy.env.scratchWorkspace, "Spline_selec3")

outSpline = Spline(selection0, "inmval", weight="0.1", number_points=24, spline_type="REGULARIZED")
outSpline.save(dstfile)
0 Kudos
KevinHibma
Esri Regular Contributor
I was just made aware this is logged, heres the tracking number:
NIM077457 - Raster save errors when using "%scratchworkspace%"  in output path.

Note - this is not fixed in the pre-release. You'll have to continue using the workaround till final. Sorry for the inconvenience, but big thanks on testing and reporting!
0 Kudos