[GIS] How to output True/False if attribute is a number in QGIS field calculator

field-calculatorqgis

I have a points shapefile which has two fields that I want to use to determine the size of each point. One field, "StepYear", refers to the year of step change in a particular time series, and it contains both numbers (e.g. 1996), and non-numericals (such as NA or – ). The non-numericals indicate a number of different cases in which the test did not proceed.

If the test did not proceed, then I want the size of the point to be equal to 2. Otherwise, I want the size to be determined by the statistical significance of the test. I want code similar to the following:

CASE
  WHEN  NOT ISNUMBER("StepYear") THEN 1 
  WHEN  "StepSig" <= 0.01 THEN 8
  WHEN  "StepSig"  <= 0.05 THEN 6
  WHEN  "StepSig"  <= 0.1 THEN 4
  ELSE 2
END

However, I haven't been able to find any function that performs the "ISNUMBER" check. Is there a function in the QGIS field calculator which outputs TRUE/FALSE for a numerical type check?

Best Answer

Following the comment by @ahmadhanb, this is a workaround I would suggest:

CASE
WHEN  to_int(regexp_substr("StepYear", '(\\d+)')) IS NULL THEN 1 
WHEN  "StepSig" <= 0.01 THEN 8
WHEN  "StepSig" <= 0.05 THEN 6
WHEN  "StepSig" <= 0.1  THEN 4
ELSE  2
END

Above to_int() part will extract numbers from "StepYear" or return NULL. Please make sure the new field created by this expression is integer type.

Related Question