I am getting -9999 values out of the Sample tool (when run in Python using arcpy.sa.Sample or from the dialog box in ArcToolBox). I am sampling a raster based on another raster. I've navigated to the location that is providing -9999 values, and the raster being sampled does not have "NO DATA" values, nor is it close to the edge of the raster extent. Changing the sampling approach from "BILINEAR" to "NEAREST" did not solve the problem. This tool formerly worked when applied to the same data inputs in ArcGIS 10.3.
intermediates_dir = 'C:/smt/spreadgis/intermediate/'
"eucdir" is the raster to be sampled, and contains no missing values
barrier is the raster used to sample "eucdir"
dir_table is the table containing the sampled directions.
arcpy.sa.Sample([intermediates_dir + "eucdir"], barrier, dir_table, "BILINEAR")
As I don't know the cause of the bug (it samples correctly in other locations), I cannot provide a minimum reproducible example.
I searched for similar errors, but due to the frequency of the word "sample" in other contexts, I was unable to find useful results.
Any help in resolving this issue would be appreciated.
Solved! Go to Solution.
As far as I can tell, this is a bug in the 10.4 Sample tool.
I was able to patch around the problem by converting the raster to points and using the Extract Values to Points tool (spatial analyst).
barrier_pts = intermediates_dir + "barrier_pts.shp"
barrier_pts2 = intermediates_dir + "barrier_pts2.shp"
target_raster = intermediates_dir + "eucdir"
arcpy.RasterToPoint_conversion(barrier, barrier_pts)
arcpy.sa.ExtractValuesToPoints(barrier_pts,target_raster, barrier_pts2, "INTERPOLATE", "VALUE_ONLY")
check to see if the first parameter is supposed to be a single raster or a list of rasters, since it is currently contained within a list ... [intermediates_dir + "eucdir"] ... and is not a single path ... intermediates_dir + "eucdir" ...
The input is supposed to be a list: from the tool documentation: "The list of rasters whose values will be sampled based on the input location data."
Trying it without the list also apparently runs, but produces the same incorrect result, as does running the tool directly from ArcToolbox outside of Python.
Have you checked that the CRS is correctly defined for both datasets?
I tried replying to your earlier comment, but it disappeared, and so did my response. Both rasters are in the same projection (UTM 11, NAD83), with the same cell size, and were created with snapRaster set, so overlay one another exactly and have the same extent.
As far as I can tell, this is a bug in the 10.4 Sample tool.
I was able to patch around the problem by converting the raster to points and using the Extract Values to Points tool (spatial analyst).
barrier_pts = intermediates_dir + "barrier_pts.shp"
barrier_pts2 = intermediates_dir + "barrier_pts2.shp"
target_raster = intermediates_dir + "eucdir"
arcpy.RasterToPoint_conversion(barrier, barrier_pts)
arcpy.sa.ExtractValuesToPoints(barrier_pts,target_raster, barrier_pts2, "INTERPOLATE", "VALUE_ONLY")