 Hello welcome back on my YouTube channel. In this video we're going to calculate areas and densities. I'm going to calculate the percentage of area covered by buildings per neighborhood in Rotterdam. So I have a layer with building footprints and I have a layer with the neighborhood polygons. We're going to do the following steps. We're going to calculate first the areas of the neighborhood polygons. Then we add the neighborhood names and areas to the buildings polygons. Then we're going to dissolve the buildings that are from the same neighborhoods. Then we calculate the areas of the dissolved building footprints. And then we divide the area of dissolved building polygons by the area of the neighborhoods. Let's start with calculating the areas of the neighborhoods. Go to the attribute table. There click the field calculator icon. There we create a new field. Let's call the output field area square meter. And the output field type is a decimal number real. Then you can find under geometry the area function that is used to calculate areas of polygons. Double click to add it to the expression. Click OK. And there we have all the areas of the neighborhoods. Talk about the editing and confirm that you want to save the result. Now I would like to join the area attribute of the neighborhood polygons to the building polygon attribute table. However, these attribute tables don't have a common key field, so I need to do a spatial join instead of a normal join. So I will use the join attributes by location tool. Join features in buildings that intersect with the neighborhoods. Under fields to add, click the three dots. And we only need here bird now, which is the name of the neighborhood. We will need that later. And the area square meters. And the join type should be a one to many join. So each building gets the name of the neighborhood and the surface area that we keep the original buildings. Save the result to a jail package and call it buildings with neighborhoods. Click run. Click close after processing. Let's have a look at the attribute table and check the results. There we see that the buetnam, so the neighborhood name and the areas are added to each building polygon. The next step is to dissolve all the building polygons based on the neighborhood name, or buetnam. Go to the vector menu, choose geoprocessing tools and click on dissolve. For input layer, choose buildings with neighborhoods. For the dissolve field, choose buetnam. All the features with the same neighborhood name will then be dissolved into one feature. Save the output to the geopackage and give it the name buildings dissolved. Click run and click close after processing. Now let's visually check the result. Go to the layer styling panel and there choose categorized and there choose the attribute buetnam and then click classify. Now all the buildings that belong to the same neighborhood have the same color. So now we can calculate the area of buildings per neighborhood. So go to the field calculator and create a new field building area square meters. Use decimal number real for the output field type. There use the dollar area function again. So now all the building area polygons belonging to one neighborhood are used to calculate areas. So each feature here is all the buildings in one neighborhood and we have here the area in square meters. And in the same way we can now calculate the percentage of building area per neighborhood. So let's create a new output field called building percentage, which is also a decimal number or real. Create the expression by using the buildings area divided by the area. So buildings area is the total area of buildings per neighborhood and area is the area of the neighborhood. Let's create percentages. So I'm going to put brackets around it and multiply with 100 and there in the preview we can see that this will result in a percentage. Click okay to apply this and there we see the building percentage per neighborhood. So if I sort it I can find which neighborhood has the largest percentage of building cover. And that is this neighborhood and that is this neighborhood. You can see that it's still in editing mode. So it's nicer to toggle this off and save the edits. And that's a proven years like and probably it's the largest cover because it contains the roof of a huge station. I'll close the attribute table because it's much nicer to use the neighborhoods for visualizing the building densities. I'm going to create a join. Click right on neighborhoods and click on properties then in the layer properties go to the joints tab. Choose buildings dissolved as the join layer. And as a join field use the field that both layers have in common which is the buetnam the neighborhood name. So choose that as the join field and the target field. Then under joint fields we are not interested to join all the fields but only the building percentage. And under custom field name prefix remove what's there because we can just use the attribute name of building percentage there. Check this and then click okay. Then open the attribute table and if you scroll all the way to the right you can find there the building percentage added to the attribute table of the neighborhoods. Now let's use this attribute for styling the neighborhoods polygons. Remove the selection. Let's hide the other layers. Change single symbol to graduate it and we're going to use a ramp. Make sure to choose building percentage as the attribute and because I now still have the outlines I need to change it from simple line to simple fill and I don't like yellow there so you can make it white or black. We use white here and now we can change also the mode and the amount of classes. Let's use here natural breaks, janks, it's five classes. It gives us a bit of an overview of the different densities in Rotterdam for different neighborhoods. So to make it easier to interpret I'm going to add the labels and I use here single labels. Make sure to use as the field the buurtnam, the neighborhood name and I'm adding a space here on wrap on characters. So labels with multiple words will be split over several lines and here you see the distribution of densities in Rotterdam. We can also visualize the result in a bar graph using a data plot leak plugin. You can install the plugin from the plugins manager. In this case it's already installed. Click the data plot leak icon in the toolbar and make some space for the data plot leak panel. Choose bar plot. Make sure you choose as layer the neighborhoods and for x field buurtnam the neighborhood name and for the y field the building percentage. You can change other settings here but I'm going to keep it as default and go to the settings tab and here I just change the x label to neighborhood and change the y label to percentage of building area. Click create plot to check the result and if you enlarge the panel it will scale and now we can clearly see which neighborhoods have the highest percentages of building surfaces. So I hope this was a useful video. Please subscribe to my youtube channel if you're interested in more updates or become a member of my youtube channel to get personal support.