2

I am working on some spatial data in QGIS(2.14.6). The dataset i am working on has a column house-number which is for addresses and it is numerical. In some cases the address is a number range ie 2-6 because the development is on 3 plots 2,4 and 6. Also note numbering is such that odd numbers are on one side and even numbers are placed on the other. Does anyone have an idea of how to set up a numerical column in QGIS such that it can take a number range. I have tried the option of using a text/string column type but i dont see how i would be able to perform numerical operations such as greater or less than. Below is an image showing an example of the plot layouts and some plots that has house numbers that is a range ie 1:5, 2:6, 14:16

enter image description here

1

You can use the @row_number in the Field Calculator for updating a column with a range. @row_number * 2 will write 2, 4, 6, .. The Field Calculator also gives you the option to only update the selected feature.

enter image description here

If you want a user to be ranged help during input and edit, you can add a Range widget ind the Properties of the layer > Fields tab.

enter image description here

UPDATE

You can use a small script for converting your range to real numbers. It can be use as a label and goes:

Add a function in the Function Editor of the Expression dialog.

enter image description here

from qgis.core import *
from qgis.gui import *

@qgsfunction(args=0, group='Custom')
def houseno_range(value, feature, parent):
    houseno = feature['houseno']
    if ':' in houseno:
        colonpos = houseno.find(':')
        lowrange = int(houseno[0:colonpos])
        highrange = int(houseno[colonpos+1:len(houseno)])
        labelstr = str(range(lowrange, highrange+1, 2)).replace('[','')
        return labelstr.replace(']','')
    else:
        return houseno

Where feature['houseno'] needs houseno to be your housenumber columnname. Then use the function as a label

enter image description here

Test on label with houseno

enter image description here

Test on label with function houseno_range()

enter image description here

  • Hi Jakob, i have added an image to illustrate what i am trying to do. I actually want to add a number range as house-number in the attributes of some particular features. – mapperx Mar 14 '17 at 8:42
  • In building 1:5 you want the numbers 1, 3, 5? The building is one geometry / feature / record. How do you want to store the three house numbers if it is just one record? – Jakob Mar 14 '17 at 10:14
  • @mapperx, you can also rewrite the label expression replacing 1:5 to 1, 3, 5. Updated the answer with this solution. – Jakob Mar 21 '17 at 11:51
  • i will try out your suggestions seems and will let you know how it works out. – mapperx Mar 23 '17 at 5:51
  • I tried to follow the example you gave but it did not work. I don't know maybe i missed something. First i created a created a new column using houseno so i could use your code. Then edited it as Range widget and set it as in the image. Then copied the the code and created a function. Then just followed the instruction as you stated. But i could get it to take the range or show the label as mentioned. I will try to look for a tutorial for range widget or could you share any if you know – mapperx Mar 24 '17 at 5:08

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.