Tuesday, June 14, 2022

GIS 4102 - Module 4 - Exploring & Manipulating Spatial Data using Python

 Module 4 for GIS programming involved creating a script in Spyder using Python. The script created a geodatabase called atg6.gdb, copied features from a data folder to the fGDB, used a search cursor to find the Name, Population, and Feature of all cities listed as county seat in the cities shapefile and created a dictionary that populated with the name and populations of each 'County Seat' city. The following is a screen shot of the console running the script with completion print messages.

Some problems that I encountered involved creating the file geodatabase. My issues were resolved by correctly setting the output environment. I corrected this through fixing syntax errors in the following line of code: arcpy.CreateFileGDB_management(outputEnv, "atg6.gdb")

Creating the for loop to copy files from the data folder to the fGDB was another problem I encountered. I corrected this error by adding a description statement that allowed all items in the fc list to be described by their base names. This allowed the script to search the features without file extensions and allowed them to be copied to the fGDB. Getting the search cursor to work correctly was another problem encountered. I ultimately reconciled this portion of the assignment by separating each field into individual variables field = “NAME”, field2 = “FEATURE”, field3 = “POP_2000”.  The feature class portion of the script was also not detecting the cities shapefile in the fGDB. I made it recognize the file by adding the .shp file extension to the end of the cities feature class so the line of code looks like this: fc = “cities.shp”.

Something I found useful used in this module and past modules was the arcpy.Getmessages function and I will have to remember these functions for future projects in order to display a “Succeeded at <date and time> (Elapsed time: <____> seconds)” message.
Beginning
count = arcpy.GetMessageCount()
After each print statement process
print (arcpy.GetMessage(count-1))


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...