We are clipping one raster to another and our teacher gave us this hint for the 2nd parameter "Remember that the Describe function returns an object. The Clip tool will need the string representation of the extent property" - I know I need a string of the extent. Everything that I have tried has given me:

ERROR 000628: Cannot set input into parameter rectangle.

Here is what I have so far

import arcpy

arcpy.env.workspace = "C:/Student/Newark.gdb"
desc = arcpy.Describe("C:/Student/Newark.gdb/studyarea")
clip = str(desc.extent)
Coord = clip.strip(" NaN")
inRaster = "C:/Student/Newark.gdb/Newark"
outRaster = "C:/Student/Newark.gdb/NewarkClip.jpg"


There's a few problems in your script, but that's ok, you have to start somewhere.

Firstly, your teacher is right, desc.extent is an object, from the Dataset properties and you can read more about the Extent Object. You don't just convert it to a string.

Secondly, variables are used as such and don't get quoted "inRaster" is a string inRaster but inRaster is the value contained in the variable inRaster ("C:/Student/Newark.gdb/Newark").

Thirdly, in a geodatabase you can only store geodatabase objects, by putting the '.jpg' on the end it's no longer a geodatabase object... if you want to create a JPEG you need to put it into a folder, not a database.

Here's the script with a few minor corrections:

import arcpy

arcpy.env.workspace = "C:/Student/Newark.gdb"
desc      = arcpy.Describe("C:/Student/Newark.gdb/studyarea")
ExtObj    = desc.extent
clip      = "%d %d %d %d" % (ExtObj.XMin, ExtObj.YMin, ExtObj.XMax, ExtObj.YMax)

# you've set the workspace so you don't need fully qualified paths
# you can do:
# inRaster  = "Newark"
# outRaster = "NewarkClip"
# but it's best to do the full paths..
inRaster  = "C:/Student/Newark.gdb/Newark"
outRaster = "C:/Student/Newark.gdb/NewarkClip.jpg" # can't do this, only geodatabase rasters go in a database
outRaster = "C:/Student/Newark.gdb/NewarkClip"     # as a geodatabase raster

arcpy.Clip_management(inRaster,clip,outRaster,"studyarea","","NONE","") # where does "studyarea" come from?
  • +1 for deriving the extent. you can either use the rectangle (second parameter) or the studyarea (4th parameter). As written you should replace one of those parameters with "#", and the "" after studyarea should be removed.
    – radouxju
    Apr 16 '15 at 7:43
  • @radouxju I generally do, no point writing empty parameters, in this instance it was a copy 'n paste with minimal change to make the changes easier to follow. I think there's a lesson there for beginners to intermediate, any optional parameters don't need to be specified, also, if you want to specify one parameter among optional parameters specify it by name (eg: arcpy.SetRasterProperties_management(Ras,nodata="1 255;2 255;3 255") skips data_type, statistics, stats_file optional parameters. Apr 16 '15 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.