Module 5- Exploring & Manipulating Data

 This module was by far the most challenging yet. I learned various skillsets like working with dictionaries, manipulating lists, describing data, and using SearchCursors. The final lab assignment of this module prompted me to use all of these skills in tandem to write a script to batch multiple processes and manipulate a list of data. 

The full prompt of this assignment asked me to create a script that would:

    1) Import the proper modules and allow overwrite outputs

    2) Create a new file geodatabase within my module folder

    3) Copy a list of files from my data folder, use the Describe() method to alter the names of the files, and         paste the newly named files into my new file geodatabase

    4) Create a SearchCursor and use it to iterate over a shapefile and find the names of the features that             met a certain criteria using an SQL Expression

    5) Print the values of three fields for the selected rows in the SearchCursor

    6) Create a new dictionary and populate it using keys and values found by the SearchCursor

I wrote my script following the flowchart pictured below: 

Once complete, the script ran and issued the following results:


This was quite the process and took many, many iterations until I got the script to run properly through each of block of code. Here are some notes I took with portions of the assignment I struggled with as well as how I worked them out:

 1         The first portion of the lab assignment I had issues with was designing my SearchCursor. Mainly, I had issues visualizing and implementing how to get three rows of data from three fields to be implemented. I tried initially to add more than one field into the AddFieldDelimiters function, like this: AddFieldDelimiters(fc, “FEATURE”, “POP_2000”). This resulted in an error as only one delimiter can be added in the parentheses. I realized that I did not actually need to have POP_2000 be a delimited field at all, I simply needed its field to be iterated within the “for” loop. Once my SQL expression was designed properly in my searchCursor and this statement was added, I was able to get the population to print. I did however receive concatenation error when trying to add a string to print within this function. I tried many different combinations to get it to all print in one line, but nothing worked. I elected to just print the string sentence first with a colon and let the population print below it.

2         The dictionary population portion of the assignment is where I got hung up the most. I toiled with the exercise, lecture, text readings, and multiple online sites to try to get it to work. I understood I needed a “for” loop with one of the two formats for populating a dictionary within it, but I could not seem to figure out how to write the syntax properly. I was initially trying to use the same row.getValue function within the dictionary format and I ended up with an empty dictionary no matter what I tried. After meeting with Travis Erickson, he clued me in that I was forgetting to reset the cursor. I used ESRI’s help page on cursors to reset the cursor using the proper syntax and was receiving errors. I decided to use the dictionary.update format and I believed everything was good to go. The error I was receiving was in my SearchCursor expression. Travis helped me realize that I was missing a “.da” (data access module) between “arcpy” and “SearchCursor” and that it may be causing the error. Sure enough, the dictionary populated after this change. I was very stumped by this as the SearchCursor I used in the previous block of code ran fine without this data access module, and I did not see it used in anything but an Update Cursor in the exercise. I am not sure I would have come to this conclusion myself had it not been for Travis’  help, but I assume it has something to do with resetting the cursor.


This concludes my work for Module 5, on the next and final step towards completing this class!





Comments