Hello All,
I'm looking to modify the 'Full Address' attribute rule for a new field I created in the Address Data Management Solutions geodatabase. The new field that was created, 'CountyID', will contain unique values and will be a concatenation of four separate fields ('GridID', 'StreetID', 'Full Address Number', 'Address Unit Number'). The 'CountyID' field has a defined length of 18 characters, deliminated by a ".". The 'Grid ID' and 'StreetID' have a length of three (3) and four (4) characters respectively. The 'Full Address Number' and 'Address Unit Number' are four characters in length each. So for example the 'CountyID' would look something like "A01.X001.0547.0000". The issue I'm having is I would like to pad zero's in the script itself for the 'CountyID' field instead of padding zeros in one of the existing fields or having to create a separate field, with padded zeros, to run this expression. I want the 'CountyID' field to update as data is inputted in real-time rather than running a Field Calculator tool every so often. I'm not sure of the viability of this task and my knowledge of code is minimal but any insight or a better approach would be greatly appreciated. Below is a screenshot of the Attribute Table and slightly modified code that currently runs for the Full Address rule in the Attribute Rule module.
Thank you
// This will calculate the CountyID for a site address point by concatenating several other field values
// Specify the fields to concatenate
var values = [$feature.GridID, $feature.StreetID, $feature.addrnum, $feature.unitid];
var combined_value = [];
// Loop through the field values and test if they are null or empty strings
// If they are not null or empty add them to an array
for (var i in values) {
var value = values[i];
if (IsEmpty(value)) continue;
combined_value[Count(combined_value)] = value
}
// Return the field values concatenated with a space between
return Concatenate(combined_value, ".");
I like to do something like this to create full labels with arcade.
var AddNum_Pre = IIF (IsEmpty($feature.AddNum_Pre),"", " " + $feature.AddNum_Pre)
var Add_Number = IIF (IsEmpty($feature.Add_Number),"", " " + $feature.Add_Number)
var AddNum_Suf = IIF (IsEmpty($feature.AddNum_Suf),"", " " + feature.AddNum_Suf)
var LSt_PreDir = IIF (IsEmpty($feature.LSt_PreDir),"", " " + $feature.LSt_PreDir)
var LSt_Name = IIF (IsEmpty($feature.LSt_Name),"", " " + $feature.LSt_Name)
var LSt_Type = IIF (IsEmpty($feature.LSt_Type),"", " " + $feature.LSt_Type)
var LSt_PosDir = IIF (IsEmpty($feature.LSt_PosDir),"", " " + $feature.LSt_PosDir)
var Building = IIF (IsEmpty($feature.Building),"", " " + $feature.LSt_PosDir)
var Floor_ = IIF (IsEmpty($feature.Floor),"", " " + $feature.Floor)
var Unit = IIF (IsEmpty($feature.Unit),"", " " + $feature.Unit)
var label = Trim(Concatenate(AddNum_Pre, Add_Number,AddNum_Suf, LSt_PreDir, LSt_Name, LSt_Type, LSt_PosDir, Building, Floor_, Unit))
return label
Thanks for your post. I was able to get some of the unique County ID's to generate based on the script you provided but still hung up on padding the Address Number and Address Unit Number with leading zeros. I know in Python you can use the .zfill() function but not sure how I would be able to do it in Arcade. I'm constructing an attribute rule that will automatically generate a unique County ID based off four (4) fields. The Address Number and Address Unit number are the two fields that would be padded with four (4) zero placeholders because they can can contain between 1 - 4 characters. If a field is <Null> then the IIF functions works great by simply replacing <Null> with '0000' but for the Address Unit Number it can be a number or letter. There is also a unique case in our dataset where there are '1/2' Address Unit Numbers. When it comes to how the '1/2' is outputted into the County ID field I would like it to spell out "HALF".
Below is a table with example data and how their current output looks based on the code I'm using now and another column with target output I'm trying to get to for the County ID. Also below is the current code I'm using to generate the County ID.
Grid ID: | County Road ID: | Address Number: | Address Unit Number: | County ID: (Current Output) | County ID: (Target Output) |
G15 | 0002 | 3341 | 1 | G15.0002.3341.1 | G15.0002.3341.0001 |
G15 | 0002 | 526 | 1/2 | G15.0002.526.1/2 | G15.0002.0526.HALF |
D12 | 0099 | 12 | <Null> | D12.009.12.0000 | D12.0099.0012.0000 |
B06 | 0007 | 5 | B | B06.0007.5.B | B06.0007.0005.000B |
var GridID = IIF (IsEmpty($feature.GridID),"", "" + $feature.GridID)
var ctyroadid = IIF (IsEmpty($feature.ctyroadid),"", "." + $feature.ctyroadid)
var addrnum = IIF (IsEmpty($feature.addrnum),"", "." + $feature.addrnum)
var unitid = IIF (IsEmpty($feature.unitid),".0000", "." + $feature.unitid)
var label = Trim(Concatenate(GridID, ctyroadid, addrnum, unitid))
return label