Monday, June 10, 2024

GIS 5103 Module 4 - Geoprocessing with ModelBuilder and Python

Module 4 of GIS Programming was another opportunity to dive deeper into the Python programming language and its many applications in Geographic Information Systems spatial data analysis.  The first part of the exercise was utilizing the ModelBuilder tool that is included in the ArcGIS software platform. Previously, I had no experience with this tool, but immediately realized its potential in the automation of GIS data processing. Below is an example of what the tool looks like [I used files from work not related to our assignment to avoid giving the assignment's answer away to other students.] As seen below, the model looks like a flowchart where the blue input elements are used as parameters to run the intersect tool [tool elements are yellow in ModelBuilder], and the output of the intersect tool is a new feature class shown as a green element. In this particular case, the Poles_Intersect feature class will contain all points from the IEC AUXILLARY POLES feature class that lie within the zone feature class's boundary. This can all be achieved by simply clicking the 'Run' button after the model is built. The model built for the weekly assignment was to use the clip tool to single out soil areas that lie within a polygonal feature class named 'basin'. Once this was accomplished, we were to select out and delete areas that were categorized 'Not Prime Farmland'. Essentially, this provided areas within the basin that were suitable for farming. 

These are very simple examples of ModelBuilder models, but more complex models can be viewed by a simple Google search. Another great feature of ModelBuilder is the option to export the model directly to a Python script file. This can be very helpful when the complexity of the model exceeds the Python knowledge base of the user. A model can be built, validated, and exported to a script file; the resulting code can be examined by the user to discover how to reach the same result by utilizing the Python programming language.


The second half of the assignment was to create a Python script [from scratch] that executes three ArcGIS geoprocessing tools.  The flowchart of this script is very linear, as shown below:


As the flowchart illustrates, the script takes a feature class named hospitals, adds geographic x- and y- coordinates to each point of the feature class [the coordinates will be added to the attribute table, in fields that are created by the Add XY Data tool]. Next, the script will create a buffer around each point [hospital] that has a 1000-meter radius. Finally, the dissolve tool was run on the newly created buffers to merge them all into a singular, polygonal feature class. Printed messages were created to inform the user what process was being ran, and the ArcGIS GetMessage() function was added to show statistics related to each of the three functions ran. The results of the script can be shown below.

 
After the script was ran, the results were examined in the ArcGIS interface. As shown below, each point represents a hospital, that lies within the buffer feature class, which has been dissolved together into a singular, continuous polygonal area. Also, the X- and Y-coordinates can be seen in the two furthest right-side columns of the attribute table.


Once again, this exercise was a great opportunity to learn more about Python scripting and the automation of geoprocessing workflow. I did not encounter any major problems working through this exercise, other than a few punctuation errors that were easily fixed. Other than these minor issues, the whole process was seamless. Although there are only two modules left in this class, I am truly excited to apply this knowledge at work to see how many redundant processes I can automate utilizing ModelBuilder and / or Python scripts.

Monday, June 3, 2024

GIS 5103 Module 3 - Python Debugging

 



Python scripting is a language of its own, and not using the proper spelling, spacing, and punctuation can make it impossible for the computer to execute the code, exactly like the same mistakes in any written language can render interpretation impossible to a human reader. The goal of Module 3 of GIS Programming was to debug errors in codes that were provided to us, and ultimately enable the computer to successfully interpret the scripts. The assignment was broken down into three parts, with a separate script for each, and the results of each can be referenced in the top image shown above. 

The first was a simple script that was written to type out the fields of an attribute table of a specific feature class. All errors were syntax errors, which include spelling, punctuation, and indentation mistakes. Working through errors one at a time is definitely the most efficient route to debugging any script; I learned this the hard way. When I had initially opened the file, I zealously jumped into the debugging process, changing this error and that error without running the code. In the midst of this haphazard methodology, I managed to change something in the code that did not need to be changed, and I was unable to successfully debug the code. After recopying the original script, I ran the code, fixed the given error, ran the code, fixed the new error, and repeated this process until the script ran. This took approximately three minutes compared to the ten minutes that were wasted by my initial technique. As shown in the top picture, the output was a list of all the fields included in this particular feature class's attribute table.

The second part of this assignment was very similar to the first part; I used the same method of running the code, fixing the error, and repeating until the script ran. This process was also very quick, and probably took less that ten minutes total. As shown in the top picture, the output was a message stating the Projected Coordinate System of the ArcGIS project and a list of all layers that were contained in the project.

Finally, we were tasked with handling a totally different type of error: a run-time error [also called an exception]. While a syntax error will prevent the code from running at all, an exception will allow the code to run, but produces an error that prevents the code from running successfully. In this scenario, we were provided a script that was broken down into two parts; the first section of code contained an error that prevented the second part from running. Instead of correcting the error in the script [a missing parameter that is required by the mapping function], we were required to get the code to run, producing an error message for the first part of the script and successfully running the second part; to accomplish this, we learned how to employ try / except statements. As shown in the bottom image, the flowchart can be followed to see how the script functions. First, the script begins, and the arcpy module is imported [this allows Python to interact with ArcGIS]. Next, a try statement is added to see if the portion of the code declaring variables contains an error. If it does throw an exception, an error message is produced, and the program continues on to the second half of the script. If no exception were to occur, the script would cycle through the entire lyrlist of the project, searching for a feature class named "parks". If a feature class is named "parks", the layer name is printed, the layer's visibility is turned on, and the layer's labeling is also made visible. Finally, the project is saved, the variables declared in the script are deleted, and the second half of the script is executed. If no feature class is named "parks", the script jumps to the lines commanding the project to be saved and the variables to be deleted, and then the interpreter proceeds to the second half of the code. The results of this script can be viewed in the top picture. 

This assignment was a great opportunity to dive deeper into the commands and functions of this programming language, and to familiarize ourselves with the particular syntax that must be used while writing Python scripts. I am still no where near a Python guru, but I am happy with the knowledge I am obtaining through this class on a weekly basis. 

Tuesday, May 28, 2024

GIS 5103 Module 2 - Python Fundamentals

 


Module 2 of GIS Programming was an opportunity to dive deeper into the fundamentals of Python script coding. We were introduced into the different object / data types, syntax, functions, methods, loops, and conditions. While I am no where near a Python expert, I am one hundred times more comfortable typing small scripts in IDLE and ArcGIS Pro. 

The assignment for this module was broken down into four parts, and then compiling those four parts into one Python script; the result of the script can be seen in the image above. 

The first part of the script was creating a string data type that consisted of our entire name, using the split method to divide our full name into its individual names, and to use indexing to print ONLY our last name to the output. This can be seen in the first line of the output [blue lettering]. This part of the assignment was very easy and did not present any issues.

The second part of the assignment was to troubleshoot a block of code that was provided. Essentially, the code is a dice game that takes a list of players, and each player tries to score higher than the number of letters in their name. For example, if a player's name is made up of four letters, they have to score a five to win, a four to tie, and anything lower than four is a loss. The errors found within this code were simple syntax errors that were easy to fix. The first issue was to import the random module, the second was concatenating an integer with a string data type [the solution is to temporarily convert the integer into a string], and the third was a case-sensitive typographical error. Once these errors were corrected, the game was run effortlessly. The results of the game can be viewed on lines two through seventeen of the output [blue lettering].

The third part of this assignment was to generate a list of twenty random numbers that lie within a range of zero to ten. This was accomplished by creating an empty list, generating random integers, and using the append method to add these random integers to the list. Also, a counter variable was defined that counted up by one each time an integer was added to the list. Once the counter equaled twenty, the loop was stopped by executing the break command. The result of this part of the script can be seen in the eighteenth line of the output above.

Finally, we were tasked with creating our own script that chose an 'unlucky' number and deleted it from the list created in step three. A conditional if statement was used to print a statement to the output; if the unlucky number was present, a message appears that states "Unlucky number [x] will be removed [y] number of times from the list." If the unlucky number was not present, a message appears that states "Unlucky number [x] did not appear in the list." Lastly, the remove method was executed to delete all instances of the unlucky number from the randomly generated list. The result can be viewed in the last two lines of the output. 

I am extremely pleased with the outcome of this script, and I look forward to expanding my knowledge base of this programming language.

Tuesday, May 21, 2024

GIS 5103 Module 1 - Intro to Python / Flowcharting


 Module 1 of GIS Programming was an introduction to the Python scripting language, which we will be utilizing this semester to automate geoprocessing tasks to make the workflow more efficient. The exercise and lab assignment for this module focused on opening the Integrated Development Environments [or IDE's], familiarizing ourselves with the interface, writing a couple one-line scripts, and importing / running a script that was written by another person. I was able to follow this code line-by-line with a moderate understanding of what was taking place, but the syntax of this language is completely new to me. Ultimately, the script created a file system on our personal S: drive for our files / data to be saved to throughout the remainder of the semester. It was really neat to just run a program that created all of these folders instantaneously. Manually, this process would have taken at least a few minutes opposed to the second it took to run the script. This was an excellent illustration of how Python scripts can be used to automate redundant and time-intensive tasks. 

The second half of this module's lab assignment was to create a flowchart of a script that would convert [3] radians to degrees and print the output. We did not actually write the code, but the process we would undertake if we were to write it in Python. Essentially, we used conventional symbology to begin / end the script [ovals are used for termination processes], define the variables such as radians [3] and Pi [3.14159] [rectangles are used for assignment and computational processes], print the output of the calculation [parallelograms are used for input / output processes], and terminate the script [oval shape again]. The flowchart for this script can be viewed in the picture above. 

I am highly excited to dive deeper into the Python programming language and use it to create a more efficient and streamlined workflow in ArcGIS. 

Thursday, May 2, 2024

GIS 5007 Module 7 - Google Earth

 


The final Module of GIS 5007L was an exercise that solely focused on Google Earth. Using ArcGIS Pro, we imported the data provided for this exercise and converted it into a KML [Keyhole Markup Language] file; this file type is mainly used in Google Earth to create interactive 3D maps. I use these functions almost daily at work because most of our clients do not utilize the same GIS software that our company does, and KML files can be viewed on any computer with Google Earth Pro installed [this program can be downloaded for free here].

As shown in the screenshot above, we created a dot density map of southern Florida that also featured some polygonal layers that illustrated the locations of many large lakes, marshes / swamps, and streams throughout the southern half of the state. The legend was provided as a JPG file, so I imported this image into ArcGIS prior to the KML conversion, and utilized the eyedropper tool to match the colors of the polygons to the colors in the legend perfectly. 

After the KML file was created, we added the legend to the screen so the map viewer can see it through the Google Earth interface. Per the lab instructions, we were to insert the legend as a graphic overlay; this essentially assigns it a geographic location and forms it against the surface of the Earth, causing some distortion within the legend. One of the student leaders offered some excellent advice on how to insert the legend as a screen overlay, which places it at a particular location on the screen [as opposed to a geographical location]. This gave the legend its original appearance and did not cause any distortion; I was very pleased with the outcome. 

The second half of the exercise was creating a 3D tour of southern Florida. In my tour, I begin with a global shot of Earth's western hemisphere and then it zooms into the southern Florida region, bringing up the layers of the KML created in the first half of the lab. Then, it zooms in further to the Miami metropolitan area, displaying Jupiter, Florida all the way south to Homestead, Florida. After this shot, the camera zooms into a 3D view of downtown Miami, and the layers / legend are removed from the screen. There is an orbit around the Miami central business district and then the camera flies over to Ft. Lauderdale, followed by an orbit of the central business district of this city. Next, the computer zooms back out to satellite view over the Tampa Bay metropolitan district [Layers / legend are turned on for this shot]. The camera then zooms back in to 3D view and orbits around Tampa Bay and then St. Petersburg before zooming back out to the entire southern Florida shot again. Finally, the computer zooms all the way back out to the original view of the global western hemisphere that began this 3D tour. Anyone that has Google Earth Pro installed on their computer can download and view the tour by clicking the link below; once the KML is loaded, just double click the '3d Tour' link in the pane on the left side of the screen [Make sure the 3D Buildings layer is turned on].


This lab assignment presented no major obstacles but was an enjoyable way to end this semester and a great opportunity to explore the capabilities of Google Earth that I do not get to utilize often. 

Thursday, April 25, 2024

GIS 5007 Module 6 - Isarithmic Mapping


 Module 6 of Cartography was based on Isarithmic Mapping. Isarithmic mapping differs from the other types of maps created in this course because it uses raster-based datasets. Raster-based datasets are pixel arrays, arranged in a grid pattern, where each pixel contains a data value. Therefore, each pixel can be individually mapped; this is why raster-based datasets are also called continuous data. Previously, this course has focused on vector datasets, which are comprised of points, lines, and polygons. 

To create raster-based datasets, sample data is taken at specific geographic points [stations] and the areas in between are filled in [interpolated] using various algorithmic methodologies. Essentially, this provides a mathematical estimate for the areas that lie between sampling stations, because it would be impossible to collect data [precipitation amounts in the state of Washington for this exercise] at every geographical point. For the Module 6 lab, we were given a data set that was created by the PRISM [Parameter-elevation Relationships on Independent Slope Model] Group, located out of Oregon State University; this data set included annual precipitation amounts for the state of Washington from 1981 through 2010. For background context, PRISM, unlike conventional interpolation methods, incorporates a regression function into each data cell that considers physiological characteristics of that geographic location, such as elevation, coastal proximity, and other factors. This provided a more accurate interpolated precipitation map than what was previously drawn by hand, and the PRISM model has been continuously evolving, and improving, since its initial introduction in 1991. 

Using ArcGIS Pro, the first half of this exercise was to map the dataset using continuous tones. This means that instead of creating classes of data ranges, there is a continuous color "ramp" between the highest data value and the lowest; each pixel's data value can fall anywhere on the spectrum between the highest and lowest data values. While this method is more accurate on a pixelated basis, it will only give a generalized estimate when viewed with the naked eye.

The second half of this exercise was to map the dataset using hypsometric tinting [using ArcGIS Pro]. This method employs the use of data classes where each pixel falls within the range of a single data class. Each data class is attributed to a different color, allowing the user to easily identify which range each pixel belongs. We also used a geoprocessing tool that created contour lines which outlined each of these data classes, further defining that boundaries of each area. While this method is not as accurate as using continuous tones, it does allow a quicker analysis by giving the user a generalized range in which the data for each area lies. 

This lab exercise was very straightforward, and no issues were encountered during the cartographic process. It was a great opportunity to use various tools included in the ArcGIS Pro software platform, including Hillshade Function, INT Tool, and the Contour List Tool. I was very pleased with the created deliverable, and believe that it effectively portrays the information in an aesthetically pleasing manner. 


Source:

     Daly, C., & Bryant, K. (2013). The PRISM Climate and Weather System—an Introduction. Corvallis, OR: PRISM Climate Group, 2.

Thursday, April 18, 2024

GIS 5007 Module 5 - Choropleth and Proportional/Graduated Symbol Mapping

This week's module focused on choropleth and proportional/graduated symbol mapping; choropleth mapping is a mapping technique that uses a graduated shading scheme across predefined enumeration units [typically political boundaries, such as counties, states, or countries in this case]. Proportional/Graduated symbol mapping is a mapping technique that places dots at geographic locations where occurrences take place, and uses progressively bigger symbols to portray differences between classes; also, these dots can be placed at either true or conceptual points during the mapping process. For this exercise, we used the choropleth method to map the population density of many major European countries and we used the proportional/graduated symbol method to map how much wine is consumed in each of these same countries. 

Overall, this assignment was a great introduction to these two mapping schemes, and many challenges were met throughout the entirety of this assignment. ArcGIS has been the software platform used for each module's assignment, and has never presented any issues while running over a virtual desktop environment - until Module 5. For extra credit, we were allowed to use pictorial symbols for our "dots" on this map, and I found a fun little clip art file at Freepik. Once this little .SVG file was introduced to the ArcGIS project file, every action taken to create this map was slowed by an incredible amount.

The process in classifying the data was relatively simple; I chose the natural breaks method, but needed to include a fifth class so detail was not lost having only four classes. However, to create the inset maps, data had to be excluded from the main map. This regenerated new class values, so I ended up selecting the manual intervals option where I could input the original class values. 

Finally, converting all labels to annotations and converting the wine consumption feature class to a point [it was originally a polygonal feature class] also proved to be quite burdensome while working over a virtual desktop. Slowly, I was able to get each label and grape cluster positioned in a manner that was easy to read and understand.

I am very happy with the quality of this map, and I feel that this exercise proved to quite helpful in grasping an understanding of these mapping methods.

GIS 6105 Module 6 - Interpolation

For the final map deliverable, I simply modified the map from Module 5 to create a sense of continuity between the two sequential lab assign...