1

I am tasked with sorting Zoning codes numbering over 100 to just 5 (Residential, Office, Commercial, Industrial and Misc).

For whatever reason I cannot get Arcade to recognize a text attribute other than the first two statements.

ArcGIS Pro Calculate Field in Arcade with If Else Statement

I've tried the following with no success:

if ($feature.ZONE == "C-1"){     
    $feature.ZONE1; 'Commercial'}
else $feature.ZONE1; 'Miscellaneous'

I want any Field containing a value "C-" or "CB-" to be Commercial, "I-" to be Industrial, "R-" residential and "Misc" everything else.

var zone = $feature.ZONE;

if (find('C-', zone,0)>0) {

return 'Commercial'
};

if (find('O-', zone,0)>0) {
return 'Office'

};
if (find(['R-',"X-","SH","SR"], zone,0)>0) {
return 'Residential'

};
else {
return 'Misc'
};

Am I just using the wrong processing tool?

0

3 Answers 3

1

I found a way for sorting the Zoning codes. It seemed like a very tedious way of doing the script, but it worked. I was hoping for a way of combining variables to one line.

    var zone = $feature.ZONE;

    if (zone == 'C-1') {
    return 'Commercial'
    }
    else if (zone == 'C-2') {
    return 'Commercial'
    }
    else if (zone == 'C-3') {
    return 'Commercial'
    }
    else if (zone == 'CB-1') {
    return 'Commercial'
    }

    else {
    return 'Misc'
    }  
1

Almost all languages, if not all, have a construct for handling these types of situations better than large else-if statements. For Arcade, it is the When statement:

When

When(expression1, result1, [expression2, result2, ..., expressionN, resultN]?, defaultValue) -> Any

Evaluates a series of conditional expressions until one evaluates to true.

Since Arcade is a young-ish language, it continues to evolve with new releases happening every few months on average. I point that out because it is really important to state what version of ArcGIS and Arcade software is being used since code written with newer functions won't run on older versions.

// Using original Arcade functions
var zone_codes = [
    "C-3", "C-1", "C-2", "R-3", "0-3", "C-2", "CB-1", "I-1"
];

var zone_groups = [];
for(var i in zone_codes) {
    var z = Split(zone_codes[i], "-", -1)[0];
    zone_groups[i] = When(
        IndexOf(["C", "CB"], z) > -1, "Commercial",
        IndexOf(["I"], z) > -1, "Industrial",
        IndexOf(["R"], z) > -1, "Residential",
        "Miscellaneous"
    );
    z = "";
};
return zone_groups;


// Using newer Arcade (1.12+) functions
var zone_codes = [
    "C-3", "C-1", "C-2", "R-3", "0-3", "C-2", "CB-1", "I-1"
];
var zone_groups = [];

for(var i in zone_codes) {
    var z = Split(zone_codes[i], "-", -1)[0];
    Push(zone_groups, When(
        Includes(["C", "CB"], z), "Commercial",
        Includes(["I"], z), "Industrial",
        Includes(["R"], z), "Residential",
        "Miscellaneous"
    ));
    z = "";
};
return zone_groups;

Returns ["Commercial","Commercial","Commercial","Residential","Miscellaneous","Commercial","Commercial","Industrial"]

0

Old post... But in my small test the logical OR operator || works. https://developers.arcgis.com/arcade/guide/logic/#operators

var line = $feature.FeatureCategory

if (line == "Shrub" || line == "Timber Shrub") {
return "Shrub"}
else {
return "Timber"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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