
For the final lab of the course, the objectives included using Spyder to list and describe rasters, using raster objects in geoprocessing, map algebra in operators, and defining raster tool parameters with classes. The end goal was to create a script for a raster detailing specific forest landcover, slope and aspect profiles by copying a script which was coded on Spyder. My script began by importing arcpy and setting the environment's workspace. I needed to create a new geodatabase using the arcpy.CreateFileGDB_management which is where my raster was saved. Part of the script involved checking for the Spatial Analyst module extension, using the arpy.CheckOutExtension and an if statement. The remaining code was in block form following the if statement, after the SA module checks out, and included creating an outraster for the elevation and the percent rise, and saving the outraster in the results folder. I then used the ReMapValue function to assign the appropriate classifications provided for the lab results, reclassified the landcover raster and created a variable for the elevation using arcpy.sa.Raster. After the elevation raster was created, variables for the slope raster and aspect raster were made which both referenced the elevation. Getting towards the end of the script, I created calculations for the previously created Slope and Aspect to only show slopes between 5 and 20, and aspects between 150 and 270. Lastly, the final was created referencing the outreclass created towards the middle of the script, and the ideal range of slopes and aspects, this was saved under the Results folder and GDB previously created. The end of the script displays an error if the SA module is not available.
This module was another struggled, but pretty fun. It was a reward to watch a code I created in Spyder execute in ArcGIS Pro, and (hopefully) detail the correct information. The only thing I really, really had trouble with was importing the sa * module. I eventually gave up and ended up importing all the arcpy.sa modules individually.
Comments
Post a Comment