It would be an absolute bear of a calculation formula to nest all those ifs, but it's doable. I would first want to know what the intended end use of the classified "direction" attribute is, though. It might be possible to have this as an expression evaluating on the fly using Arcade, depending on where you're using the information.
But to do it in Survey123, you just need to keep track of your parenthesis. Here's part of the code broken up and formatted nicely so you can see what's going on a little easier. Basically, just write each range in its own if, then at the very end include a '' for the final "else", then a close parenthesis for each if statement.
Also, since N spans the 0-line, its statement looks different from the rest
if(${bearing} < 12) or ${bearing} >= 349, 'N',
if(${bearing} >=12 and ${bearing} < 34, 'NNE',
if(${bearing} >=34 and ${bearing} < 57, 'NE',
if(${bearing} >= 57 and ${bearing} < 79, 'ENE',
''))))
In Survey, this'll need to be all on one line, but it should work.
Alternate Approach: Concatenate Separate Ifs
It occurs to me that there is a way to cut the number of statements in half. If we were to draw out the compass, it might look like this:
If we evaluate the major cardinal directions separately, then concatenate them to an evaluation of the diagonals, we can get all 16 possible combinations with only 8 ifs. I won't type them all out, but here's a brief portion to give you an idea.
concat(
if(${bearing} <= 33 or ${bearing} >= 327, 'N',
if(${bearing} >= 57 and ${bearing} <= 123, 'E',
'')),
if(${bearing} >= 12 and ${bearing} <= 78, 'NE',
if(${bearing} >= 102 and ${bearing} <= 168, 'SE',
''))
)
In those areas where the major direction "wedge" intersects with the diagonal "wedge", you'll end up with values like "NNE" or "WSW". In areas where they do not, the empty string will be returned from one or the other if statement, and you'll get "N" or "SE".
- Josh Carlson
Kendall County GIS