Lab 04
Lab 04: Arcpy
This lab covers the Arcpy, including topics such as SearchCursor, UpdateCursor and InsertCursor.
There are four questions in total. Please provide your code answers directly below each question.
Make sure to run all cells so that the answers are stored. Once completed, submit the .ipynb file (ensuring that all answers are included) to Canvas by midnight (11:29 PM) on September 29.
This lab is worth a total of 65 points and contributes 6.5% toward the final grade.
1. SearchCursor (20 points)¶
using the arcpy.da.SearchCursor to retrieve and display information about each traffic accident. Specifically, your script should do the following:
- Use a SearchCursor to iterate through the Vehicle_Crash feature class.
- Retrieve the following fields:
- CRASH_DA_1 (the date of the crash)
- NUMB_VEHC (the number of vehicles involved in the crash).
- Sort based on following field:
- NUMB_VEHC (the number of vehicles involved in the crash)
- Print a statement for each crash that indicates the date and the number of vehicles involved in that accident in the following format:
"On [date], there are [number] vehicles that were involved in traffic accident."
2. Insert below new data using InsertCursor (20 points)¶
- Using InsertCursor to add 'points_data' to the 'Vehicle'
- Note: Please ensure that your insert row and the feature class ('Vehicle') have the same column names.
3. Update "Vehicle_Crash_insert" using UpdateCursor (20 points)¶
- Add a new field named 'Vehicle_Class' of type 'Text' to 'Vehicle'.
- Update Values:
- If 'NUMB_VEHC' is greater than or equal to 3, update the 'Vehicle_Class' to 'More'.
- If 'NUMB_VEHC' is less than 3, update 'Vehicle_Class' to 'Less'.
4. Statistics (5 points)¶
Compute and print the proportions of "More" and "Less" classes as percentages based on 'Vehicle' (now for the "Vehicle" data, you should have inserted new rows and update the values.)