Tuesday, June 19, 2018

Module 6: Geoprocessing with Python



Above is the messages from the script I wrote and ran this week.  I utilized Model Builder in ArcGIS to get the basic code and then exported it to a python script and edited in PythonWin.  The instructions for the assignment were to write a script that performs the three geo-processing functions: Add XY tool, Buffer tool, and Dissolve tool. Get Message function was utilized following each tool to document the successful completion of each tool.

ArcPy site package is like a library of functions that add functionality to Python.  The site package works very much like a module, but a package contains multiple modules as well as functions and classes. 

A function in Python is a specific bit of program that does a specific task. Functions syntax is typically: <function>(<arguments>)

A method is a function that is closely coupled to an object.  Method is called as follows: <object>.<method>(<arguments>)

Classes can be used to create objects, and once the object is created, its properties and methods can be used.  Classes are often used to avoid having to use long and complicated strings.  Arcpy classes are often used as shortcuts for tool parameters that would otherwise have a more complicated equivalent.  Syntax for setting the property of a class is:  <classname>.<property>=<value>

Tools can be called 1)by its function- arcpy.<toolname_toolboxalias>(<parameters>) or 2) as a module- arcpy.<toolboxalias>.<toolname>(<parameters>) 3)once a particular tool is identified, the tool's syntax can be accessed from python using the Usage function
All tools are functions, but not all functions are tools. 

One of the points from our exercises for this week was a focus on getting help with syntax.  Help with syntax can be obtained a number of ways.  A couple of ways are: 1) help panel is visible within the Python window, entering the code brings up the syntax for the tool 2)from the search menu, search the tool, clicking the definition in the search tool will bring up the item description that contains syntax and examples of code.

No comments:

Post a Comment