[MUSIC] Hello everyone and welcome back. In this lecture, I'm going to continue where I left off last time with the model we've been building. So far we have copied the feature class, added and calculated the default value for the is_river field. And then we loaded up the feature class as a feature layer, selected the parcels by location that intersect with the river. And set those parcel's value for the is_river field to 1 indicate that they do have the river running through them. Next up I think what we need to do is add another field for whether it's on the correct side of the river. So I'm going to do that way back here before we load it as a feature layer. And while we could do it in line with the rest of this, let's show off some branching in ModelBuilder and learn a few other concepts while we do it. So I'm going to select Add Field and I'm going to hold control and select the field calculation here. And I'm going to hit Ctrl+C on my keyboard and Ctrl+V to paste them. And we're going to duplicate those, and it's going to branch off of this initial copied features and then run that same operation again. So now let's tweak them to actually reflect what we want to add. So, in this case the add field isn't is_river anymore, it is_on_correct_side_of_river. And this is basically setting up the end goal for this model, which is this field that has whether or not it's on the correct side of river as 0 or 1 to indicate whether the parcel's on the same side of the river as the town boundary. So I'll click OK, that's fine now. And then let's rename this, parcels_with_correct_side. Just so we know a little more what's going on and let's even rename this time. Add Correct Side Fields. This one can be Add River Fields. That way we know which one's which when we go to modify them later. And this one will be Calculate Default Correct Side Value. And now we can actually look at this at a glance and know what our model is doing. And once again, even though I've renamed these, they're still the same tools underneath the surface. And, I'll call this parcels_with_default_side_value. So, I could run these now, and that underlying feature class would get the values attached. But, now that we've branched out here, how does ModelBuilder know when to run this? Well, by default, it's pretty smart and figures out kind of where to go, but generally speaking, if we know that this needs to be available before some time in the future, we should use the prerequisite option. Now, in this case, I think we want to make it available before we make a feature layer because we want to make sure that this field is available when it's a feature layer. So, I'm going to use the connect tool and click and drag from the output of the Calculate Value tool here to the Make Feature Layer. In this case, I'm just going to call it a precondition which says that these need to run before this and ModelBuilder will choose whether it runs the rest of this or whether it runs this and then this. But regardless, all of this will run before it runs Make Feature Layer and everything after it. And now let's just run the whole thing and watch the branching in action. So let's validate it, no warnings, great. If it doesn't tell us anything, we're good. And if it does, it'll pop up a dialog telling us what's wrong. And now let's click Run. And just watch it in action here. So it's running Copy Features and then it's adding the river fields and default river value. And then that's adding Correct Side Value and now it's doing Make Feature Layer and everything after it. So it did run all of it, we can see it by the shadows here. And it didn't highlight it in red and I'm not totally sure why but the dialogue box showed us exactly what was running when. And we are able to see that it ran all of this before it then proceeded. Okay, so now we have the bulk of our setup done. We've done kind of our basic infrastructure setup. We've added a couple fields and set the default values. And then we figured out which parcels have rivers in them. Now we can continue on with our analysis. So I have a sort of problem here, in that I've already added the is_river field. And so I want to now dissolve the parcels layer based upon the is_river field, but I have a selection active on the is_river field for the rivers layer. And I personally don't know how to create a new selection or clear the selection actually. I don't know how to clear the selection in ModelBuilder, but I do know how to switch it to something that we can use. So, I'm going to copy Select Layer By Location, just so I can use it here again. And then I'm going to actually make the inputs here, as both the input and the selecting layer. Because what I'm going to do means that the inputs don't really matter except the input feature layer. And I'm going to select SWITCH_SELECTION and I suspect we could probably do something like this with the feature layer and the selecting features being the same. And calling it new selection or something like that and we might get what we want. But we're going to switch selection, so now all of the non-river polygons will be selected. And that's really what we want, we want to only dissolve those anyway. So we're going to get what we really want out of this. So I'll click OK. And what it will do is it's going to select the parcels that intersect with the river. Calculate the value for those parcels to be 1. And then it's going to select all the non-river parcels now, which we can then use in our dissolve step. So let's go find our dissolve tool here. And it's under Generalization and Dissolve. And before we do, let's call this Switch Selection to Non-River Parcels, just to continue our documentation here. And we'll rename this to. Non-River Parcels here. And then we can feed that into Dissolve as input features. And what we still need to select with Dissolve is the field that's going to dissolve on. And what we want to dissolve in this case is is_river. Notice that is_on_correct_side_of_river shows up. It knows that that's created first and that it will be on this feature class so that's really handy. We could use that here if we needed to and we will coming up. So is_river is what we're dissolving on, where we want distinct polygons for each part of is_river. And then what we really don't want is we don't want to create multi-part features, right? Because what I'm trying to get is separate polygons on each side of the river. So if it created multi-part features for all of the values that were 0, I'd get one big polygon for both sides of the river. Instead I want one big polygon on the left side of the river and one big polygon on the right side of the river, that are separate polygons. So I'm going to uncheck that, you click OK. So the output of this will give us each of those polygons. But we still don't know which one's correct yet. So we need another Select By Location. So I'm going to, once again, take this Select By Location, and copy it and move it out here. And let's rearrange all this stuff. And we'll take this one over to here again. And what we really want is this dissolved layer here is going to be what we want to make a selection on. And then we're going to select with some data we don't have on the canvas, the town boundary. So let's add town boundary to the canvas and make it the selecting features, because what we're going to do is select the dissolve polygon that intersects with the town boundary. But, remember I need to make this a feature layer before I do because it writes out the dissolve polygons to the hard drive. And I might want to necessarily make this name difference, again that it doesn't collide with some other name, but for now we can leave it as is. In fact, the validate button will warn us if we have multiple things writing out to the same name. And I need to make a feature layer. So let's copy this over here. And move it here. And we'll make this the input here as the input features. And remove this other redundant precondition because that was just because I copied it. And now, once I have the feature layer, I can feed this feature layer in as the input layer. So, the town boundary is the selecting features which doesn't have to be a feature layer necessarily, that could be a feature cause but the layer to make the selection on has to be a feature layer. So, let's name these. So, let's rename this to Select Correct Side and we'll rename this Correct Side Polygon because that's what we selected. And once again, we can auto layout and see a little bit of how ModelBuilder's choosing to arrange our layout here. And before we proceed, let's again step through our model and see everything in action. We've already seen this first part up to here, but let's do what we did before where we looked at the model in action, each step, so that we really understand what's going on. And so let's validate it to clear out everything. And it's telling me I have duplicate data set name for a variable. So, the validate button helped because it reminded that when I copied that Make Feature Layer, I didn't change the name here. It says parcel_layers still. And in fact, it is not the parcels_layer. This is the dissolved_polygon_layer. And I should rename this to result two. So the validation button can help us prevent ourselves from making mistakes. So, let's validate again. We're clear. And I'm going to select all of the stuff that we all ready went through. And we understand what the adding Correct Sides stuff does because we watched this in action, too. So we're going to go through all that Calculate Default River Value as just one big run step here. And so we'll watch it in action. Great! Okay, so that's all done up to here and if we right-click on the Parcels Layer. So since it already have Add To Display checked it, it didn't do it. It unchecked it. But then when I click Add To DIsplay again, it shows up. So we still have the river's polygon selected here. So now let's run the switch selection. And it's a quick operation. And if I just zoom out or do something to change this by like hitting F5, I can see that it did change it and in fact these polygons in the middle here are not selected. So we're doing quite well. And now, let's run our next step, the dissolve of those selected polygons. So, that's running. And, we don't see anything because we didn't have Add To Display check. So, I'm going to click Add To Display, and I get two polygons here. So, let's turn off Parcels Layer. So, the selection goes away. And we can see that we get some separate polygons here. And if I open the attribute table, I have two polygons. So I have the one on the left side, And the one on the right side. So we're making progress here. And let's deselect so we leave everything the way it was and don't mess with our model. And expand our model back up. And then we'll run the Make Feature Layer again, quick and easy, and then we'll run the Select Correct Side here, since that used the town boundary to select which polygon was on the right side. And we don't see it because we added the dissolve feature class, not the dissolve feature layer. So let's add this to our display. And in fact, we can see that it has a selection active on the correct side of the river. So our algorithm works. We just proved that the algorithm to find the right side of the river does work. But we still need to use this selected polygon to mark the parcels on this side of the river as being on the correct side. So think about how we might do that still. And we'll save that for the next video. So in this video, we added in quite a few steps in terms of actually finding the right side of the river. So we dissolved the parcels after we marked which ones were on which side of the river. And then we found which one is on the right side of the river by selecting by location with the town boundary and the dissolved polygons here. In the process, we also added this stuff in the beginning where we made our model branch. But still controlled the flow so that it didn't proceed to Make Feature Layer until after all of this had been attached. In the next video, we will finish our model off by selecting the correct parcels using this new polygon here and then calculating the field again. See you next time.