GEOG 485:
GIS Programming and Software Development

Lesson 3 Practice Exercise B


If you look in your Lesson3PracticeExerciseB folder, you'll notice the data is exactly the same as for Practice Exercise A...except this time the field is "HasTwoParkAndRides."

The objective

In Practice Exercise B your assignment is to find which cities have at least two park and rides within their boundaries.

  • Mark the "HasTwoParkAndRides" field as "True" for all cities that have at least two park and rides within their boundaries.
  • Calculate the percentage of cities that have at least two park and rides within their boundaries and print this for the user.


This simple modification in requirements is a game changer. Following is one way you can approach the task. Notice that it is very different from what you did in Practice Exercise A:

  • Create an update cursor for the cities and start a loop that will examine each city.
  • Make a feature layer with all the park and ride facilities.
  • Make a feature layer for just the current city. You'll have to make an SQL query expression in order to do this. Remember that an UpdateCursor can get values, so you can use it to get the name of the current city.
  • Use SelectLayerByLocation to find all the park and rides CONTAINED_BY the current city. Your result will be a narrowed-down park and ride feature layer. This is different from Practice Exercise A where you narrowed down the cities feature layer.
  • One approach to determine whether there are at least two park and rides is to run the GetCount tool to find out how many features were selected, then check if the result is 2 or greater. Another approach is to create a search cursor on the selected park and rides and see if you can count at least two cursor advancements.
  • Be sure to delete your feature layers before you loop on to the next city. For example: arcpy.Delete_management("ParkAndRideLayer")
  • Keep a tally for every row you mark "True" and find the average as you did in Practice Exercise A.