I have a building dataset and I am trying to perform a spatial analysis, to determine which building should be developed as a 3D model, for a mapping project.

Because in some areas the building density is too high, I have created a Ranking Matrix, so in the case that the buildings are too close from one another, the one with the higher rank will be chosen. And if the rank is the same, the one with the larger footprint will be preferred.

Can anyone suggest how the formula inside the Field Calculator should look like, so it would perform this analysis? I have tried many iterations and I can't seem to figure this out.

I would like the end result of this analysis to be another field, with 1 and 0, for suitable/not suitable for 3D development.


UPDATE: the features I want to compare are 100m buffers of the above mentioned buildings. So if the 100m buffers overlap, I want to compare the ranks of the two (or more) overlapping features. If the ranks are different, I want the formula to update the attribute table with '1' - for the suitable building. If the ranks are the same, I want to chose the building with the larger footprint and update that with '1', else, it should be '0'. Also, if there is no overlapping, those features should be also '1'

  • 2
    A nice question, Ovidiu. Would be nice if you can provide an image of these buildings or a small snippet of them. Moreover, it is not yet clear to me whether building are simply close to each other or they overlap, title of your question IMHO contradicts with its content
    – Taras
    Aug 31, 2021 at 5:16
  • 1
    Have you calculated when they are "too close"? Can you add a screenshot showing the attribute table?
    – BERA
    Aug 31, 2021 at 5:36
  • 1
    Yeah, we definitely need example data, along with your intended ranking.
    – Erik
    Aug 31, 2021 at 6:06
  • Apart from the other comments: Ranking meaning what exactly? You have a numerical attribute value like from 1 to N and the higher this value is, the higher it is ranked? Please edit your question to address all the suggestions made here. Otherwise, you not just risk that the question will be closed, but more importantly, it will be difficult to give any helpful advice, not to say impossible.
    – Babel
    Aug 31, 2021 at 7:03
  • There are 16 categories of buildings (188 buildings in total) that are being considered for 3D development. Because some areas have denser urban fabric, it would be visually cluttered to have them all in 3D. So I thought about having a buffer from each building and this ranking matrix that would identify for me which buildings I should develop in 3d ibb.co/KDbMb8C Aug 31, 2021 at 7:18

1 Answer 1


Create the buffer as separate layer - it should include the attribute field for rank. Then use this expression to generate the new boolean field to get a true/false value for which buildings to render in 3D (screenshot 1):

if (rank > array_max(overlay_intersects(@layer, rank)) or overlay_intersects( @layer) = false,1,0)


To include not only the distance and rank, but also the area (footprint) of the building, use this expression (you should have an attribute for the area of the building, create it with $area) - see screenshot 2:

    when overlay_intersects( @layer) = false then 1 -- no other building in the buffer-distance
    when rank > array_max(overlay_intersects(@layer, rank)) then 1 -- the buidling has the highest rank of all buidings withen the buffer-distance 
    when if (
        rank >= array_max(overlay_intersects(@layer, rank)) and 
        area > array_max (overlay_intersects( @layer, area)),1,0) then 1  -- the building has the same rank as another building inside the buffer-distance, but a larger area
    else 0  -- all other cases

Screenshot 1: Buildings in blue, labeled with their rank value. Buffers in pale yellow. Highlighted in light yellow the buildings selected with this expression using Select by expression: enter image description here

Screenshot 2: includes also a condition about the area (footprint) of builings with same rank: enter image description here

  • thanks a lot! The formula has helped me identify the buildings as intended! If you could help me tweak it a bit, it would be greatly appreciated. ibb.co/rt471nD I have the situation now where the have the same rank, but I want to keep only the one with the highest footprint. Thanks a lot for your inputs! Aug 31, 2021 at 8:04
  • Edited the question and added an expression for that.
    – Babel
    Aug 31, 2021 at 8:16
  • In the second screenshot I am seeing two instances. One in which it works ( marked up with red) and one which doesn't (marked up with blue) and I am trying to understand the formula, so I can figure why, in your case, the blue one hasn't been selected. Because it also didn't work for the for the two I shared earlier ibb.co/ngFhN7y Technically this shouldn't be selected. Aug 31, 2021 at 8:38
  • I can't see about which cases you speak, refering to my example. And regarding your data, from the screenshot alone it's difficult to say as I don't see the rank values. Can you share your data or describe more in detail where the problems are?
    – Babel
    Aug 31, 2021 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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