Goals
The goals of this exercise were to export a geoprocessing model as a script and add several smart variables and modify the exported script. The model that was exported into a script was the same model that was created in exercise 1.
Methods
This exercise took the model that was created in exercise one and exported it to help create a Python script. The first thing that had to be done was to export the model. Once that was exported, PyScripter was opened and the script was started. First step was to comment out the title and purpose of the script along with the authors name and the date. The next step was to import ArcPy System Modules and the environmental settings. Some of the ArcPy modules that were used were os, time, and datetime. Next the environmental setting to overwrite existing files was added. The next step was to create variables and import our geodatabase from exercise one. From there we used the os.path.join to join the existing files in the exercise one geodatabase to a variable name. Next we set up the path to the newly created exercise three geodatabase. Once the path was created, we set up variables for the clip, selected, buffered, dissolved, intersected, and final selected variables.
After the base of the script was completed, the exported python script form step one was imported into PyScripter. We left out the local variables that were created in the model builder because the variable had already been created earlier. The code taken from the model executed the tools. All that needed to be done was replace the input and output variables in the tools. The last step was to debug and run the code.
Results
The following images show the script that was created in this exercise. The script debugged and executed correctly. The desired output was achieved. In the conclusion section errors will be discussed
Conclusion
Exercise three was the first Python script that we created in this course. It was nice that the output was the same as the first exercise so that we could directly compare what it was like to create and model vs a script to execute the same geoprocessing tools. The first couple of times the script was run, it did come up with errors. This was because the pathing to the exercise 3 geodatabase was incorrect. Once that was fixed, there were just a couple of spelling issues that needed correcting. As soon as the spelling was correct, the script ran correctly and gave the desired output.
No comments:
Post a Comment