Select to view content in your preferred language

Error in executing tool (Focal Statistics)

02-24-2018 03:19 AM
New Contributor

Hi, I'm really new at using python and I'm trying to create a script for terrain ruggedness index but I'm using 4 shapefiles. I want to convert them to rasters and then merge them and do the TRI on this one raster. My script keeps failing because of the RuntimeError: Object: Error in executing tool. I would be really grateful if anybody helps me.

I got this:

Traceback (most recent call last):
File "F:\GIS_mag\py_nmg\", line 60, in <module>, v3x3max, "Rectangle 3 3 CELL", "MAXIMUM", "DATA")
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\geoprocessing\", line 510, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool

This is my script:

# Import arcpy module
import arcpy

# Script arguments
dmr1 = arcpy.GetParameterAsText(0)
if dmr1 == '#' or not dmr1:
    dmr1 = "dmr1" # provide a default value if unspecified

dmr2 = arcpy.GetParameterAsText(1)
if dmr2 == '#' or not dmr2:
    dmr2 = "dmr2" # provide a default value if unspecified

dmr3 = arcpy.GetParameterAsText(2)
if dmr3 == '#' or not dmr3:
    dmr3 = "dmr3" # provide a default value if unspecified

dmr4 = arcpy.GetParameterAsText(3)
if dmr4 == '#' or not dmr4:
    dmr4 = "dmr4" # provide a default value if unspecified

TRI = arcpy.GetParameterAsText(4)
if TRI == '#' or not TRI:
    TRI = "F:\\GIS_mag\\py_nmg\\tri" # provide a default value if unspecified

# Local variables:
dmr1_ras = "F:\\GIS_mag\\py_nmg\\dmr1_ras"
dmr2_ras = "F:\\GIS_mag\\py_nmg\\dmr2_ras"
dmr3_ras = "F:\\GIS_mag\\py_nmg\\dmr3_ras"
dmr4_ras = "F:\\GIS_mag\\py_nmg\\dmr4_ras"
dmr = dmr1_ras, dmr2_ras, dmr3_ras, dmr4_ras
py_nmg = "F:\\GIS_mag\\py_nmg"
v3x3max = "F:\\GIS_mag\\py_nmg\\3x3max"
v3x3min = "F:\\GIS_mag\\py_nmg\\3x3min"

# Process: Point to Raster
arcpy.PointToRaster_conversion(dmr1, "Field3", dmr1_ras, "MOST_FREQUENT", "NONE", "1")

# Process: Point to Raster (2)
arcpy.PointToRaster_conversion(dmr2, "Field3", dmr2_ras, "MOST_FREQUENT", "NONE", "1")

# Process: Point to Raster (3)
arcpy.PointToRaster_conversion(dmr3, "Field3", dmr3_ras, "MOST_FREQUENT", "NONE", "1")

# Process: Point to Raster (4)
arcpy.PointToRaster_conversion(dmr4, "Field3", dmr4_ras, "MOST_FREQUENT", "NONE", "1")

# Process: Mosaic To New Raster
arcpy.MosaicToNewRaster_management("F:\\GIS_mag\\py_nmg\\dmr1_ras;F:\\GIS_mag\\py_nmg\\dmr2_ras;F:\\GIS_mag\\py_nmg\\dmr3_ras;F:\\GIS_mag\\py_nmg\\dmr4_ras", py_nmg, "dmr", "", "8_BIT_UNSIGNED", "", "1", "LAST", "FIRST")

# Process: Focal Statistics (2), v3x3max, "Rectangle 3 3 CELL", "MAXIMUM", "DATA")

# Process: Focal Statistics, v3x3min, "Rectangle 3 3 CELL", "MINIMUM", "DATA")

# Process: Raster Calculator"SquareRoot(Abs(Square(\"3x3max\") - Square(\"3x3min\")))", TRI)
0 Kudos
3 Replies
MVP Emeritus

I would suspect that there is a disconnect between the script and the parameters unless you are running this as a tool within arcmap/PRO.

Throw in some print statements to print out your parameters at each stage before you get to the processing stage

New Contributor

The problem was the 'dmr' in lines 51 and 54, because at local variables it's defined as tuple made of 4 strings but the focal statistics method can only work with one, therefore I just changed the 'dmr' in lines 51 and 54 for "F:\\GIS_mag\\py_nmg\\dmr" and now works perfectly fine.
Thanks for your help!

0 Kudos
MVP Emeritus

You should mark this closed then Nina