knu2xs / arcgis-python-toolbox-bootstrap Goto Github PK
View Code? Open in Web Editor NEWQuickly bootstrap an ArcGIS Python toolbox with a few enhancements to make life a little easier
Quickly bootstrap an ArcGIS Python toolbox with a few enhancements to make life a little easier
Hey Joel. Since I've asked for your help in my other issue, I'd like to also share some thoughts with you on streamlining the creation of python toolboxes. Something that has bothered my a lot when beginning to write python toolboxes were two things:
The order I define my parameters the class getParameterInfo()
is the same order the parameters are displayed in the tool. And this order ALSO matters in my pyt file, since I call and change the parameter values by index (e.g. parameters[0].valueAsText
). This usually means that I stick to the order of the parameters as I had defined them since changing the order could break the code. In the GUI, this order is usually counter intuitive.
I constantly repeat myself when naming my parameters: arcpy.Parameter()
has a "name" argument, and I assign the parameter to a variable (usually with the same name) in my execute()
class. With the classic approach (not using your template), there are even more repetitions.
To solve these two problems, I've recently started the following practice: I import the parameters as a dictionary within the execute()
class with following code:
paramdict = {y.name : y.valueAsText for y in parameters}
In this way, I can simply call my parameters using their name as I had defined them within arcpy.Parameter()
like so: paramdict["exName"]
. This means that I can change the orders o my parameters without needing to change the subsequent code (solving issue 1). Also, I need to name my parameters only once (which solves issue 2).
What do you think of this approach?
This is technically not an issue with your template. But since you're thinking about (and sharing your thoughts!) on easier ways to write python toolboxes, maybe you've thought of this question as well: is there a way to document the python toolbox from within the pyt-file? I've this as an SO question: https://gis.stackexchange.com/q/317308/40929
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.