Module 5: Explore and Manipulate Data
In this weeks module the focus was on how we can explore and manipulate data that are within ArcGIS Pro. The script creates a new file geodatabase, copy feature class data to the new file geodatabase, create a Search Cursor for the cities feature class, and create a new dictionary.
First we needed to create a new file geodatabase that goes into the results folder. It is important to note that before any of this can begin you need to make sure you import arcpy and import env. Also, to make sure you can create the geodatabase more than once you need to have the overwrite output to True. If you are getting an error message if trying it again it is because ArcGIS Pro is open and it needs to be closed before running it in Python IDLE. If you run it in the Notebook portion in ArcGIS Pro you do not seem to have that problem. The image below shows the outcome of the script that was written.
The next portion of the script was creating a feature class list and copying that into the new geodatabase that was previously created. When making sure the data gets copied you need to use the Describe() function. Also, to get all the data copied you need to make sure to the script as the following
arcpy.CopyFeatures_management(fc, outputEnv + "/ejd31.gdb/" + fcdesc.basename). This piece of code makes sure everything gets copied and that the basename of the feature shows up when it gets copied. In the image below shows that each feature got copied and how long it took to get the information to copy into the new file geodatabase.


After that I needed to create a Search Cursor that only printed the Name, Feature, and Pop_2000 only for the county seat within the cities shapefile. I knew how to write the code for one row in the attribute table but was not sure for three. I made the fields code as fields = [“NAME”, “FEATURE”, “POP_2000”] and the sqlQuery = “FEATURE = ‘County Seat’”. I used the arcpy.da.SearchCursor because I did not want to change the table but to just find the specific rows and print them. Also, you need to make sure to use a for loop statement to make sure only the specific rows get printed and not the other ones in the attribute table. The image below shows all the features that were only County Seat with the name and population of those features.





The last portion of the script was creating a new dictionary based off the information from the cities shapefile attribute table. The dictionary needs to focus on the name and population of the county seat features. Another issue I was having was trying to get the for loop statement to create a dictionary for an empty dictionary. I knew how to make the dictionary but was not sure how to make the statement work. I did try different versions and none were working for me. I think asked the discussions page and Serenity helped me with the script needed to have another line of code saying with
arcpy.da.SearchCursor(fc, fields, sqlQuery) as cursor: The information in the parentheses is based off the previous script above. The difference is that I needed to add the specific row numbers for the keys and values that I wanted represented in the dictionary. Lastly, I chose the dictionary variable[keys] = variables which was
county_seats[name] = population. The image below shows the new dictionary with just the information of the Name and Population of the county seats in the cities shapefile

An important note is that to get the copying features to print separately the code is print(f”Copying: {fc} \n”). This was able to help me get them to print one at a time instead of all of them at once over and over again. Knwoing how to get the information to print properly will help know what is being copied in the first place. The script creates a new file geodatabase, copy feature class data to the new file geodatabase, create a Search Cursor for the cities feature class, and create a new dictionary. The image is of the flowchart that I used for the script that was written.