Exploring and Manipulating Data - Module 5

 In this assignment, we were tasked with selecting and organizing desired data within provided datasets. A folder of feature classes was provided which contained information on notable geographic locations in the state of Nevada. 

Through the use of Python code operating in a Python script -> Python shell, we were asked to create a new geodatabase within our output folder for our studen assignments. This was a relatively easy task involving importing our arcpy modules, to access the features of ArcGIS Pro,  and importing a work environment and workspace to our data folder. In addition, we had to ensure that the code for an overwrite output was placed near the top of our script as the consisten running of this program as we worked through it would need to overwrite files multiple times. 

Creating the new geodatabase was as simple as setting an output variable to the file path for our results folder then using a simple CreatFileGDB_management function.

Next, we needed to create a list of all of the feature classes that existed within our current workspace which was achieved by setting a variable fclist to the arcpy module ListFeatureClasses function.  

Now, to place all of the feature classes found in our workspace into our new data base, we had to set a varialble which uses the describe function to access the infomation stored within our feature classes. This allows the files to be understood by their type and with a simple CopyFeatures_management function we were able to copy them by their basename (geodatabases do not allow extensions for shapefiles, i.e. .shp, therefore the feature classes needed to be assigned by basename) into the new database. The completion of their output, which I added print functions and message counts to so we could witness their status, is shown in the code results below. 



Once all of our feature classes were in the new geodatabase, we set our new environment to the data base and were required to set up a search cursor to pull the names, population, and feature type from the cities feature class that are labeled as county seats as their primary feature. First, I created the variables for the feature class being 'cities'  and set the three fields I would be wanting to pull (NAME, FEATURE, POP). This part was a bit tricky as I found that each field needed to be its own variable: field, field 1, and field 2. Then using the search cursor function I input the feature class we are pulling from and that FEATURE = county seat. This delineated the requisite information as I printed for each field variable using a for loop as they had been limited to only the FEATURE = county seat. I used the print function to print the getValue function of each field. The results are below:





We were then tasked with creating a dictionary repository to hold and display the name of the county seats and their population. I set up an empty dictionary named county_seats and placed empty brackets next to it to assign it as an empty dictionary. 

To place these values in our dictionary, there appeared to be several ways to do this, I opted for setting my workspace to my new geodatabase, setting my feature class as the 'cities' shapefile, and using what is called a delimiting field. This delimits my search cursor by the "FEATURE" field within my feature class. Then using a delimited search cursor (arcpy.da.SearchCursor), I pulgged in the feature class, the fields I was looking for [Name, Pop], the delimited field with the sql expression saying it must = 'county seat.' Then, using a for loop I set the NAME as space [0] and the pop as space [1] in my dictionary and then used the update function to plug in the name:pop to my library. The printed library below shows the results. 



Below is a flowchart to describe the process of my code:




Comments