Finding the Format for arcpy Parameters
The combination of the ArcGIS help, coping "Python snippets" from "Results", and the "Source Assistant" in the Wing IDE will allow you to determine how to format parameters for most of the arcpy functions. However, there are a few that we have to do a little more work with.
All of the parameters we pass into arcpy functions are strings. Most of these are simple but some contain multiple values. Also, when you want to pass "nothing" for a parameter, you sometimes pass a negative one, sometimes a pound sign ("#"), and sometimes something else (i.e. arcpy is not very consistent). You can determine
You can use the method shown here to determine the exact format and values for parameters for virtually any toolbox function.
Determining Parameters for Clip
It is common to "crop" large rasters to just the area of interest to have them execute faster. You'll want to do this for this week's assignment and in the future. ArcGIS's "Management -> Clip" tool will do this but the documentation is minimal for how to specify the bounds of the clipping area or the "clip bounds".
In ArcMap, load a raster and then clip it to a specified rectangular area. An easy way to clip any raster to a defined area is to:
- In ArcMap, move your cursor around to location the upper left (west-north) corner of the area you want to clip.
- In the lower-left corner of ArcMap, you'll see the coordinates displayed. Write these numbers down.
- Do the same for the lower-left corner of the area you want to clip to.
- Search for "Clip" and select the one for rasters which is in "Management".
- Enter the coordinate values you want to clip by in the appropriate text-entry boxes.
- Click "OK". Your raster should be clipped to the specified area and added as a new layer.
- If all went well, Go into "Results" and copy the "Python Snippet".
- Paste the snipped into the Wing IDE.
- Now, you can see exactly where each of the coordinate values needs to be in the string that is sent to arcpy to clip a raster. You can use Python now to complete these values, format the bounds string, and pass it to arcpy.
In the future you can use this method to determine exactly how to call virtually any toolbox tool from arcpy.
Other Parameters
Some of the tools in ArcMap have text string that represent specific settings that need to be replicated exactly. An example would be specifying units for a buffer which are formatted as "1000 Meters" where 1000 is the amount to buffer by and "Meters" is the units. To determine the exact name for other types of units that are supported, simply execute the Buffer tool in ArcMap with the units you want to use and then copy the Python Snippet to determine the name.