0

I am using ArcGIS Pro 2.6.

I have a line feature class, in the attributes of which there is a field "Type", and "Thickness", I need to make a complex Symbology that unites these 2 fields.

It would seem an easy task, but the lines are constantly updated and the values in the "Thickness" field as well. I need to make sure that the "Thickness" field is graded, such as from 0 - 2, 2.5-4, etc. and at the same time it was merged with the "Type" field as in the picture

Script:

var w = $feature.Thickness
var width_str

// Here we define the width classification ranges
if(w < 0.8){
    width_str = ' up to 0.8'
} else if (w < 2) {
    width_str = ' between 0.8 and 2'}
} else if (w = Null) {
    width_str = ' '}

return $feature.Type + width_str

I have error:

General parsing error

What causes that?

0

1 Answer 1

0

Beyond the parsing error, there is a larger issue with the handling of null values. Arcade, similar to JavaScript and some other languages, will cast null to 0 when casting to numeric for use with comparison operators. Under the current logic of the code, a null value will result in the first conditional check as being true, and hence null will get a label of ' up to 0.8' instead of an empty string.

Before getting into ways of addressing null values, I want to point out that many languages have specific functions for evaluating series of conditional expressions so that long if/else statements are not needed. In the case of Arcade the function is When | ArcGIS Arcade | ArcGIS Developers, and I will rewrite the code using it.

Getting back to null values, there are at least a couple different ways to handle them. One approach is to use Default Value | ArcGIS Arcade | ArcGIS Developers to check for null (or empty string) and set it to infinity, which will allow the current code logic to work.

var w = DefaultValue($feature.Thickness, Infinity);
var width_str;

// Here we define the width classification ranges
When(
    w < 0.8, width_str = ' up to 0.8',
    w < 2, width_str = ' between 0.8 and 2',
    ' '
);

return $feature.Type + width_str;

Another approach is to put the IsEmpty | ArcGIS Arcade | ArcGIS Developers check first to handle null.

var w = $feature.Thickness;
var width_str;

// Here we define the width classification ranges
When(
    IsEmpty(w), ' ',
    w < 0.8, width_str = ' up to 0.8',
    w < 2, width_str = ' between 0.8 and 2',
    ' '
);

return $feature.Type + width_str

Your Answer

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

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