[GIS] How to input number range in QGIS numerical column

qgis

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

Best Answer

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

Related Question