I've been trying several times to sample (Sample tool from Spatial Analysis ArcGis 10.5.1) a list of rasters to a location sample (also in raster format .tif).
Here's the code I've been using, and apparently the problem raised up when Python execute the line of the tool - it creates well all the files in the specified folder:
import arcpy, os, sys, string
from arcpy import env
from arcpy.sa import *
arcpy.env.workspace = r'C:\Users\Victoria\Desktop\***\***'
inputFolder = arcpy.env.workspace
outputFolder = os.path.join(inputFolder, "sample")
raster = arcpy.ListRasters('*br*')
colony = arcpy.ListRasters('*col_1*')
for r in raster:
outName = os.path.splitext(r)[0] + "_col1"
saveDir = os.path.join(outputFolder, outName)
Sample(r, colony, saveDir, "NEAREST", "Value", "CURRENT_SLICE")
print '{0} saved in {1}.'.format(outName, saveDir)
And here's the error that shows up after run the code:
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.5\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Victoria\Desktop\***\***\prueba1.py", line 15, in <module>
proc = Sample(r, colony, saveDir, "NEAREST", "Value", "CURRENT_SLICE")
File "C:\Program Files\ArcGIS\Desktop10.5\ArcPy\arcpy\sa\Functions.py", line 1617, in Sample
process_as_multidimensional)
File "C:\Program Files\ArcGIS\Desktop10.5\ArcPy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "C:\Program Files\ArcGIS\Desktop10.5\ArcPy\arcpy\sa\Functions.py", line 1609, in Wrapper
process_as_multidimensional)
File "C:\Program Files\ArcGIS\Desktop10.5\ArcPy\arcpy\geoprocessing\_base.py", line 510, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool
I'm really new in this.
in_rasters
parameter be a list of rasters? You are providing one raster at a time. Andin_location_data
should only be one raster layer or one feature layer but you are providing a list of rasters. Look at the documentation for sample.for r in rasters
,r
will be a single raster. IfSample
wants a list of rasters and you are inputing one raster (r
) it will not work.