Basics of Python (for ArcGIS 10)
This course from Esri has a fee requirement. If formally enrolled in the class please contact your instructor for an access number. This class is similar to the Python for Everyone class but contains some additional different information. It will work on any version of ArcMap 10.0 or higher.
In this course you will learn:
The only software required for this class is ArcGIS 10.0 or higher. The class mentions the use of IDEs and command prompt scripts but they are not used in the class. You may want to experiment with an IDE and command prompt to see how it works, but not required to do the lessons.
Helpful information
There are three different ways that you can input Python scripts for ArcGIS mapping functionality. You can use the Python Window in ArcMap, you can use an IDE like PythonWin or you can use Command Prompt. With the Command Prompt you can only enter a single line of code, the other two methods allows for the input of a sequence and editing of functions. In general an IDE has better editing functionality. The ArcMap Python Window gives the ability to drag and drop tools, as well as directly interacting with map elements. In an IDE or ArcGIS Python Window you must press enter twice to run the script.
If you use a double quote (" " or ' ', note the space between the quote is only there to separate the elements but the space is not required) around any word or phrase it will be text item, without the quotes it will be considered a number (or provide an error for text). You can add text fields to text fields or number fields to number fields but you cannot directly add to different field types to gather without additional statements.
In Python all variables are case sensitive. The general way a variable is written is to be very descriptive. The naming of the variable involves two or more words there is no space used and the second word usually begins with a capital letter but not a requirement, like clipVariable. commands begin with lowercase letters.
A list will use [ ], Tuples will use ( ) and dictionaries will use { }.
File utilize will use an r for read, an a for append and a w for write. You must remember to close a file when down using the close () statement.
There are several decision (looping) statement which include ir (as well elif and else), while, and for; each of these statements must end in a colon. Items in the decision must be indented, which the ArcGIS Python will do for you automatically.
To make a comment line use the hash symbol #; this line will be descriptive only and no execution will done on this line, it makes it easy to debug the program by using this feature. It is recommended that you build the structure using comments before writing code.
ArcPy is the Python module for ArcGIS, it is automatically loaded when using the ArcGIS Python Window but must be loaded when used in an IDE. There are three sub-modules in ArcPY and they are: the mapping module, the spatial analyst toolbox and the geostatistical analyst tool.
In this course you will learn:
- Efficiently work with the ArcMap Python window.
- Apply Python syntax rules to prevent errors in scripts.
- Apply recommended practices to set and use variables that store information used by a script.
- Understand the types of data that can be accessed through a Python script.
- Use if, while, and for loops to test for conditions and perform different actions in a script.
- Quickly access and modify code to run ArcGIS geoprocessing tools.
The only software required for this class is ArcGIS 10.0 or higher. The class mentions the use of IDEs and command prompt scripts but they are not used in the class. You may want to experiment with an IDE and command prompt to see how it works, but not required to do the lessons.
Helpful information
There are three different ways that you can input Python scripts for ArcGIS mapping functionality. You can use the Python Window in ArcMap, you can use an IDE like PythonWin or you can use Command Prompt. With the Command Prompt you can only enter a single line of code, the other two methods allows for the input of a sequence and editing of functions. In general an IDE has better editing functionality. The ArcMap Python Window gives the ability to drag and drop tools, as well as directly interacting with map elements. In an IDE or ArcGIS Python Window you must press enter twice to run the script.
If you use a double quote (" " or ' ', note the space between the quote is only there to separate the elements but the space is not required) around any word or phrase it will be text item, without the quotes it will be considered a number (or provide an error for text). You can add text fields to text fields or number fields to number fields but you cannot directly add to different field types to gather without additional statements.
In Python all variables are case sensitive. The general way a variable is written is to be very descriptive. The naming of the variable involves two or more words there is no space used and the second word usually begins with a capital letter but not a requirement, like clipVariable. commands begin with lowercase letters.
A list will use [ ], Tuples will use ( ) and dictionaries will use { }.
File utilize will use an r for read, an a for append and a w for write. You must remember to close a file when down using the close () statement.
There are several decision (looping) statement which include ir (as well elif and else), while, and for; each of these statements must end in a colon. Items in the decision must be indented, which the ArcGIS Python will do for you automatically.
To make a comment line use the hash symbol #; this line will be descriptive only and no execution will done on this line, it makes it easy to debug the program by using this feature. It is recommended that you build the structure using comments before writing code.
ArcPy is the Python module for ArcGIS, it is automatically loaded when using the ArcGIS Python Window but must be loaded when used in an IDE. There are three sub-modules in ArcPY and they are: the mapping module, the spatial analyst toolbox and the geostatistical analyst tool.