GEOG 485:
GIS Programming and Automation

Lesson 3 Practice Exercise C Solution

PrintPrint

Below is one approach to Lesson 3 Practice Exercise C. The number of spaces to query is stored in a variable at the top of the script, allowing for easy testing with other values.

# Selects park and ride facilities with over a certain number of parking spots
#  and exports them to a new feature class using CopyFeatures

import arcpy
parkingSpaces = 500
arcpy.env.workspace = "C:\\data\\Geog485\\Lesson3PracticeExercises\\Lesson3PracticeExerciseC\\Washington.gdb"

# Set up the SQL expression to query the parking capacity
parkingQuery = '"Approx_Par" > ' + str(parkingSpaces)

# Make a feature layer of park and rides that applies the SQL expression
arcpy.MakeFeatureLayer_management("ParkAndRide", "ParkAndRideLayer", parkingQuery)

# Copy the features to a new feature class and clean up
arcpy.CopyFeatures_management("ParkAndRideLayer", "BigParkAndRideFacilities")
arcpy.Delete_management("ParkAndRideLayer")

The video below offers some line-by-line commentary on the structure of the above solution: