Using Arcpy with IDE
Assumptions
|
It is assumed that each geoprocessing tool discussed in this module will be a concept that the learner is knowledgeable about. This type of information could have been gained through experience in the geospatial field or through an introduction to geospatial technology course. If the functionality of a specific tool is unclear, review the introduction to gist website, http://introductiontogist.weebly.com. The complete functionality of the Python commands will be explained in the module.
Programming Mode
As noted in the previous module an IDE (Integrated Development Environment) has two modes of operation. In the immediate mode, when a return key is pressed at the end of the line, the line is executed; unless a looping function is used which requires a double return. In immediate mode, the content of variables are remembered from one line of code to the next. Programming mode will allow the user to write all lines of code, but the execution of the code will not occur until the scripts are saved and then run. A Python script is a text file, with the py extension instead of the normal text extension. When the script has the py extension, the IDE will automatically assume that the script is in the Python format. If a simple text editor is used make sure that the py extension is added when saved. The IDE editor will prompt the user with suggestions of command format while typing.
If the code runs successfully with no errors, generally the results are displayed in the immediate mode window. If there were any errors associated with the execution of the code, then an error message will appear in the immediate mode window. The error messages can be several lines long and at times, they may be somewhat difficult to fully understand. For example, a simple typographical error can generate long error messages. Most of the error messages will reveal the line where the error is located which is very useful in the troubleshooting process. The author’s experience has been that errors are usually typographical and not logical. For example, a missing ending bracket can cause errors.
Once the process runs successfully, the file or results will need to be reviewed, generally, in Esri ArcMap Desktop. In some processes when a new file is produced and an error occurs, the file will be created with the appropriate name, but not correctly populated. Once the error is corrected and the script is executed again, a new error might result because the file already exists and the script was not formatted to over write the current files. Thus when a file(s) is created as part of a script, check that no previous files of the same name were created during the testing phase. Delete any duplicated files while testing. Make sure that no files are open that are going to be addressed by the code, this will also cause errors because the file is locked when open, unless it is a relational database.
If the code runs successfully with no errors, generally the results are displayed in the immediate mode window. If there were any errors associated with the execution of the code, then an error message will appear in the immediate mode window. The error messages can be several lines long and at times, they may be somewhat difficult to fully understand. For example, a simple typographical error can generate long error messages. Most of the error messages will reveal the line where the error is located which is very useful in the troubleshooting process. The author’s experience has been that errors are usually typographical and not logical. For example, a missing ending bracket can cause errors.
Once the process runs successfully, the file or results will need to be reviewed, generally, in Esri ArcMap Desktop. In some processes when a new file is produced and an error occurs, the file will be created with the appropriate name, but not correctly populated. Once the error is corrected and the script is executed again, a new error might result because the file already exists and the script was not formatted to over write the current files. Thus when a file(s) is created as part of a script, check that no previous files of the same name were created during the testing phase. Delete any duplicated files while testing. Make sure that no files are open that are going to be addressed by the code, this will also cause errors because the file is locked when open, unless it is a relational database.
Functionality
The following concepts will be covered in this module:
- arcpy
- buffer
- env (environment)
- merge
- clip
- tabular join
- spatial join
- geocoding