Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there a way to do a random value calculation within a range in QGIS? I have been able to do this within ArcMap Field Calculator with the following code:

Dim max, min
max=20
min=5
x=(Int((max-min+1)*Rnd+min))

__esri_field_calculator_splitter__
x

Thanks

share|improve this question
    
The built in field calculator doesn't have a "Random" function. This would be relatively easy to do with Python if there's an Advanced Field Calculator plugin (or equivalent) out there somewhere. Anyone? –  GIS-Jonathan Apr 26 '12 at 13:47
    
That is my thoughts. I do the same thing in the ArcMap Field Calculator with the Advanced option. Is there any development for the Field Cal in QGIS in the next release? –  Ryan Garnett Apr 27 '12 at 13:47
    
You'd have to ask on the QGIS mailing list - lists.osgeo.org/mailman/listinfo/qgis-user –  GIS-Jonathan Apr 27 '12 at 13:57

2 Answers 2

up vote 4 down vote accepted

While QGIS doesn't appear to have this functionality, you may be able to work "around" it.

If you export your data to a SpatiaLite database you can then use the random() from SQLite in an SQL statement. I guess something like this:

update TABLE set COLUMN = ROUND((20-5+1) * random() + 5)

Any other database would do too, but that one can be treated as a local file and doesn't require installation of something seperate.

share|improve this answer

You could load the DBF into OO/Libre Office Calc and do this there. I think you need to have Base installed for Calc to be able to work with DBFs and you'd need to set the headers for columns that you create appropriately for data-type, field width, precision and so on. I quite often work on shapefile DBFs in Calc and have never had problems doing this, it's very convenient.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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