Select to view content in your preferred language

Get Compass Bearing in Field Maps

552
1
07-01-2023 04:47 PM
JustinAnderson4
New Contributor

Is it possible to get the compass bearing of the device when collecting a point so that it reads as text i.e., "northwest," "north," "south," etc.? If so, can someone please so me how to make this happen?

Tags (1)
0 Kudos
1 Reply
JustinReynolds
Regular Contributor

Hello,

Here is one way to do it.

This assumes that the feature layer schema includes gnss metadata fields and that the method of geometry capture used a gnss receiver (i.e. not user defined or snapped).  You can now force users to use a gnss receiver in the map settings. This would be a form calculation on a field of interest configured for Field Maps.

 

 

function directionDesc(direction /* text */) {
  return Decode(direction, 
                'N', 'north', 
                'NNE', 'North-northeast',
                'NE', 'northeast',
                'ENE', 'East-northeast',
                'E', 'east',
                'ESE', 'East-northeast',
                'SE', 'southeast',
                'SSE', 'South-southeast',
                'S', 'south', 
                'SSW', 'South-southeast',
                'SW', 'southwest',
                'WSE', 'West-southwest',
                'W', 'west', 
                'WNW', 'West-northwest',
                'NW', 'northwest',
                'NNW', 'North-northwest',
                'Unhandled')
};
  
function degToDirection(deg /* number */, numDivisions /* number (4, 8, 16) */) {
  if (IndexOf([4, 8, 16], numDivisions) != -1) {
    var divSize = 360 / numDivisions; 
    var val = Floor((deg / divSize) + 0.5) % numDivisions + 1;

    var arr;
    var arr4 = ['N', 'E', 'S', 'W'];
    var arr8 = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
    var arr16 = ['N', 'NNE', 'NE', 'ENE', 'E','ESE', 'SE', 'SSE', 
                'S', 'SSW', 'SW', 'WSW', 'W','WNW', 'NW', 'NNW'];

    if (numDivisions == 4) {arr = arr4};
    var eight = 8 // because my browser keeps converting "8)" to an emoji! on the line below
    if (numDivisions == eight) {arr = arr8};
    if (numDivisions == 16) {arr = arr16};

    var idx = IIf(val == 0, 1, val);
    var direction = arr[idx - 1];

    Console(Concatenate(Text(deg, '000'), ': ', direction));
    // Console(Concatenate(Text(deg, '000'), ': ', directionDesc(direction)));
    // Console(Concatenate(Text(deg, '000'), ': ', directionDesc(direction), ' (', direction, ')'));

    return directionDesc(direction);
  };
  return 'The value passed to numDivisions parameter is out of bounds!  Expecting 4, 8, or 16.'
};

/* 
  This assumes that the feature layer schema includes gnss metadata fields
  and that the method of geometry capture used a gnss reciever (i.e. not user defined or snapped).
  You can now force users to use a gnss reciever in the map settings.
*/ 
if (!IsEmpty($feature.esrisnsr_azimuth)) {return degToDirection($feature.esrisnsr_azimuth, 16)};

/////////////////////////////////////////////////

// Division breaks for each division size  
Console('______ 16 Divisions ________');
degToDirection(349, 16);
degToDirection(11, 16);
degToDirection(12, 16);
degToDirection(33, 16);
degToDirection(34, 16);
degToDirection(56, 16);
degToDirection(57, 16);
degToDirection(78, 16);
degToDirection(79, 16);
degToDirection(101, 16);
degToDirection(102, 16);
degToDirection(123, 16);
degToDirection(124, 16);
degToDirection(146, 16);
degToDirection(147, 16);
degToDirection(168, 16);
degToDirection(169, 16);
degToDirection(191, 16);
degToDirection(192, 16);
degToDirection(213, 16);
degToDirection(214, 16);
degToDirection(236, 16);
degToDirection(237, 16);
degToDirection(258, 16);
degToDirection(259, 16);
degToDirection(281, 16);
degToDirection(282, 16);
degToDirection(303, 16);
degToDirection(304, 16);
degToDirection(326, 16);
degToDirection(327, 16);
degToDirection(348, 16);
degToDirection(349, 16);
degToDirection(371, 16);
degToDirection(372, 16);

Console('______ 8 Divisions ________');
degToDirection(338, 8);
degToDirection(22, 8);
degToDirection(23, 8);
degToDirection(67, 8);
degToDirection(68, 8);
degToDirection(112, 8);
degToDirection(113, 8);
degToDirection(157, 8);
degToDirection(158, 8);
degToDirection(202, 8);
degToDirection(203, 8);
degToDirection(247, 8);
degToDirection(248, 8);
degToDirection(292, 8);
degToDirection(293, 8);
degToDirection(337, 8);
degToDirection(338, 8);
degToDirection(382, 8);
degToDirection(383, 8);

Console('______ 4 Divisions ________');
degToDirection(315, 4);
degToDirection(44, 4);
degToDirection(45, 4);
degToDirection(134, 4);
degToDirection(135, 4);
degToDirection(224, 4);
degToDirection(225, 4);
degToDirection(314, 4);
degToDirection(315, 4);
degToDirection(404, 4);
degToDirection(405, 4);
-- Output --
East-northeast

______ 16 Divisions ________
349: N
011: N
012: NNE
033: NNE
034: NE
056: NE
057: ENE
078: ENE
079: E
101: E
102: ESE
123: ESE
124: SE
146: SE
147: SSE
168: SSE
169: S
191: S
192: SSW
213: SSW
214: SW
236: SW
237: WSW
258: WSW
259: W
281: W
282: WNW
303: WNW
304: NW
326: NW
327: NNW
348: NNW
349: N
371: N
372: NNE
______ 8 Divisions ________
338: N
022: N
023: NE
067: NE
068: E
112: E
113: SE
157: SE
158: S
202: S
203: SW
247: SW
248: W
292: W
293: NW
337: NW
338: N
382: N
383: NE
______ 4 Divisions ________
315: N
044: N
045: E
134: E
135: S
224: S
225: W
314: W
315: N
404: N
405: E

 

 

- Justin Reynolds, PE