arcpy.Resample_management() syntax

5250
8
Jump to solution
07-30-2015 03:28 AM
BenLeslie1
Occasional Contributor III

What's the correct syntax for using the path of a raster dataset to set the output cell size as mentioned, but not explained, in the help docs?

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

I get "ERROR 000628: Cannot set input into parameter cell_size"

p.s. I know there are ways round this using GetRasterProperties etc but would like to know how to do it this way.

Thanks

0 Kudos
1 Solution

Accepted Solutions
BenLeslie1
Occasional Contributor III

Just to confirm this has been logged as a bug.

View solution in original post

0 Kudos
8 Replies
DanPatterson_Retired
MVP Emeritus

http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/resample.htm

arcpy.Resample_management("image.tif", "resample.tif", "10", "CUBIC")

where the cell size in in the units of the data, not what you want them to be

0 Kudos
BenLeslie1
Occasional Contributor III

I don't think that answers my question, I want to set the cell size using the 'third way' as highlighted in bold in the extract from the help docs below:

You can specify the cell size in 3 different ways:

  • Using a single number specifying a square cell size
  • Using two numbers that specify the X and Y cell size, which is space delimited
  • Using the path of a raster dataset from which the square cell size will be imported
0 Kudos
DanPatterson_Retired
MVP Emeritus

If you don't want to use a number, then you have to specify the full path to a raster with the cell size you want.  It is best to use raw notation or use forward slashes in the path name.

0 Kudos
BenLeslie1
Occasional Contributor III

Thanks, but that doesn't answer my question, I'd like to know the correct syntax for inputting the raster path; I have tried many variations, including your sugesstions, all without success such as:

using the env.workspace setting to set the path and then defining the raster file name

typing the full path using raw notation

typing the full path using forward slash notation

using single quotes

using double and single quotes

using single and double quotes

using triple double quotes

using double double quotes

setting the raster as a layer and using that

typing it as it appears in the GUI i.e. "Same as layer ............"

I'm beginning to suspect that the tool doesn't do what the help docs says it does.

As I said, I know there are other ways of doing this but I'm just a firm believer the help docs should:

1. Help

2. Reflect how the program works

0 Kudos
DanPatterson_Retired
MVP Emeritus

Then pass it on as a potential bug...since you have just about everything covered.

XanderBakker
Esri Esteemed Contributor

If I run the tool manually and copy the Python snippet from the Results window, I see the following syntax:

arcpy.Resample_management(in_raster="C:/Forum/ZonalStatsPercLoop/gdb/Rasters.gdb/DEM10m",
                          out_raster="C:/Users/Xander/Documents/ArcGIS/Default.gdb/DEM10m_Resample",
                          cell_size="C:/Forum/ZonalStatsPercLoop/gdb/Rasters.gdb/Raster25m",
                          resampling_type="NEAREST")

If I run this script from as standalone script (including the import arcpy statement and changing the output name), it throws the following error:

ExecuteError: ERROR 000622: Failed to execute (Resample). Parameters are not valid.

ERROR 000628: Cannot set input into parameter cell_size.

So, yes you should definitely report this as a bug. For now you could use the following alternative to use the cellsize from an existing raster:

import arcpy
ras_in = "C:/Forum/ZonalStatsPercLoop/gdb/Rasters.gdb/DEMint"
ras_out = "C:/Forum/ZonalStatsPercLoop/gdb/Rasters.gdb/DEM25m_v2"
ras_cell = "C:/Forum/ZonalStatsPercLoop/gdb/Rasters.gdb/Raster25m"

cellsize = "{0} {1}".format(arcpy.Describe(ras_cell).meanCellWidth,
                            arcpy.Describe(ras_cell).meanCellHeight)
# environment
arcpy.env.extent = ras_cell
arcpy.env.snapRaster = ras_cell
arcpy.env.cellSize = ras_cell

arcpy.Resample_management(in_raster=ras_in,
                          out_raster=ras_out,
                          cell_size=cellsize,
                          resampling_type="NEAREST")
BenLeslie1
Occasional Contributor III

Just to confirm this has been logged as a bug.

0 Kudos
AndySmith
Esri Contributor

The bug reference and description is as follows:

BUG-000089799: arcpy.Resample does not accept path to raster dataset as input to cell size parameter