4

In QGIS I'm trying to label the neighbouring features of a certain polygon but not getting much success. All the features are inside the same layer named MG_Municipios_2020. I'm using the Rule-Based Labeling with this expression to verify which geometries intersects with the one I want so that I can lable them:

intersects (
      $geometry, geometry (
             get_feature(
                 'MG_Municipios_2020', 'MN_MUN','Coronel Fabriciano' 
             )
      )
)

enter image description here

Can somebody help me to understand why is it not working?

6
  • 1
    what do u show ? the condition u're using or the content of your label ?
    – Snaileater
    Apr 7, 2021 at 17:32
  • I'm sorry, I don't think I get what you mean. But what I'm trying to do is label - with the field NM_NUM - the features that are neighbouring the orange polygon in the image, which has the value "Coronel Fabriciano" in the field NM_NUM.
    – Felippe M.
    Apr 7, 2021 at 17:38
  • 2
    what u're showing so far is "a condition" and probably not the content you're using for your labels ... your expression so far returns true ou false and could be used to select which features will be labeled ... (ok you're labeling with NM_NUM ... so ... are u using a conditionnal labeling with that expression being the condition ?)
    – Snaileater
    Apr 7, 2021 at 17:46
  • Yes, I'm using a conditional labelling with the expression being the condition. I don't have much knolegde about it but I gessed that the filter in the Rule-Based Labelling worked as a IF. So if the result is true (the first feature intersects with the second one) than it would label, otherwise it wouldn't. Isn't it right?
    – Felippe M.
    Apr 7, 2021 at 17:56
  • yeah you can use ruled based labeling or use single labels labeling with the label containing the condition itself (as indicated in my answer) ...
    – Snaileater
    Apr 7, 2021 at 17:59

1 Answer 1

3

I think you should try something like :

CASE WHEN intersects (
      $geometry, geometry (
             get_feature(
                 'MG_Municipios_2020', 'MN_MUN','Coronel Fabriciano' 
             )
      )
) THEN "NM_NUM" END

I mean ... the whole expression being your label content ...

2
  • 1
    It didn't work, neither in the single labels nor rule based. I'll send the files so you can verify if I did something wrong or what if you have the time: drive.google.com/file/d/1ArERc07Au2qSlI021p4Xlq-h8P10HWD_/…
    – Felippe M.
    Apr 7, 2021 at 18:08
  • 2
    In the expression you used 'MN_MUN' but in your table the field name is 'NM_MUM' ... if you simplify your expression you can see that the getfeature is returning NULL ... that explains why the rest of the expression won't work ...
    – Snaileater
    Apr 7, 2021 at 18:30

Your Answer

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

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