[MUSIC] Hello everyone, and welcome back. In this lesson we're going to go through how to use the field calculator in ArcGIS. This is something that you've used a little bit in previous lectures and in your assignments. But we haven't gone into much detail about what it does, and how it works. So to start with I have some parcel data here, and in the attribute table I have a number of metrics that have been extracted to these parcels. Distance to the flood plain, various elevation metrics, slope metrics, that kind of thing. And let's say that knowing that these units are in meters that for whatever reason I needed the mean elevation of each parcel in feet instead, so that's something I can easily use field calculator to do. Before I do that though, I noticed when I brought up the data that all these addresses are capitalized, and I find them really hard to read so I want to correct them. I want to make these much more of the format that we're used to seeing addresses in. Where the first letter of each word might be capitalized but the rest of it is not capitalized. So I can use a field calculator to edit a field in place using the it's own information. So if I right click on the header of this field and go to field calculator. I get the field calculator dialogue. And you might get a warning before the box comes up that you're doing it outside of an edit session. That's okay, you can proceed through that if you want. Just know that that means you can't undo what we're going to do right now. So, if we make a mistake there's no undoing it. You're going to learn about edit sessions in lesson four in this class and you could use that to allow you to undo this work. And I'm going to switch it to the Python mode. because by default it uses an older parser. Also, just do Python mode and I'm going to switch the type on the right to string because we're working with string or text information. Remember that, and in the box here where it says site address equals, I need to put in the new value for each field. because what field calculator does is it goes through each record in the attribute table, and evaluates the expression we write, similar, but different to our select by attributes type expressions. But it evaluates each expression we write and populates the field with the result of that expression, so if I want to just keep everything the same, I could do site address equals site address if I double click on that. Now, when I'm in the Python mode, it surrounds them with exclamation points as field delimators, saying this is a value from the attribute table. So if I just clicked okay on this right now and ran it, it's going to come up exactly the same, but it's a valid expression. So let's go back into field calculator and to make it lower case as I was saying before, if I want to have each record evaluated where it says okay. For this first record, give me the value of the field side address, okay. So value of the field site address equals this as of right now, it would just place that value in the box. But if I want to make it title case, I can switch this to string to type. And then go to the bottom here. And then at the end here I'll click Title, double-click it to add it to the box, and what this is going to do is it says okay, take the value of the string in the site address field for the current record and run the title method on it, which changes it to title case where the first letter is upper-cased. It replaces the value in field site address. Since site address equals, we're assigning this to this it replaces the value in that field for this record with what we're putting here the title case version of site address and then it moves onto the next record and starts all over again. So, if I click OK now. It runs and we can see that I got the title case representation of the address in this field, and that it ran on every record, and that each record is the same as it was before, except it's title case now. Okay, so now let's go back and do what we initially meant to do which is change the mean elevation to feet. Now this one I'm not going to do in place because I want to keep the original meters version of the mean elevation. But I want to add a new field that has the mean elevation in feet. So I'm going to go to the add field box, and I'm going to add mean elevation feet, as the field name. And you should be getting pretty familiar with this Add Field box now. And think for a second about what type of data this is. And I can safely do a float because it has a decimal. But I don't need massively huge number storage here. So I'm going to do a floating point number here. And I'll keep the rest of this at its defaults. And then click okay. And what I get is a field at the end of my data table with all null values now. So, I'm going to right-click on that field and go to Field Calculator now. And delete my previous expression here, that we got from the title case. And in the box, I don't have to use the same field, because remember, I'm assigning whatever I put in here. The result of whatever expression is in here, to the record in the field, mean elevation feet now. So I could put mean elevation here and it would put the mean elevation in meters in that box, but that's not what we want. So we're going to do the conversion to mean elevation in feet. So I'll put in the times operator the asterisk. And I can use a space or not a space. But the space helps make it a little more visible. And the conversion from meters to feet is to multiply by about 3.28. It's a little longer than that if we wanted it really precise. But this is close enough for this demonstration. Basically, I'm converting this number from one unit to another in this case. And this would end up with the value in feet and it's going to take this value and assign it into this field for every record in the data set. And just to be very explicit, what's going to happen is as we go to this first row it's going to grab the mean elevation for this first row, multiply it in this expression and apply it to this first row. We get to the second row and it's going to take the mean elevation in the second row and multiply it in this expression and take that result and apply it to the new field in the second row. It's going to go to the third row and do the same thing. So whenever we're pulling values from these fields, it's only in the context of whatever row is currently being evaluated. So all those fields they're going to come from the same row no matter what. You don't have to do any extra work to make sure you're pulling from the exact same row. Think of it as one row operation that we happen to kind of loop through and do a bunch of times in a row. But there's always only one row at a time. And if I run it now by clicking okay. We'll get the result, and we can see that it looks like, yeah, that's correct. 432 is about 131 times three point some odd. So it passes the sniff test of we got the values we expected. So we've added the field we intended to and now I want to right click and I want to just show you one more thing, we're not going to go into it in depth but going back to the field calculator I want to click show code block and for those of you who know any Python programming, what this allows us to do is write functions, and functions are blocks of code that take inputs, do some operation, and provide a more complex output, so that that title option that we used before, that's a function, and what it does internally doesn't really matter except that when we put data into it what comes out is what we put in title case. We can do more complicated things than that though. And if you show this code block you can write functions here that do some work. And they're going to take a parameter. Just make sure you help them take a parameter. And then write your function code. And then down here I call my function with maybe some parameter value or something like that. Maybe I want to provide some field in as this value here. This for those of you who don't know Python, this is not a complete example, this won't work here. But I just want to make the point that you can write much more complicated expressions than just putting stuff in a box down here. As you go on in using GIS, this will become a much more useful tool in your toolbox, because working with Python expands the type of analysis and the type of attributes you can generate with the field calculator. So I'm going to cancel out of this because I don't want to run this because it's broken code. And that's it for this lecture. In this lecture I showed you how to use the field calculator to modify a field in place and to generate new values from a field based upon existing values in a field. I also showed you that there's potential future learning opportunity for you that we don't have time for in this class to learn Python and expand that capability in the field calculator. Okay, I hope that helps, see you next time.