Click for a transcript of "3C" video.
PRESENTER: This video describes a solution to lesson 3 of practice exercise C, wherein we want to select park and ride facilities that meet a certain threshold of a minimum number of parking spaces, and then, copy them to their own new feature class.
After importing the arcpy site package in line 4, we set up the variable representing that threshold. So in this case, we set that equal to 500 parking spaces.
Putting the variable at the top of the script is helpful so that number is not buried down later in our code. And so if we want to adjust this value and test with other values, it's easy to find.
In line 6, I'm setting up the arcpy workspace to be equal to my file geodatabase location. This is a little different from some of the things shown in the other practice exercise videos. But it's a nice way to work with file geodatabases, in the sense that, from now on, if you refer to a feature class, you only have to use it's name. You don't have to put the entire path. And you'll see that occur later in this script.
Line 9 is probably the most critical line of this script. It's setting up the SQL query expression to get park and ride facilities that have greater than that number of parking spaces. So if you were to look at this in ArcMap, where the park and ride facilities are the black dots, we would do a Select By Attributes. And we query on that attribute Approx_Par is greater than 500. And that would give us those large park and rides that are primarily found in the Seattle and Tacoma areas.
Notice that you need to convert that integer of 500 into a string, just for the purpose of putting it into this query expression. However, you don't need to enclose it in any type of special quotes. The field name, you do have to put into double quotes, and that's why I've surrounded this part of the expression with single quotes, as you learned in your lesson materials.
Once you have that query string all set up, you can run MakeFeatureLayer to get a Park and Rides Feature Layer with just those selected park and rides that meet the criteria.
So there's three parameters to pass in here. The first one is the name of the feature class that were operating on. And again, because we set up the workspace, we can just put that we're working with the Park and Ride Feature Class.
The second parameter is the name of the feature layer. And we could name this anything here. It's just going to reside in the computer's memory, as long as we're consistent.
And then the third parameter is that SQL query expression. This is optional. If we omitted this, we would just get everything. But we want to just have those park and ride facilities that meet the criteria.
Once we have that feature layer, we can run the copy features tool to make a brand new feature class with just these selected elements. So the two parameters here-- the first one is the name of the feature layer that we're working with. And, in line 12, remember that we called this Park and Ride Layer.
The second parameter, Big Park and Ride Facilities, is the name of the new feature class that we want to create. And so once we've done that, we have a new feature class and we can run the Delete tool to clean up our feature layer. And that's all we need to do in this script.