Wrapping Tools in Functions
See original GitHub issueIs there any particular reason why the tools analysis functions are not wrapped in functions with parameters? One challenge I have had is that sometimes it makes sense to use Python with these tools and that is often made difficult because the functionality is not wrapped inside of a functions. The benefits of doing this are the following:
-
Enables tool import into other tools outside of this library
-
Makes it easier to build off the tools
-
Provides a way to edit inputs without going through the GUI
I am willing to help with this if this is a big ask. The general pattern I used for my tools looks like this:
`# Main Function def chained_near_analysis(in_fc, near_features, search_radius=None, location=False, angle=False,fid=False, method=“PLANAR”):
…
if name == ‘main’:
# Define input parameters
input_features = arcpy.GetParameterAsText(0)
near_features = str(arcpy.GetParameterAsText(1)).split(";")
search_radius = arcpy.GetParameter(2)
location = arcpy.GetParameter(3)
angle = arcpy.GetParameter(4)
fid = arcpy.GetParameter(5)
method = arcpy.GetParameterAsText(6)
chained_near_analysis(input_features, near_features, search_radius, location, angle,fid, method)`
This isolates the function from the GetParameter functions which require typically some interaction from a GUI. Do you have any concerns with this approach?
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
The transit analysis tools will not be deprecated. They have been re-implemented as a python toolbox in a similar way to BetterBusBuffers (runTool()) in this branch, which will be merged as soon as Pro 2.4 is released.
While I might prefer a more descriptive function call name, this is acceptable. Thank you for incorporating this feedback, it actually saved me on a project.