Print
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 = r"C:\PSU\geog485\L3\PracticeExerciseC\Washington.gdb" arcpy.env.overwriteOutput = True # Set up the SQL expression to query the parking capacity parkingQuery = "Approx_Par > " + str(parkingSpaces) # Select the park and rides that applies the SQL expression parkAndRideLayer = arcpy.SelectLayerByAttribute_management("ParkAndRide", "NEW_SELECTION", 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:
Video: Solution to Lesson 3, Practice Exercise C (3:32)
Below is an alternate approach to the exercise.
# 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 = r"C:\PSU\geog485\L3\PracticeExerciseC\Washington.gdb" arcpy.env.overwriteOutput = True # 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: