Wednesday, August 6, 2014

Sharing Tools and Final Thoughts

Sharing Tools
Last week and in a previous week, we shared tools that we created by adding the toolbox and the script to a zip file and sharing in this manner. This week we learned that this can be simplified into just one file by embedding the script into the script tool.  This is helpful when you want to share with the not so savvy user by reducing steps needed for using the script and for sharing with the they think they are savvy user and password protecting the script so that they can't get in there an fiddle with your code.  The script tool that we created included a prewritten script that only needed slight modification for embedding purposes.  The tool was used to select 6 parameters that selected a random number of points, within a certain distance of one another and created a buffer around each point.  These are my results.

Script tool dialog box and results


Final Thoughts
What is the most memorable, interesting or useful things I learned about using Python with ArcGIS during the course?  Hmm, let me think.  I learned that programming, in general, can be useful for repetitive, complex, lengthy tasks.  I have learned that I don’t think Python is as easy to learn as they say it is, and therefore doubt I will try to pick up any other additional programming languages.  But I have also learned that for every one person who gets and understands programming, there are thousands that benefit from it.  Where would any of us be without the programming pioneers of the early PC days?  We would probably still be hand drawing maps and shuffling through mounds of paper data trying to analyze it all.  Not everyone is cut out for everything, and that’s OK, it’s what makes this world work.  We each have our strengths and our weaknesses.  But when we identify our weakness and strive to make them strengths, that’s when we excel, that’s we step ahead of the next guy, that’s where we become a part of something bigger than us.  

To sum up this class, I have come to the realization that I do not have a programmer’s brain.  I have no idea how you guys remember all the things that go into modules and functions and command and syntax.  Maybe back in the day, when my brain hadn't lost quite so many cells, I would have had an easier time with this.  I hope one day maybe to retain just enough to keep me guessing on what I can do with Python. I definitely have a use for it at work.  Thanks for the instruction along the way.

Friday, August 1, 2014

Creating interdisciplinary collaboration through Python script tools

Landscape genetics is an area of research that combines population genetics, landscape ecology, and spatial analysis to understand the effects of landscape composition, configuration and matrix quality on gene flow and spatial genetic variation.  Knowledge of these areas typically requires more than one discipline of study so it makes sense that interdepartmental collaboration would be necessary.   The author, Thomas R. Etherington, identifies this area of concern, and using his knowledge of Python programming and ArcMap was able to create thirteen script tools for use by his colleagues that simplified basic, repetitive and complex processes.   Through use of script tools created and stored in an ArcMap toolbox, the author made it possible for non-GIS specialist to access the tools through a much simpler to understand GUI interface.  The author also recognizes that through script tools, geoprocessing and analysis can be combined for larger workflows.  While not specifically mentioned he is most likely referring to ModelBuilder.  Another point the author expands on is that since the scripts are created in Python, which is an open source language, they are easily accessible for other developers to use and modify to fit their own specific needs.


Python based GIS tools for landscape genetics: visualizing genetic relatedness and measuring landscape connectivity, Thomas R. Etherington, pages 52–55Methods in Ecology and Evolution, January 2011, Volume 2, Issue 1

Creating Custom Tools

Say you have a script that you want to share with other users.  This script can be sent to another user and they can run the script.  But what if that script needs to have a variable parameter.  In a stand-alone script, the user would have to edit the script file and have some knowledge Python.  Wouldn't it be better to create a GUI tool that the end user could easily pull up in ArcMap and change those variables without having to know Python?  Creating a custom tool can do just that.  Many times users of ArcMap are not always well versed of the ins and outs of GIS, geoprocessing or Python programming.  A custom tool can be configured to choose specific parameters and perform functions detailed in the associated script.  A custom tool can be used in ModelBuilder to manipulate geoprocessing functions whereas a stand-alone script cannot. Additionally, print messages in a stand-alone script are only visible in an interactive window.  With a custom tool, print commands can be viewed in the Results window.

Our assignment this week was to create a custom tool based on a given script.  First we needed to create the toolbox and a script to it.  Then we associated a script file to the tool.  Parameters must be defined in the tool that correspond to the parameters in the associated script.  Once the parameters are established, clicking on the script tool will produce the following screen.

Script tool with established parameters

 A stand-alone script cannot run certain commands within a script tool.  For example, a simple print command such as print "Clipping", inname.name, must be modified to properly run in the script tool.  The arcpy.AddMessage function takes the place of the print command and commas are replaced with the plus symbol.  As you can see in the results below, printed messages can be viewed in the results window of a script tool.

Viewed messages in the Results window