I have an output from ST-DBSCAN with the attribute "CLUSTER_SIZE". I'd like to extract only attributes belonging to clusters of size >= 10. If this condition cannot be met, then extract attributes with clusters of size >= 7. If this condition cannot be met, NULL can be returned.
I am working with the following code:
CASE
WHEN "CLUSTER_SIZE" >= 10 THEN TRUE
WHEN "CLUSTER_SIZE" >= 7 THEN TRUE
END
Since layers with CLUSTER_SIZE >= 10 will always also have CLUSTER_SIZE >= 7, the algorithm needs to stop if the first condition is already met. According to QGIS documentation for CASE, this code would provide exactly that:
CASE is used to evaluate a series of conditions and return a result for the first condition met. The conditions are evaluated sequentially, and if a condition is true, the evaluation stops, and the corresponding result is returned.
Yet outputs for layers with CLUSTER_SIZE >= 10 are instead filtered by CLUSTER_SIZE >= 7. It seems CASE is not stopping at the first condition.
I have also tried:
CASE
WHEN "CLUSTER_SIZE" >= 10 THEN TRUE
ELSE "CLUSTER_SIZE" >= 7
END
and
if("CLUSTER_SIZE" >= 10, TRUE, if( "CLUSTER_SIZE" >= 7, TRUE, FALSE))
But the problem persists. How can I write a conditional code for QGIS' "Extract by Expression" tool that returns if the first condition is met and continues only if it's not?
For clarification, the outputs I need are:
- Layers only with clusters >= 10 if they have clusters of at least this size
- Layers only with clusters >= 7 if they do not have any clusters bigger than 10
I am basically loosening my filter in case I have layers with clusters smaller than 10, but this is to be done as an exception only.