Select to view content in your preferred language

Python Script failing to execute IDW_sa

1991
2
11-11-2010 04:28 PM
sethdocherty
Emerging Contributor
I'm currently doing a research project for school which requires me to interpolate recorded temperatures within in our study area. After the maps are made, I'm going to string them together into an animation to show temperature variations over time. I will end up having over 1000 maps interpolated so its out of the question to do them one at a time. I'm in the process of creating a script to automate this. To make the process of coding easier for myself, I created a setup in the model builder, which i ran successfully, and exported the code to python. My problems arises here... I run the code and get these errors:

Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Seth\Documents\summer project 2010\CommunityNet\python test\modelbuilder test1.py", line 32, in <module>
gp.Idw_sa(sensorlocation_shp, "8_2_2010_1", test1, "0.000265", "2", "VARIABLE 12", "")
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000860: Input point features: is not the type of Composite Geodataset, or does not exist.
ERROR 001000: Z value field: Field 8_2_2010_1 does not exist
ERROR 000876: Output raster: C:\Users\Seth\Documents\summer project 2010\CommunityNet\python test\modelbuilder test1.py's extension is invalid for the output raster format.
Failed to execute (Idw).

Here is my code for reference:

# ---------------------------------------------------------------------------
# modelbuilder test1.py
# Created on: Thu Nov 11 2010 08:20:08 PM
# (generated by ArcGIS/ModelBuilder)
# Usage: modelbuilder test1 <sensorlocation_shp> <test1>
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

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

# Load required toolboxes...
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")

# Script arguments...
sensorlocation_shp = sys.argv[0]
if sensorlocation_shp == '#':
sensorlocation_shp = "C:\\Users\\Seth\\Documents\\summer project 2010\\CommunityNet\\python test\\location\\sensorlocation.shp" # provide a default value if unspecified

test1 = sys.argv[0]
if test1 == '#':
test1 = "C:\\Users\\Seth\\Documents\\summer project 2010\\CommunityNet\\python test\\location\\test" # provide a default value if unspecified

# Local variables...

# Process: IDW...
gp.Idw_sa(sensorlocation_shp, "8_2_2010_1", test1, "0.000265", "2", "VARIABLE 12", "")
0 Kudos
2 Replies
BradPosthumus
Frequent Contributor
The input parameters are missing. Currently this script is using sys.argv[0] for both parameters. The first value in sys.argv is always the name of the script (which explains your error message).

Use:

sensorlocation_shp = sys.argv[1]

...for your input shapefile and:

test1 = sys.argv[2]

for your output raster. Since you're already invoking the geoprocessor object, you can also use:

sensorlocation_shp = gp.GetParameterAsText(0)

...and:

test1 = gp.GetParameterAsText(1)
0 Kudos
sethdocherty
Emerging Contributor
I totally forgot about this thread until the other day.  I thought I'd post my script that worked. It may be useful to some. 

# ---------------------------------------------------------------------------
# test.py
# Created on: Sat Feb 19 2011 09:03:47 PM
#   (generated by ArcGIS/ModelBuilder)
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

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

# Load required toolboxes...
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")


# Local variables...
Aug5th_shp = "E:\\GIS\\2010 Summer Project\\summer project 2010\\CommunityNet\\Animation\\Location\\Aug5th.shp"
Extent = "-74.357 40.631 -74.181 40.718"

# Process: IDW...
for i in range(145):
   
    x=i+1
    z=str(x)
    time="a"

    tempEnvironment0 = gp.extent
    gp.extent = "-74.357 40.631 -74.181 40.718"
   
    Intp5_= "E:\\GIS\\2010 Summer Project\\summer project 2010\\CommunityNet\\Animation\\Animation Inerp Maps\\Aug 5th\\Intp5_"
    gp.Idw_sa(Aug5th_shp, z + time, Intp5_ + z, "0.000298", "2", "VARIABLE 12", "")

    gp.extent = tempEnvironment0
0 Kudos