Converting a String Field to a Numerical Field in QGIS

Numerical data saved as a string in a PostGIS table column needs to be converted to a numerical data type to be properly analyzed. Below is a process by which to convert string data to real numbers in QGIS.

  1. Open the layer with the improper string column in QGIS, and toggle editing mode by selecting the icon in the editing toolbar.

 

  1. Display the attribute table for the layer of interest and pick the ‘Field Calculator’ from the toolbar. This will be used to create the new numerical field and copy the values from the ‘name’ field.

 

  1. In the field calculator, ensure that the ‘Create a new field’ option is checked, and define an output field name (GAS_PPMM, in this case). Select the ‘Decimal Number (real)’ option under ‘Output field type’ to create a single precision, floating-point data field.

  1. To calculate the values for the new field, an expression must be entered in the indicated box in the field calculator. Since the values are simply being copied to the new field in this case, the expression “name” will make the new field equivalent to the name field, however the values will now be stored as numerical data. Select Ok to create and populate the new field.

  1. The attribute table should now contain a new field with the same values as the string field now stored as a real number, rather than a string.

Posted in Instructional Information.