Select to view content in your preferred language

Attribute rule arcade statement

619
11
Jump to solution
08-27-2024 01:33 PM
EricBregant2
Occasional Contributor

Hello! I am working on an attribute rule that will concatenate 6 fields that make up a street address to create a full address. The problem is that 2 of the fields are not always populated with a value. They will either be null or empty.

In the image below, you can see my 6 fields (ST_NUM, DIRPRE, FEANME, FEATYP, DIRSUF and Unit (LV_APT)

Screenshot 2024-08-27 132256.jpg

If I do a simple concatenate of those fields, the result will leave spaces at the end of the full address. I know this is because of there not always being a value in DIRSUF or LV_APT.

I have been working on the below code, but I know I am missing some parts. Any ideas or anyone know a better way?

// List the fields to combine
var parts = [$feature.ST_NUM, $feature.DIRPRE, $feature.FEANME, $feature.FEATYP, $feature.DIRSUF, $feature.LV_APT];

// Loop through the address parts, if not null or empty add them to a new array
var filteredparts = [];
for (var i in parts) {
    var value = parts[i];
    if (IsEmpty(value)) continue;
    filteredparts[Count(filteredparts)] = value
}

// Concatenate with a space
return Concatenate(filteredparts, " ");

0 Kudos
11 Replies
MikeMillerGIS
Esri Frequent Contributor

It is best sharing code, add is as a code sample.  For arcade, I pick Javascript.  It is much easier to read, it maintains formatting, etc.  

var lv_apt = $feature.LV_APT;
if (!IsEmpty(lv_apt)){
  lv_apt = `#${lv_apt}`
}
parts = [$feature.ST_NUM, $feature.DIRPRE, $feature.FEANME, $feature.FEATYP, lv_apt];

return function not_empty(x) {
  return !IsEmpty(x);
}
return Concatenate(Filter(parts, not_empty), ' ');

 

0 Kudos
LindseyStone
Frequent Contributor

Here is how we did it, our two direction fields, unit, and addNum_suf fields may or may not be Null.

//Array to hold values and an index
var i = 0;
var features = [];

//Add value to array if not empty
function addvalue(feat) {
    if (!IsEmpty(feat)) {
        features[i++] = feat;
    }
}

//Add your values
addvalue($feature.Add_Number);
addvalue($feature.AddNum_Suf);
addvalue($feature.St_PreDir);
addvalue($feature.St_Name);
addvalue($feature.St_PosType);
addvalue($feature.St_PosDir);
addvalue($feature.Unit);

//Return a concatenated string with a space between each attribute
return Concatenate(features, " ")

 

0 Kudos