2

I have two layers. One with polygons of areas of a city. Another one - with points corresponding to buildings. In point layer there is a field with the names of management companies of that buildings. I need to calculate the percentage of management companies (unique strings) in each area (polygon).

I tried to use Join attributes by location (summary) and v.vect.stats, but both wants my attributes to be numerical, not strings. Any suggestions?

enter image description here

7
  • 1
    Intersect the areas and buildings to get them in one attribute table, then use Field Calculator
    – BERA
    Nov 22, 2021 at 6:15
  • Another idea is to: [1] Join points to polygons and then us the [2] Group Stats plugin
    – Taras
    Nov 22, 2021 at 6:19
  • 1
    IMHO usage of a Virtual layer can be useful, you can find some inspiration in this thread: gis.stackexchange.com/questions/305165/…
    – Taras
    Nov 22, 2021 at 6:26
  • Is there a field (in point layer) indicating what point is in which polygon? Nov 22, 2021 at 8:58
  • @BERA, I can intersect that layers, but I have no idea how to get percentage for companies inside areas with Filed Calculator. Gonna try to google some examples of grouping by value of the field.
    – Burtsev
    Nov 22, 2021 at 11:33

1 Answer 1

2

You can calculate the number of points with the same management company within each of the polygons using this expression with the aggregate function count, where company is the field containing the management company and polygon is the name of your polygon layer:

count ($id, group_by:= company || array_first(overlay_within('polygon', $id)))

It calculates the number of features, grouped by a string concatenated from the company's name and the id of the polygon it lies within. Simply leave away the company || part to get the whole number of points per polygon and thus calculate the percentage using this expression:

count (
    $id, 
    group_by:= company || array_first (overlay_within('polygon', $id))
) /
count (
    $id, 
    group_by:= array_first(overlay_within('polygon', $id))
) *100
4
  • when I'm trying to create new field for point layer with the first of expressions you suggested QGIS hangs...
    – Burtsev
    Nov 22, 2021 at 11:42
  • Depending on the number of features, it can indeed take a while. Maybe creating a spatial index can improve speed. To improve efficiency, you could limit the calculation to just one feaure per company per polygon - now, the same calculation is repeated for each feature, even if it is part of the same group (same company in same polygon).
    – Babel
    Nov 22, 2021 at 11:47
  • sorry don't know how to set such a limit. I have about 8700 points. By the way, preview of this expression is working and showing values for different companies...
    – Burtsev
    Nov 22, 2021 at 12:00
  • Finally it works for the part of my data. After deleting duplicates I'm getting a point layer with percentage for each company.
    – Burtsev
    Nov 22, 2021 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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