3

I need to filter values in an array with a certain field value

Below works quite well

array_length(
    overlay_contains(
        'UPRNs_Fibre_Status_5f6488b0_aa3b_4f7d_ae6b_025ff9024f2e',
        $id
    )
)

However, I need to filter values with the following expression

to_date("Delivery_Actual_End__c") < make_date(2022,08,22) AND "CDS Milestone View v2_In Contract"

3
  • 2
    Why don't you use: array_length(overlay_contains('UPRNs_Fibre_Status_5f6488b0_aa3b_4f7d_ae6b_025ff9024f2e', $id, filter:=to_date("Delivery_Actual_End__c" ) < make_date(2022,08,22) AND "CDS Milestone View v2_In Contract" = 'Yes'))
    – Mayo
    Aug 23, 2022 at 11:10
  • Worked well, thanks. It's really slow to calculate for over 1k polygons but I reckon that's only way to do without using processing tools.
    – foxhq
    Aug 23, 2022 at 11:40
  • Yes, this is because this expression is a kind of aggregate funtion so it evaluates each feature 1k times in total it's 1m times the function evaluate features.
    – Mayo
    Aug 23, 2022 at 11:48

1 Answer 1

2

Maybe it could be faster if you first filter features with the simpler filter, and then you filter by location. Try this:

array_length(
    array_filter(
        aggregate(
            layer:='UPRNs_Fibre_Status_5f6488b0_aa3b_4f7d_ae6b_025ff9024f2e',
            aggregate:='array_agg',
            expression:=$geometry,
            filter:=
                to_date("Delivery_Actual_End__c") < make_date(2022, 08, 22)
                AND
                "CDS Milestone View v2_In Contract" = 'Yes'
        ),
        contains(
            $geometry,
            @element
        )
    )
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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