[MUSIC] >> Okay, hello everyone and welcome back. In this lecture we're going to continue where we left off with the last lecture by making the first part of our tool to find which parcels are on the same side of the river as the original town boundary. So to start out, let's make a new toolbox as we did before. I'll go to Add Toolbox and what we can do this time that we didn't do before is we can just click the New Toolbox button up here, just like the New File to your database button. So I'll click New Toolbox and I'm going to call it Town Relocation Tools. And it doesn't have to end in tools just in practice people often do end it in tools. Because the standard built in ones end in tools and it's a good way to encapsulate what's inside of it. So I"ll click that now once, not double click again because it goes inside if I do. So I'll click once and click Open. And when I do, I should get Town Relocation Tools toolbox down here. Now what I need to do is right click and go to New and Model. Or I can go up here just to the standard toolbar and click ModelBuilder and bring up the canvas. So let's do it that way this time and to add it to the toolbox I'll do Save As in the Model menu and then I can find what toolbox to put it in. And by default it put me in my ArcGIS folder in My Documents. So I'm going to go find my folder that I just made my toolbox in to go put it in there. And here's Town Relocation Tools and I'm going to call it Mark Parcels On Same Side of River. I'm sure you can come up with a better name but that's sufficient for now. And if I go to Town Relocation Tools, I can see it inside the toolbox now. Okay and to start with, I can add data a few different ways. I can take the parcels and just drag them onto the canvas this way. Or I can use the Add Data button on the model to add the data to the model canvas without adding it to the map document. I can also add data by creating a variable and I can add data of all sorts of different types. So I might want to add data that's a feature class to add data like this. And then I can double click on it to fill it what feature class it is. And then I can also add a tool which I'll do now and define the inputs to add the data out front of it. So that'll make sense in a moment. Now one thing I like to do with my models in particular is I like the first step in my model to make a copy of the data I'm working on. Because especially if I'm going to add fields to that data set. When I keep working with the data I want to not actually destroy my input. When I have a complex model, I may end up running it 5, 10, 20 times to debug it and that means that I add that field 5, 10, 20 times. And it's nice to not to worry about that because if the first part of the model is to make a copy, then it starts with the clean version of that data set each time. And I don't destroy my input and I don't get weird behavior in my model. But so far we haven't really talked about ways to make copies of data with geoprocessing tools. The only things we can put on our model canvas are geoprocessing tools and data or variables here. So, we need to learn how to do it with a geoprocessing tool. In fact, a lot of the things you use, especially in our catalog to make copies of data are geoprocessing tools. If it looks like a geoprocessing tool when it pops up, it probably is. Otherwise, it tends to look like a standard interface option here like this is not a geoprocessing tool. But in the catalog window, if I go to a geodatabase somewhere and go to Import Feature Class, this is a geoprocessing tool, right, we recognize this. Well, note that it's called feature class the feature class. In this case, we won't use that tool, we're going to instead use the Copy Features tool. Because the nice thing about the Copy Features tool is it also works on selected sets. So in this case, we won't have a selection. But I want you to know about this because it works when we have selection active on a layer and we'll use that a little later on in this model. So directly from search results I can just drag and drop the tool onto the model canvas just like I could from our toolbox here too. And with tools I can also add them up here with the Add Data or Tool button. Okay, and now we can get to our last way to add data to our map document, or not to our map document, to our model. Well, I already showed you the three other ways where we can add variables, we can use the Add Data button or we can drag and drop. If I double click on a tool and it has a data input, I can select from the input features list anything in my map document or that's already in my model. So I'll click Land_unit_ parcels here and that's our parcels layer. And if I click okay, Land_unit_parcels shows up in front of here. So I could've added it that way. I can also delete it here and it will be undefined in the model now. And then I can still just drag and drop it onto the canvas and then use the connection tool up here, the Connect tool. And click on it and drag and release on Copy Features and then select that it belongs as the Input Feature's parameter. That's not just a casual word, if I double click on it, I can see that this is Input Features. So when it's offering me to some sort of item to select when I make a connection, it's offering me different parameters in the model that that variable, that that item on my canvas can potentially fulfill. It will only show me items that that variable can actually fit as and we can make it connect to something else too. So note that we have Environments and so it shows me the Environment settings for that tool that this particular feature class can be set as. So we can set it for the Extent or the Cell Size or the Mask. But it's not a raster and we're not doing raster analysis, so I'm going to not set those right now either. One other thing to note is we can set it as a Precondition. And a precondition means that the data isn't fed in, but that this particular operation, whatever is happening out to the left here needs to happen before we run this tool. And we'll make use of that a little later. Okay, now let's name these a little more clearly. And I'm going to leave copy features as it is, but I'm going to insert text to explain why I'm doing that. So I'm going to create a label, I'm going to have both selected now. So if I do this, I'll create a label here and I'll call it, I'll say Copying data to allow for multiple testing runs as I said before. Now the only issue here is if I change around my canvas or something and then I click the Auto Layout button, sometimes things like that get a little messed up. The labels don't necessarily go particularly well. So we might want to add our labels mostly at the end. But I just want to make sure you saw that we could do that. The other thing is let's name our output a little more clearly here. So let's close this. I'm going to rename it here and we'll call it copied_parcels_layer. And notice that when I do that and click back into the tool, that doesn't affect the name in the output feature class. Instead it just affects the name we use to reference it and the rest of ModelBuilder. So what I might want to do is call it copied_parcels_layer here. And that way I get the same data layer name in the default geodatabase. And I don't end up with naming collisions if I do anymore copy features later. Okay, now let's add another tool to our canvas, so one thing we know we need to do, is before we actually mark the river, or the parcels that have rivers, as rivers, we need to add a field to mark. So let's go to search for geo processing tools again. And here's another thing you've only done in the interface you haven't done with geoprocessing tools in this class or in these classes is Add Field. You've done it from the Table Menu but you have not done it directly from a geoprocessing tool yet. So here it is right here and I can just drag it straight to the canvas. It's also in the main toolbox, if I go to Data Management Tools > Fields. There's an Add Field, geoprocessing tool right there. It's the same as this. And, this tool, if I don't click to open it, you notice familiar, you'll notice familiar items here like the input table, the field name and the field type, but it's not the same tool we've used when we're looking at the attribute table. So if I got to open attribute table in the table menu here. I can go to Add Field, and I just got a different interface for it. These two things do the same function though. Adding a field here isn't really any different than adding a field to the geoprocessing tool, so we could use either one, but on ModelBuilder we can only use the geoprocessing tool, it doesn't use interface items. So let's connect them let's say I want the output of this copy features tool, this new parcels layer, this copied parcels layer to be the input to Add Field. And I want it to be the input table because it can't be the field it's the input table. But this time Add Field didn't light up because I need to define more before Add Field is ready to run. And in fact I need to define the field name. So in this case I'm adding a field to say whether or not the parcel is a river. So is_river will be my parcel name. And I'll make it a short because it's just going to be a zero or a one. And I'll leave it as nullable because initially they won't have any values so the field will be full of null values. I'll click okay and now that item is ready to run and I'll click Auto Layout again just to align everything. And I'll name this one. I'll right click on it and go to Rename, and I'll call it parcels_with_ river_ field, just to kind of keep track of what's going on here. And now we can add one more tool to here. Because we have now copied our parcels layer and get that copied_ parcels_ layer is this item here. And then we pass that layer into the add field tool and get this particular feature class with that field added. But, what we still need to do is set the value on that field. So I'm going to go to Calculate Field. And guess what this does. It's the field calculator. So we've accessed the field calculator by right clicking on field, going to field calculator and we get this dialog here. It's another item that is available as a geoprocessing tool specifically so that we can use it in geoprocessing workflows like ModelBuilder or Python scripting. And I connect this version of the copied_ parcels_ layer here as the input table again. Now, one thing to note is these items are basically the same here, and the reason that it exists in both spots is that all model tools need to have an output so that you can feed things linearly into the rest of the model. Theoretically, I could make a connection between this item and Calculate Field and make that the input table and then set this as a precondition. So that what it would do is run this, it would run this, and then it would run this tool with this as an input. Because the precondition says this needs to complete before going to the item that it's a precondition for. But, it makes a lot more sense to just make this the input table here and I'll delete that precondition because it's redundant. Because, any time there's an arrow, the item on the left side of the arrow here happens first. The other thing we get here, is that ModelBuilder does some special work in the background, that if it has this copy of it here. Even though they're referencing the same feature class on my hard drive, the Calculate Field tool now knows that this field that we added here should exist. So when we go to Calculate Field, under field name is_river shows up here because even though it doesn't actually exist on the feature class yet because we haven't run our model, it knows that it should exist because it's getting the output of the Add Field tool. So, that's great. And I can click okay, and it's still not ready to run, even though it knows the Input Table and the Field Name. So what we need to do is give it an expression. And what I want to do here is just set the default. I want to say that none of the parcels are a river layer for now, or not a river layer. None of the parcels are coincident with the river for now, we'll then go mark which ones are but we need to set the default up to zero first. So I'll click okay, and this time I'm going to rename this to say Calculate_ Defaults_ River_Value. And it still knows to run the Calculate Field tool. If I double click on it, it names it up here and names it over here but it's still the Calculate Field tool. And I can do the same to these other tools as well. And let's rename this, so we know what's going on to. And I'll call it, Parcels_with_Default_ River_ Value. And then I'll hit the auto arrange button again, and I'm going to hold control and scroll to zoom out a bit so we can see the whole thing, and here's our model so far. What it does is it takes the land unit parcels we provide to it, it copies them to a new version of that same layer. It adds the field for whether or not the parcel is coincident with the river, and then it calculates that field to be a zero. In the next lecture, we will move a little more quickly since we have some of the Model Builder basics down, and we're going to add another field and calculate its value to be a default value of zero. And that will be the field for whether or not it's on the correct side of the river. And then we will start calculating the actual values of those fields. We're just filling in blanket zeros as defaults now so that we can then override that value for places that are coincident with the river or that are on the correct side of it. Okay, so in this lecture we learned a bit more about connecting variables and tools in ModelBuilder. And we learned about some tools that we've used in the ArcGIS interface, but that exist as geoprocessing tools, so that we can use them in ModelBuilder and Python, such as the Copy Features tool, the Add Field tool, and the Field Calculator tool. See you next time.