2

This question already has an answer here:

My problem is to get the sum of the area of all buildings inside a block.

There are a layer with the buildings (they contain an block_id to which block they belong and the area) and a layer with all blocks (they have a block_id). I want to sum the areas of all buildings with the same block_id and store this sum in a new column in the block-layer to the block with this block_id. I add an picture to clarify my question and structure of data. There are two blocks. The left on has the block_id = '078060' and the right one block_id = '078070'. Now all my buildings in the left polygon have an attritbute also called block_id with the value '078060'. I want then to sum up all the areas of the buildings in the block and store this value to my block layer.

I thought about calculation this with the field calculator in QGIS. But I don't know how.

The question "Summing up the area on a polygon by a certain attribute result" is just a first step to solve my problem, because the calculated sum for the categories (block_id) should be added to a new column in the blocks_layer. I was looking for a possibility to automatically calculate the sum and store it to a new column.

enter image description here

marked as duplicate by TomazicM, whyzar, HDunn, LaughU, Dan C Jul 29 at 14:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    look at this gis.stackexchange.com/q/239623/49538 – Fran Raga Jul 26 at 8:29
  • @beajifu To clarify, you have 2 shapefiles (polygons), one of the physical buildings and another intangible layer which encompasses some of these buildings. Each shapefile has a block id so you might have 5 buildings in block 1 and 6 buildings in block 2? – James B Jul 26 at 8:39
  • The attribute table of first layer 'buildings' looks like (id | street | area | block_id | geom) and the 'blocks'-layer looks like (block_id | geom ) . The block_id of the buildings layer is connected to a block with this block_id. I could have a block with block_id = 123 and two buildings with ( 1 | street a | 100m² | 123) and (2 | street b | 200 m² | 123) . Now I want to sum the areas of these two buildings (100m²+200m²=300m²) and store this sum to the block with the id 123. I hope I could clarify what I want to do. – beajifu Jul 26 at 8:46
  • maybe screenshots would help ... – snaileater Jul 26 at 9:15
2

Use Statistics by categories tool in the Processing Toolbox in conjunction with joins.

I have created a test dataset with some polygons with block_id and area field (categorized visualization based on block_id) as well as blocks with an id:

enter image description here

Attribute table looks like this:

enter image description here

Select Statistics by categories tool in the Processing Toolbox:

enter image description here

Select the field you would like to calculate your statistics on (in your case area) and the field containing the category (here the block_id)

enter image description here

What you get is a table with a broad variety of statistical parameters (called "Statistic by category"):

enter image description here

You can now join this table to your block based on the block_id. Right click your blocks and under properties selct Joins. Click the enter image description here and fill out the form as shown below:

enter image description here

If you open your blocks attribute table, you will notice a field called sum_sum containing the values just calculated above:

enter image description here

  • Thank you very much. This works pretty well. QGIS is so powerful but sometimes it's hard to find a way to solve a problem. – beajifu Jul 26 at 9:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.