2

I have a string of values (over 10,000) I want to label them but I don't want to label every single one. I need to label every fifth number.

3

One solution: create a new column of type integer. Using field calculator, assign the value using the $rownumber variable.

Then, enter the following logic into the "Show label" option in rendering parameters of the label dialog:

[new column name] % 5 = 0

The % is the modulo operator - it represents the remainder of the first number after dividing by the second number. [new column name] would be the column that you created. In essence, you're telling the computer to divide the row number of each entry by 5 and test if the remainder is 0. If it is, then the feature gets labeled.

  • +1 but you should go further with the CASE WHEN syntax for direct labelling – radouxju Feb 10 '15 at 19:54
  • Also note that you would want to update your new column anytime you add or delete a feature. – spencerrecneps Feb 10 '15 at 19:58
  • the new column is not necessary, the conditional labelling using modulo could be applied on the fly – radouxju Feb 10 '15 at 20:06
  • @radouxju Which version of QGIS are you using? I tested in 2.6.1 and the $rownum parameter returned 0 in the labeling engine, which is why I recommended the new column. Haven't researched whether that's a known issue or not. Would be curious to hear if you fail to replicate my issue. – spencerrecneps Feb 10 '15 at 20:12
  • I've only tested on 2.0.1., and indeed $rownum also returns 0. But $rownum is the total number of records, not the id of the current record. So you don't need it in this case. – radouxju Feb 12 '15 at 19:55
1

Using QGIS 2.0.1, you can use an expression directly in the labelling tab in order to get what you need :

CASE WHEN      $id%5    =0 THEN    "yourfield"    END

in other words, if your id value ($id is built in) is divided by 5, then label with the value in "yourfield"

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.