 Hello, I'm Stacy, I'm a GIS analyst with a natural capital project, and I'm glad that you've joined me to learn some techniques for working with the geospatial data that's used by the Invest Ecosystem Services Modeling Toolkit. This episode provides an introduction to working with vector layers. To get the most out of this tutorial, I highly recommend following along in your own GIS session. In this video, we will demonstrate techniques in QGIS, and we'll be working with some sample data. The webpage for this video provides a link to the sample data that we'll be using. So if you haven't already, now is a good time to pause this video, download the sample data, unzip it, and bring up a QGIS session before continuing. Most of the data that's used by Invest Models are rasters, but most models also have vector data as either required or optional input. A vector layer may contain either points, lines, or polygons. The coastal vulnerability model provides a good example of all of these. Wind and wave data is given as a point vector, the continental shelf is defined as a line vector, and habitats are defined as polygons. Here are some examples of vector layers that are used as inputs to different Invest models. The ones with an asterisk next to them, like geomorphology or watersheds, also require additional parameters for each feature, which we must define in the vectors attribute table. As usual, I recommend consulting the Invest User Guide to learn the specific requirements for whichever model you're working with. Something else to know about vectors is that there are two primary formats that they come in, Shapefile and GeoPackage. Shapefiles were developed by Esri many years ago, and they've historically been the most common way of defining vector data. Now I use Shapefiles all the time, and you'll find Shapefiles in many of our models sample datasets. However, Shapefiles have a lot of limitations, just a few of which I've listed here. First, Shapefiles are defined by at least four different separate files with different file types, and all of these files are required for the Shapefile to work properly. Shapefiles also have a file size limit of two gigabytes, and their attribute table field names are limited to ten characters. And if you work extensively with vector attribute table data, you know how frustrating that limitation can be. GeoPackages are a modern, open, platform-independent data format that is becoming widely used. They consist of only a single file, have no limit on their file size, and you can use much longer more descriptive field names, which is really nice. There are also other differences between these two formats, which you can learn about with a web search. NatCap has been increasingly supporting GeoPackages as both inputs and outputs of our models, and we encourage you to try using GeoPackages if you haven't already. Now let's look at an example of both of these formats in our GIS. Open a File Explorer window to the sample data that you downloaded for this tutorial. In the folder called Vector Basics Data, you'll see two different versions of the same data. One data set is called BuildingsOSMGeoPackage.gpkg, and this is vector data of building footprints from the OpenStreetMap project in GeoPackage format. The other four files are called BuildingsOSMShapeFile, and they are the same OpenStreetMap building data but in ShapeFile format. Now all of these files together make up a single vector layer. Let's bring both of these layers into the GIS. Drag in BuildingsOSMGeoPackage. For ShapeFiles, we can bring them into the GIS by using the file that ends in .shp. So let's drag in BuildingsOSMShapeFile.shp into the GIS. We can see that these layers contain the same polygons if we turn the layers on and off. If we right-click and open up the attribute table for each one, we can also see that they have the same field names. We can work with these fields in a similar way. Because many of us are still using ShapeFiles, we will work with ShapeFiles for the rest of this tutorial, but most of these same methods will also apply to GeoPackages. This vector layer contains polygons of building footprints that can be used as input to the Urban Flood Mitigation Model for calculating infrastructure damage to flooding. I downloaded these data from OpenStreetMap, clipped it to our study area, and projected it to the coordinate system used by some of the other sample data provided for this model. To learn more about coordinate systems, please check out our previous tutorial that covers that topic. Now that we have our basic data set to work with, let's look at the Invest User Guide to see what the requirements are for this layer. The webpage for this tutorial includes a link to the Urban Flood Risk Mitigation Model Chapter, which you can open now. Under the Data Needs section of this chapter, there is an entry for Built Infrastructure Vector. In reading this, we learned that the Vector's attribute table must contain a column called Type, with integer values referencing different infrastructure types. For example, a value of 1 might correspond to residential buildings, a value of 2 might correspond to office buildings, etc. It also says that this column is related to the Damage Loss table, where we provide values of potential damage loss for each type of infrastructure. So going back to the GIS, let's look at the Shape Files attribute table. By default, it does not contain a column called Type, so we need to create this column. To do this, first click on the pencil icon to turn on editing mode. Then click on the icon that says Open Field Calculator. If you haven't used Field Calculator before, I do recommend learning about it, since it is a very useful tool for assigning values to vector fields. And it has a lot more capability than we will use in this exercise. By default, there is a check mark next to Create a New Field. And in this case, this is what we want, since we are creating a new field called Type. In the box where it says Output Field Name, we will enter the word Type, just like it says in the user guide. And note that exact spelling is required by the model. Our building type values will be unique integers, so we can keep the default field type of whole number or integer. Now we can use the expression tab to assign a value to the type field. For a real-world project, you might need to assign different type values to different polygons, and there are a variety of ways to do this, which often begins with selecting a subset of polygons before opening the Field Calculator tool. At the top of the window, we can see an option that is grayed out that says Only Update Zero Selected Features. If we had a subset of features selected, we could check this box to only assign values to that selection. But for this simple exercise, we will assign just one type value to all of our buildings. In the expression tab, there's a white box where your calculations are typed. In this case, it's pretty simple. All we want to do is assign a value of one for all polygons. To do this, we just need to type a one in the box. This is telling the tool to create a new field called Type and assign all features a value of one for this field. Now we can click OK, and then let's look back at the table, and we can see that the column called type has been created, and all of the entries now have a value of one in that field. To save our edits, click on the Pencil tool or the Editing Mode button again. It will ask if we want to save our changes, and yes we do, so we'll say save. Now that we have the vector layer prepared, let's create the Damage Loss Table that goes along with these building polygons. Open a spreadsheet program. I'll use Excel, but you can use something else if you prefer. And first, let's go back to the User Guide to read what it has to say about the Damage Loss Table. It says that the table must contain two fields, Type and Damage. The Type field has values that correspond with the ones that we just added to the building layer, and the Damage field contains values of potential damage loss in currency per square meter. So let's add the two required columns to our table. First Type, then Damage. The Type field has values that correspond with the ones that we just added to the building layer, and the Damage field contains values of potential damage loss in currency per square meter. In our vector layer, we only assigned a single value of one to all of our building types. So under the Type column, add the value one. For the Damage Loss per square meter, let's add an arbitrary value of 100. This is telling the model that any residential buildings that get flooded will incur a cost of $100 or whatever currency you're using per square meter. These values will be used to calculate the value of avoided flooding due to natural infrastructure. And of course, in a real world project, you'd be researching this Damage value much more carefully. Let's save this table by clicking on the Save button. Where it says Save as Type, we want to select CSV, delimited. This is the format that is required by the Invest models. And then for file name, I'm going to call this DamageLoss.csv. And then click Save. The next step of this process would be to test out your building layer and this Damage table by running them through Invest. We won't do that now. You can do that for homework. The sample data that was provided for this tutorial includes a folder called UFM model data, which contains the rest of the data required by the Urban Flood mitigation model. So please try out your new data by running it on your own. Next, we'll look at some of the Invest errors related to vector layers. The building's layer that we just looked at should work fine in Invest. But what if it doesn't? What if we get an error? Listed here are several of the errors that you might encounter when running a model if Invest has problems processing the polygons in your vector layer. Now, as you can see, there are a variety of these errors and they are not particularly user friendly or self-explanatory. So when we're trying to decipher these errors, key words to look for are topology, geometry, polygon, and ring, all of which you see highlighted here. Errors like this usually indicate that there's something incorrect about the geometry of one or more of your features, usually polygons like building footprints or watersheds. If you get one of these errors or ones that are similar, you'll need to go back to the GIS and use the check validity and fix geometries tools. So let's try that now. First, let's find out which features are causing problems by using check validity. Under the vector menu, go to geometry tools and then choose the tool, check validity. For the input layer, make sure that it says buildings OSM shape file. And then we can leave the other options as default. And this will produce several temporary files with the results. So we can just click run. In the tool output window, the log already shows us that it found one error and one invalid geometry. So let's now close this window and look at the spatial results. The check validity tool produces one layer with valid features, a separate layer for invalid features, and a third output for errors. Right now, let's just look at the invalid output. Right click on the invalid output and go to zoom to layer. It zooms to one particular polygon. So now we know which one is problematic. And if we open the attribute table for invalid output and scroll to the right, we see a column called errors. And in this case, the problem is that the polygon intersects itself, which we can easily see by looking at the polygon. Now that we know the problem, we need to fix it with the fixed geometries tool. So under processing, let's bring up the toolbox. And then up here in the search window, type the word fix. And you should find a tool under vector geometry called fix geometries. Let's double click to launch this tool. For the input layer, again, we're going to select buildings OSM shape file. And then for fixed geometries, let's navigate to the folder where we want our outputs to be saved. So we'll say save to file. And I'm going to call this layer buildings OSM fixed geom.shp. You can call it something else if you prefer. And we're going to save this because late for homework, you're going to run this through in the invest model. So click save. And then click run. After you've used the fixed geometries tool, try running the model again with this repaired layer. Usually that gets rid of the invest errors. So give that a try for homework. One other error you might get related to vector layers happens when you enter the shape file or geo package into the user interface. Red X's will appear next to the layer. We can see this next to building footprints. And you'll have a red X at the run button. And when you click the X, a message will appear telling you what's wrong. And in this case, the error says the fields are missing from the layer. And the missing field is named type. If you get this error, you need to go back to the GIS and check the attribute table, adding the type field and populating it with values, like we described earlier in this tutorial. Okay, that's enough for this session. Remember to do your homework and run your new and fixed buildings layer and damage table through the urban flood mitigation tool. If you have any questions or comments about this episode, we'd love to hear from you on our community forum. There's a link to the forum in this video's webpage, where you can search for previous posts and create a new post under the category of training. I and other techies at NACAP will see your post and respond as soon as we can. Thanks for following along.