[MUSIC] Hello again and welcome back. In this lecture, we're going to continue on with that model we've been building, and I think this time, we'll finish it off. In the process, we'll learn a bit more about ModelBuilder, specifically, about intermediate and managed parameters, as well as about making things model parameters. When we left off last time, we had successfully selected the parcels on the correct side of the river, dissolved them, so that we got which side of the river was correct, and then selected which big chunk of the river was on the correct side. What we have left to do is now re-select the parcels using that big dissolve the chunk from the correct side of the river, and then update the attribute for whether or not the parcels are on the correct side of the river to be one for those selected parcels. At that point, we will have successfully met our objective with this model. So right now, we have a selection active on the correct side polygon here. And we can't really see it in the map document right now because I don't have it loaded, but imagine that we have one polygon representing this side of the river here. And we have another polygon representing this side of the river, and the polygon in this side is selected right now. So what we need to do, or at least what would be a good idea to do, is to copy this feature out to the disk. Theoretically, we should be able to use it to do our next selection since the section operation can work with an existing selection, but just to be absolutely clear and be careful, let's copy out to disk. So, let's search for Copy Features again, Copy Features. And remember, Copy Features only copies out the selected features, and so, if we have a selection active on a feature class, it's a great way to subset our features, sort of like the Export Data tool in Hardmap. Let's connect this selected polygon in here as the input features to Copy Features. And then switch tools here, and it lights up, because it has everything it needs, in part because it assumed an output location for us. And to make it be even a little better about that, let's right click on this output here, and make it managed. And we'll come back to that again in just a moment. But for now, let's rename this Correct Side on Disk. Okay, and we'll name this Copy out Correct Side Polygon. Okay, now we have this on our hard drive ready to use again let's use it as the selecting features on yet another round of Select By Location. So I could copy it from elsewhere in the canvas to reuse the tools we already have, or I can go find it again here. So Select By Location, and it's named Select Layer By Location. And let's connect that in as the selected features. And notice that it only gave me the selecting features option, not the input features, because this isn't a feature layer, right? It's on my hard drive, and only a feature layer can be used as the input features. So that's a good reminder of that, when you try to connect it as an input to Select Layer By Location. And what we're selecting is actually all the way back here. We're trying to make a selection on parcels layer now. So let's connect and as I drag off the screen here, it hands for me, so then I'll release again on Select By Location and put it as the Input Feature Layer. And now, it lights up saying it's ready to run. Connect and double click it to check everything's ready, and I do want it to be a new selection, and any existing selection on the parcel layer should be erased. And it's going to be an intersection with the correct side polygon here. Okay, and this is a little messy, so let's auto lay it out again. And I can see that line coming all the way back from parcels layer, connecting in to select layer by location. Now, I would call this here a branching section of the code or of the model, where we have to tell ModelBuilder what to run first because this kind of ends here without really doing anything else. And then we need to make this a pre-condition to say it should run before this. I wouldn't necessarily call this here a branch because really, we're just using a layer or a variable from earlier again later in our model. Not really super important, but just in terms of semantics, if you hear me talking about branching or something like that, that's what I'm talking about. Okay, and now we should have our correct parcels selected, and all we need to do is run that field calculation. So that we can update the attribute indicating whether or not those parcels are on the correct side of the river to be true or the value of 1. So, let's do Calculate Field, And drag it under the canvas, and I'll connect this parcels layer in here as the input table. And then, let's set up our field calculation here by double clicking on it and selecting our field name, which is is_on_correct_side_of_river, which is 0 right now because we created it and then filled it with 0s. And now with the selected features, we want to just select it as 1, or set those selected features to be 1. And it doesn't really matter what expression type I use, I usually make it PYTHON 9.3, but I know earlier, we left it as the default of Visual Basic. So since I'm just setting it to 0 or 1 in this case, any expression type is okay. I'll click OK here, and now it's ready to run. And let's, again, do this interactively, just like we did before, run it right here. So if I run this one here, it executes everything up to and including it. Okay, so we have this, and we can go take a look at this correct side polygon as it's selected. And we can see it there, just like we did before. And now, let's run the one that copies it out to disk. But before we do, let's make our final change, and If I right click on it, we can see that I made it manage, but it also made it an intermediate product. When we make it an intermediate product, what it does is it automatically puts it in our scratch geodatabase. And it basically understands that we don't really care about this. Even though we're writing it out to our hard drive as a Feature Class, it's not a particularly important Feature Class to us. So it can put it anywhere, and we want it to manage creating and recreating that data if we run this model multiple times. So, it's sort of designating it as a temporary file. Okay, so now, let's run it. And you just copy that out to disk, and I can add this to the display too. And it won't be super interesting, except that it's the selected polygon we had before as its own polygon, so I can turn off that dissolved polygon layer and see this, just this one polygon. And now, what we can do is select layer by location, like we did on our model. And it ran quickly again. And we need to add that parcels layer to our display. And let's turn off the previous one. So here we go. As we can see, what we wanted was to select all these parcels, and that worked. And then we can run the field calculator. We know that those are all 0 right now, for null even on the correct side of the river, and what we can do is run the calculate field. And it should update them. So if we do anything to force a refresh, like sorting it, we can cause it to reload the data and display the correct values. So we can sort it, and nulls are down here. But then all the selected records are 1. Okay, so success, right? We have a successful algorithm for finding out which parcels are on the correct side of the river, and we now have an attribute that can be read for that. We're almost done. The nice thing about feature layers is that they, even when we're working on them, they work against the underlying data. So, even though we've kind of loaded up and worked on it, we still are actually working on this underlying copy parcels layer. So if we want to make this tool reusable, we need to do a couple things. We need to make the town boundary a parameter as well, so somebody who's running this later needs to provide the rivers layer, the parcels layer, and the town boundary. But we also want them to provide where they want the output data to go. So we're going to make this a model parameter. And I'm going to save it and close it. Yes, please save it. And then we're going to run the model here by double clicking it. And it's telling me the stuff already exists, but let's just run it with what we have right now. Okay, so we'll run it as it is for now. And see what it gives us. So it did a copy features, just like it was supposed to. But notice that the output features didn't show up in our table of contents yet, because it's not done. And that it removed the previous versions of those datasets that we had created as it needed to work with them, because those were managed data. And when it was done, it gave us our output layer here. And we can go look at it and see the mix of is_on_correct_side_of_river and null values, so we just ran that as a geoprocessing tool. We still have a problem though, when I double click on it, rivers and parcels are kind of self-explanatory. But town boundary still looks a little codey, it has the town_boundary and then copy parcels layer isn't particularly clear about what it's asking. So let's go make some corrections in our model to make this more useful. Right click, go to Edit. So first thing, let's rename this to Output Parcels, or maybe even Output Data. And then let's fix town boundary so that it's, Named Old Town Location Boundary, just to be a little clearer. And if I wanted to, I can even go change what order these are in. Since I've made the model parameters in the order that we really wanted them in, it doesn't really matter that much, but if I go to Model Properties and go to the Parameters tab, I can move them up and down. So that maybe if I wanted them to provide the old town location first, I can move that up. And then when I go to OK, And save it and run the tool, that shows up at the top, and Output Data is here at the bottom. Now one final thing we probably want to do before we distribute this to somebody else or reuse it is remove these defaults because somebody else won't have them, and they're going to get these kinds of odd errors here when they try to run it. So, let's close this, and let's double click each of these and remove them. Now that we've debugged our model, even though it makes some of these not quite ready to run, it's okay because since we finished debugging it, we don't need to run it in ModelBuilder anymore. At least not right now, and so we can save it. And then let's also make our output data not defined. Click OK, and it saved one last time. And now, when I run it, it looks just like a normal geoprocessing tool. Okay, so it took a bunch of videos, but we finally did it. We finally made this model, which isn't anywhere close to the most complex model you can make, but it involved many different steps and a little bit of branching in order to get the result that we wanted from this. But we now have a reusable tool that we can use whether we need to automate it like I do, so that it can happen multiple times or whether we just want to make sure that in the future, we can come back and do the same process after we've forgotten how we did something. There are a few more things I want to show you with ModelBuilder that we didn't get a chance to explore with this model, but we'll save them for the next video. For now, you know how to take a bunch of different tools and bring them together into a unified workflow. You also know how to use some tools that we'd only used in the interface prior to now as model tools, because they are also geoprocessing tools. And then you've learned a bit about model flow with preconditions and with connecting different parts of the model together in order to get from the start to the end, including model parameters and intermediate data, all the things you need in order to put together structured automated workflows in ArcGIS. See you next time.