Masthead

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 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 ArcGIS, 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:

  1. In ArcGIS, move your cursor around to location the upper-left (west-north) corner of the area you want to clip.
  2. In the lower-right corner of ArcGIS, you'll see the coordinates displayed. Write these numbers down.
  3. Do the same for the lower-left corner of the area you want to clip to.
  4. Search for "Clip" and select the one for rasters which is in "Management".
  5. Enter the coordinate values you want to clip by in the appropriate text-entry boxes.
  6. Click "OK". Your raster should be clipped to the specified area and added as a new layer.
  7. If all went well, Go into "Results" and copy the "Python Snippet".
  8. Paste the snipped into the Wing IDE.
  9. 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 how to format parameters for arcpy functions. However, the Python Snippets often use functions that have different names or are in different libraries than the ones in the ArcGIS documentation.

Other Parameters

Some of the tools in ArcGIS 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 ArcGIS with the units you want to use and then copy the Python Snippet to determine the name.

© Copyright 2018 HSU - All rights reserved.