I'm trying to extract attribute data from a layer in QGIS (version 2.18.2 for mac) to use it internally on my plugin (I need that due to complex matrix operations with numpy and scipy), but QGIS is always returning rounded values with different methods, e.g.:
Original data when viewing it from open attribute table option:
[3.46000000, 0.48000000, 12.86999999, 13.30000000, ...]
Using getValues()
or getDoubleValues()
functions:
layer = iface.activeLayer()
print layer.getValues('G2')[0] #G2 is the field name
>>> [3.46, 0.48, 12.87, 13.3, ...]
Using getFeatures()
function:
field = [f['G2'] for f in layer.getFeatures()]
print field
>>> [3.46, 0.48, 12.87, 13.3, ...]
And using dataProvider()
function:
dpro = layer.dataProvider()
feat = [f['G2'] for f in dpro.getFeatures()]
print feat
>>> [3.46, 0.48, 12.87, 13.3, ...]
At the first moment I thought it could be a display limitation from console's output (I was testing there before implementing on the plugin), but running from the plugin I had the same result.
Is there a method where I can extract the data with all the decimals?
Type: double; Type name: Real; Length: 23; Precision: 15; WMS and WFS flagged
3.46000000
but some lines has31.53999999
. Looks like it's trying to guess the data type from a sample and applying it to the rest of the lines. I thought could be a data problem but it should return the field length as it is.