Thursday, August 4, 2016

Exercise 9

Goals

The goal of exercise nine was to create a custom script tool that will generate a swiss hillshade. The tool will be kept in a custom toolbox in a geodatabase and will be accessible to use within ArcMap. This will be a much shorter Python script. 




Methods

Exercise nine's python script starts out like all of the previous scripts. The first step is to ensure that the script is running properly by using a print statement. The second step is to import the system modules. In this exercise, we import os, shutil, time, datetime, and arcpy. Once the modules are imported, we can move on to the next objective. In this next step the GetParametersAsText function is used for each of the input feature classes. This allows the user to specify the name of the DEM directly into the tool. So the tool is portable and can be used in many different situations and projects.  Next, variables are set up. Once the proper variables are set up, a try statement is set up. Within the try statement, the process to generate the swiss hillside is added. This includes using the divide function, hillshade function, focal statistics function, and plus function. Now at the end of the try statement, there needs to be an except statement. This statement will make it so that an error message will be reported if the try statement fails. This is the end of the script to make the swiss hillshade tool.  The next step in the exercise was to add it to a tool box and to use the add script wizard to set up the script for ArcMap. 


Results

This exercise was very short but I think that the results of it were very useful. A nice short script to create a tool that you can put into ArcMap and then use again and again is a very helpful skill to have. The results of this exercise are below in the form of the python script for the swiss hillshade tool. 










Conclusion

As I said earlier, this was a very short exercise but an extremely useful one. Doing this exercise made me think, if someone works for a company and they need to execute a GIS process many times every day, it would be extremely helpful to be able to just write a script once and create a tool for it. This way The script can already have the process built into it and you can save yourself a bunch of time. This exercise truly showed us a very useful python tactic. 




Exercise 8

Goals

The goal of this exercise is to use a suite of loops to clip and project a directory of scanned USGS topographic sheets into a seamless raster. The topographic sheets are in a layout referred to as a tile index or a quad index. These quads have a collar around the edge of the map that needs to be clipped away so that we have a seamless mosaic. 


Methods

This script was easily the longest and most complex script that was written during this class. That being said, it starts off the same as just about all of the other scripts. First, a print statement showing that the script was working is written. Second, all of the system modules need to be imported. For this script, os, shutil, time, datetime, and arcpy were all imported. The next step, similar to previous scripts, is to write a block of code that allows existing files to be overwritten. The next step was to create variables. Some of the variables created included our workspace, geodatabase path, featuredataset path, and clip geodatabase path. The next thing in the script is two blank lists that will end up being populated with the name of the topos as we iterate through loops later. Along with the blank lists, file location and files name for some of the created data sets are set up. The next step was to create a spatial reference object. Next a boolean loop is set up. If the condition is true the function will then traverse a workspace and final all files with a specified type. Inside of the loop, we want to be able to track the progress, to do this, you can set a letter as a variable equal to zero. You then add one to the variable later on as the loop progresses to indicate how many rasters are left. The next step in the script is applying the walk to the directory. Next we set up an interaction loop. The first thing that needs to be done in the iteration loop is set up the counter. Next the names of the top will be formatted. Once the names are reformatted, the process of projecting the topos can be executed. Next we take the projected topo and create a polygon of the topos footprint which includes the collar. Now the tiles can be added to the list of tiles and then the tiles can be merged together. Next we set up an if loop that will clip the collar from the tiles one by one. There is an if else statement inside the loops that will allow a tile to pass over the clipping tool if it has already been clipped. In this case the first tile that went through the loop had already been clipped. Once All of the tiles have been clipped then the mosaic tool is used to combine all of the clipped tiles into one larger topo map. 



Results

The results of this exercise were the projected and clipped rasters and then a mosaic of all of the rasters combined together. Below are images that first show the script that was written in the exercise and below that is the final mosaic topo map that was created. 







Conclusion

This exercise was difficult, but, it definitely helped get more practice with loops and cursors along with many other elements of python scripts. The final map came out looking good besides the discoloring. The discoloring in the map is just a result of the way the USGS maps are scanned. All of the data in this exercise was provided by USGS topo maps! Overall this was a difficult but worthwhile exercise for this class.