1

I am using I am writing a script to create a tool (in ArcMap 10.7.1) that involves overlaying an agricultural field with a specific grid size. I need the grid to contain a custom width and height of the individual cells, as specified by the tool user. The input will look like this:

#User-defined input, stored as an integer
cellSize = arcpy.GetParameterAsText(0)

#Generate grid
polygonWidth = cellSize
polygonHeight = cellSize

The grid will be generated with the arcpy.GridIndexFeatures_cartography tool.

What I don't know how to do is to add the measurement units to the end of the tool parameter. I want the numeric entry that my users provide to be followed by "feet."

When I upload my script to the toolbox, is there an option that will allow me to specify the measurement units, so that I will be able to generate a proper grid?

1

The tool you mention in your question is GridIndexFeatures_cartography, looking at the tool help you will see that the parameters for the width and height:

polygon_width (Optional) Width of the index polygon specifed in either map or page units. If page units are being used the default value is 1 inch. If map units are being used the default is 1 degree.

polygon_height (Optional) Height of the index polygon specifed in either map or page units. If page units are being used the default value is 1 inch. If map units are being used the default is 1 degree.

Are both of type GPLinearUnit which will accept a unit description like feet, metres, miles etc.. When you are setting up your script to run from a toolbox specify the parameter type of Linear Unit (a lot of text on this page, do a Ctrl + F and search for GPLinearUnit) for your first parameter, the value obtained from this script tool parameter can be passed directly into the call of GridIndexFeatures.

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.