Wednesday, July 20, 2016

Exercise 5

Goals

The goals of exercise five was to use standard raster geoprocessing preparation tools, like project, clip, as well as basic raster analysis tools such as, hillshade and slope. The use of a FOR IN loop will be used by creating a list of rasters from a provided geodatabase. 


Methods

To start off this exercise, it was necessary to set up the script in the usual manner. The first thing added to the script was a print statement to ensure that the script started running. The next thing that needed to be done was importing system modules. Os, time, datetime, arcpy, and env were all imported similar to last exercise. But this time, shutil was also imported as well. The overwrite output setting was turned on next. The last thing that was done to set up the script was setting the workspace. The next step in writing the script was to set up smart variables. All of the variables created will be used later in the script. There were also lists created with nothing in them to start. These lists would later hold clipped rasters in one, hillshade rasters in another, and slope rasters in the last. The next step and probably the biggest step was to create the FOR IN loop that would get rasters and reformat their name and project the rasters. Projecting the rasters was done by using the arcpy.ProjectRaster_management tool. The loop would also preform a variety of the basic geoprocessing preparation tools. The FOR loop would then take the projected rasters and run a clip and add it to the clipped raster list. The loop then runs a hillshade and puts the output into the hillshade list. The same is done with the slope. The loop was then complete. So the FOR loop ran through every raster that was provided and spit out clips, hillshades, and slope for all of them. The last step in the script was merging all of the tiles. All of the clips were merged together, all of the hillshades were merged together, and all of the slopes were merged together. 


Results

The results of exercise five are relatively simple. In our new exercise five geodatabase, there is now a lot of new rasters and combinations of these rasters. This exercise really showed the importance of using loops when you can. They can save you many lines of the same code. The completed script is shown in the images below. 




Conclusion

As I stated earlier, this exercise showed us how important the use of loops are in python and coding in general. If we hadn't used a loop, the script would have been over ten times longer. Loops keep things more organized and easier to look over. Overall, this was a good exercise to show us how helpful using loops is for python coding. 

No comments:

Post a Comment