Select to view content in your preferred language

Field Calculate taking hours to run on less than 20000 feature?

294
7
Jump to solution
a month ago
Labels (2)
Amarz
by
Frequent Contributor

Hello,

I am running an arcade script on my Building Footprint Layer that takes all the points (Addresses) within, and concatenates them into a string and puts the values into a field. (see below)

However, this particular script is taking hours to run?

Data is within the same sde, in a SQL database, working in ArcPro 3.3

 

 

 

// Retrieve the ADDRESS feature set
var address_fc = FeatureSetByName($datastore, "DBO.MasterAddress", ['Address_Full', 'AddressType'], true);

// Initialize a string to store the Address_Full values
var address_string = "";

// Loop through the addresses and check if they are within the current building polygon
for (var addr in address_fc) {
    // Check if the address is within the current building polygon and has AddressType = "Address"
    if (Within(addr, $feature) && addr.AddressType == "Address") {
        // If this is not the first address, add a comma separator
        if (address_string != "") {
            address_string += ", ";  // Add comma separator
        }
        // Concatenate the address to the address_string
        address_string += addr.Address_Full;
    }
}

// Return the collected addresses as a comma-separated string
return address_string;

 

 

 

0 Kudos
2 Solutions

Accepted Solutions
CodyPatterson
MVP Regular Contributor

Hey @Amarz 

This could be because you're filtering through all of your addresses while also making calls to the Within function, once done, it creates a new string each time, your run time for this would be O(N * M + N * K) which is quite large if speaking in asymptotic terms.

Consider this program here:

var address_fc = Intersects(FeatureSetByName($datastore, "DBO.MasterAddress", ['Address_Full', 'AddressType'], true), $feature);

var address_list = [];

for (var addr in address_fc) {
    if (addr.AddressType == "Address") {
        address_list.Push(addr.Address_Full);
    }
}

return Concatenate(address_list, ", ");

The main differences is that there's a checking of only the relevant addresses with intersects, and within may run per-iteration, something that could take forever. If I did this correctly and get the growth correctly, this is O(N + B * K), which is N number of addresses + B number of filtered intersecting addresses, finally multiplied by K concatenation.

Cody

View solution in original post

0 Kudos
KenBuja
MVP Esteemed Contributor

That line should be

Push(address_list, addr.Address_Full)

View solution in original post

7 Replies
CodyPatterson
MVP Regular Contributor

Hey @Amarz 

This could be because you're filtering through all of your addresses while also making calls to the Within function, once done, it creates a new string each time, your run time for this would be O(N * M + N * K) which is quite large if speaking in asymptotic terms.

Consider this program here:

var address_fc = Intersects(FeatureSetByName($datastore, "DBO.MasterAddress", ['Address_Full', 'AddressType'], true), $feature);

var address_list = [];

for (var addr in address_fc) {
    if (addr.AddressType == "Address") {
        address_list.Push(addr.Address_Full);
    }
}

return Concatenate(address_list, ", ");

The main differences is that there's a checking of only the relevant addresses with intersects, and within may run per-iteration, something that could take forever. If I did this correctly and get the growth correctly, this is O(N + B * K), which is N number of addresses + B number of filtered intersecting addresses, finally multiplied by K concatenation.

Cody

0 Kudos
Amarz
by
Frequent Contributor

Thank you for the explanation @CodyPatterson. The code validates, but I am getting the error 

ERROR 002717: Invalid Arcade expression, Arcade error: Integer index expected, Script line: 7

when attempting to run it. Any further help is apprecaited.

0 Kudos
KenBuja
MVP Esteemed Contributor

That line should be

Push(address_list, addr.Address_Full)
CodyPatterson
MVP Regular Contributor

Hey @KenBuja 

Great catch! Switching between too many programming languages has its quirks!

Cody

0 Kudos
MichaelVolz
Esteemed Contributor

So how long does it now take for your updated script to run?

0 Kudos
Amarz
by
Frequent Contributor

Well, not sure what happened. Ran for 1.5 hours and got the dreaded 9999 Error.. so I am attempting to run again.

The Error is due to the array exceeding the character count of the field on some buildings, so I am doing going in smaller batches and will manually edit the features or the field to reflect the correct address.

0 Kudos
Amarz
by
Frequent Contributor

Thank you @CodyPatterson & @KenBuja for the assistance! Is there a way to add something that will return a null value if the Building Footprint doesn't have an address on it? Or is that already built in?

 

0 Kudos