Module Five Exploring & Manipulating Data
For this week's Module 5 we worked with exploring and manipulating data. We were tasked with creating a script that would create a new geodatabase, then copy all the data from my data folder into the new geodatabase, then populating a dictionary with the names and population of every County Seat city in New Mexico. Finally printing out the creating and completion of the script.
Some of the learning outcomes from doing this week's lab exercises and writing the script were getting familiar with working with search cursors, list and working with dictionaries. Also to use the script to be able to check for, describe and list data. As well as using a flowchart to design a model of a script.
I have shared below the output of the script I wrote with the help of the lab instructions, lab exercises, reading material and research. I have also shared a picture of my flowchart I created for the design of this script.
To start the script, I needed import the necessary components and set the workspace environment to my data folder, then set my output environment. Using CreateFileGDB_management() to create the new fGDB. Then I used ListFeatureClasses() to get the feature classes names and used a for loop to copy all the features from the Data folder into the newly created fGDB. Following up with adding the print statements. Then moving on to creating a search Cursor for the cities feature class. Search cursors are used to search records and carry out SQL expressions in Python. I set the fields variable equal to the list of field names from the attribute table of the feature class cities. I used a sqlwhere clause to filter and then a SearchCursor to loop through the filtered records and prints the name, population, and feature type for each matching city. Following up with adding the print statements. Finally, I created an empty dictionary named county_seats. I used the SearchCurser() to populate the dictionary with the city names as keys and populations as values, deleting the cursor and row variables after the loops runs. Then adding a print statement to print the populated dictionary. Then I did the final follow up with adding all the print and getmessage statements.
For the most part this lab went a lot smoother for me than I was expecting, which showed all the previous work paying off. But of course, I still had some issues. One of my issues that I got stuck on for longer than I would like to admit. Was adding the print (arcpy.GetMessage()) statements. It was finding the right spot to place them and adding the spaces correctly. I kept looking back on the past exercise and the current exercise which helped me. I noticed for some of my print statements I needed to add the + sign to the line of code before adding the space \n. Another time waster\learning experience I had was when I was creating the Search Cursor. First, I did not put the correct updated file path. Which I didn't notice even after receiving the error. It was after rereading the instructions about updating your workspace environment that made me double check that I did it correctly and I noticed I had not. Then somehow when updating it I removed a period from the file path. With the errors that Notebook gives you I knew the file path was wrong, but I couldn't figure it out. I thought I had possibly moved the new fGDB or deleted it. After trouble shooting it for more time than I like to admit I spotted the missing period. Final thoughts are once again run your scripts in small sections to help solving the error messages. It is very helpful!
Comments
Post a Comment