Tuesday, June 28, 2022

GIS 4102 - Module 6 - Working with Rasters

The final module for GIS programming has come to a conclusion. Module 6 had us working with rasters in order to produce an ouput that reflected map algebra calculations involving slope and aspect. The requirements for the final output were to create a raster that incorporated these elements:
• Forest landcover (classifications 41, 42, and 43)
• Slope between 5° and 20°
• Aspect between 150° and 270°

Here is a screenshot of the final raster.


And here is a screenshot of the Spyder console successfully running the script.

Here is the psuedocode for my script.
START
Import modules
Enable overwrite output setting
Set workspace to Elevation fGDB
Set output env
Create mod6 fGDB
Print mod6 fGDB completion statement
Create if conditional statement for script to run only if spatial analyst is available
     Check out spatial analyst extension
     Remap value function to assign landcover classifications 41, 42 and 43 all as new value of 1
     Reclassify tool on landcover raster using Remap variable
     Save reclassify raster
     Print reclassify completion statement
     Assign elevation raster variable
     Create variable for slope based on elevation, and percent rise field
     Create variable for aspect based on elevation field
     Create temp variable for slope1 condition >= 5
     Create temp variable for slope2 condition <= 20
     Create temp variable for aspect1 condition >= 150
     Create temp variable for aspect2 condition <= 270
     Combine 5 temp rasters into 1 final raster using boolean and map algebra operator (&)
     Save function direct final_raster.tiff
     Print combination completion statement
Create else condition if spatial analyst is not available
     Print Spatial Analyst is not available statement
END

Some problems I encountered over the course of this module involved correctly importing the spatial analyst module, syntax errors, and assigning variables to conditions involved in the slope and aspect functions. For the spatial analyst module I opted to use the import arcpy.sa code to import the spatial analyst module and for every sa function I included arcpy.sa in the script such as this example for the reclassify tool:  arcpy.sa.Reclassify. General syntax errors I ran into during this module mainly stemmed from when I had to copy bits of code from previous modules. I have learned over the course of these modules that observation of correct filepathing is essential to create a functioning script. Updating filepathing from mod5 to mod6 was necessary for correcting a filepathing error for the file GDB creation that I kept running into. The last major problem I had to deal with was assigning the variables in order to perform slope and aspect calculations using map algebra. The instructions called for the final value to be between two values thus two temp variables were needed: one greater than low value and one less than high value. This involved the creation of two variables for slope (s1 & s2) and two variables for aspect (a1 & a2). The values were determined via values obtained from the instructions. The result of this calculation was five temp rasters that were combined into one final raster using the Boolean And map algebra operator (&). The final raster was saved via the .save function. 

Over the course of this final assignment I found myself referencing past modules to grab sections of code needed for this module. In my future GIS programming endeavors I plan to create a script template that incorporates elements that have been enforced over the course of this class such as including  comment information such as name, date, description, etc and also including common modules imported. 


No comments:

Post a Comment

Spring 2023 semester wrap up

 The spring 2023 semester at UWF has been an eventful one in which I finalized the requirements for my bachelors of science in natural scien...