Select to view content in your preferred language

Default COGO labeling expressions - getting COGO ERROR label

192
2
Jump to solution
02-07-2025 01:56 PM
Labels (1)
RobertChaney
Frequent Contributor

I have a parcel fabric where the COGO field values are in meters.  I'm able to modify the Default COGO label expression: var cogo_distance = $feature.Distance * 3.28084;

RobertChaney_0-1738963941666.png

Which gives me the proper label in feet.  However, for lines with values in the ArcLength field, the COGO ERROR label shows.  When I attempt to change the variable in the default COGO expression to the following:

var cogo_arclength = $feature.ArcLength * 3.28084;

I get COGO ERROR labels on all lines.

RobertChaney_1-1738964159759.png

If I take off the conversion for the Distance field, the ArcLength shows properly, but of course the Distance field shows the COGO ERROR.

RobertChaney_2-1738964255427.png

Can anyone help point out where I need to further modify the expression to get both fields to show properly in feet?

Thanks,

Robert.

Pro ver. 3.3.1

geodatabase is fgdb

Parcel Fabric ver. 5

// Change the settings portion to configure direction format, color, rounding and abbreviations
// This is an Arcade expression

// SETTINGS
var ShowDistance = true;   //set as 'true' to show distance
var ShowDirection = false;  //set as 'true' to show direction
var DirectionType = 1; // 1 = Quadrant Bearing; 2 = North Azimuth; 3 = South Azimuth
var ShowRadius = false;     //set as 'true' to show radius
var ShowCurveParameter = true;    //set as 'true' to show a curve parameter
var ShowCOGOType = true;  //set as 'true' to show prefixes and postfixes defined below for each cogo line label
var COGOType_Entered = ['', ''] //Change prefix and postfix for Entered courses
var COGOType_Computed = ['±', '']  //Change prefix and postfix for Computed courses
var COGOType_FromGeom = ['<', '>'] //Change for prefix and postfix From Geometry courses. The < is a special character to represent the left angle bracket
var CurveParameter = "ArcLength"; //set as 'ArcLength' or 'Chord' or 'Angle' for central angle. Case sensitive!
var ErrorString = "COGO ERROR";   //set to display invalid COGO combinations
var RadiusAbbr = 'R=';     //radius abbreviation
var Radius2Abbr = 'R2=';     //radius2 abbreviation for spiral curves
var ArclengthAbrr = '';  //arclength abbreviation
var ChordAbbr = 'C=';      //chord abbreviation
var AngleAbbr = 'A=';      //central Angle abbreviation
var DistUnitRounding = 2;  //number of decimal places for distance units: distance, radius, arclength & chord
var NumberFormat = "#,###.00" //number format. In this example: thousands separator with padding of 2 zeros 
var directionColor = "blue='255'"; //direction color: red, green, blue, cyan, magenta, yellow, black. You can also use RGB or CYMK combinations.
var distanceColor = "black='255'"; //distance color: red, green, blue, cyan, magenta, yellow, black. You can also use RGB or CYMK combinations.
var radiusColor = "blue='255'";    //radius color:  red, green, blue, cyan, magenta, yellow, black. You can also use RGB or CYMK combinations.
var curveParamColor = "black='255'"; //curve parameter color:  red, green, blue, cyan, magenta, yellow, black. You can also use RGB or CYMK combinations.
var partialCOGOColor = "magenta='255'"; //partial COGO color: red, green, blue, cyan, magenta, yellow, black. You can also use RGB or CYMK combinations.
var invalidCOGOColor = "red='255'"; //invalid COGO color: red, green, blue, cyan, magenta, yellow, black. You can also use RGB or CYMK combinations.
var fontNameSize = "<FNT name = 'Arial' size = '10'>"; //font type and size

// VARIABLES
var cogo_direction = $feature.Direction;
var cogo_distance = $feature.Distance * 3.28084;
var cogo_radius = $feature.Radius;
var cogo_arclength = $feature.ArcLength * 3.28084;
var cogo_radius2 = $feature.Radius2
var cogotype = $feature.COGOType
if (HasKey($feature, "labelPosition")){
   var labelPosition = $feature.labelPosition
}
else {
   var labelPosition = 1
}
var binaryDictionary; //binary dictionary to check COGO combinations
var checksum = 0; //initialize checksum
var validValuesArray; //array of valid values for COGO combinations
var partialValuesArray; //array of partial values for COGO
var directionStr = ""; //direction string using for label
var distanceStr = "";  //distance string using for label
var radiusStr = "";    //radius string using for label
var radius2Str = "";    //radius2 string using for labeling spiral curves
var curveStr = "";     //curve parameter string using for label
var prefixPostfix = ['', '']  //Used for prefix and postfix of COGO Type
var angleRad; //curve angle in radians
var COGOValidity; //COGO combinations validity. can be valid, partial or invalid.

if (IsEmpty(cogo_direction) && IsEmpty(cogo_distance) && IsEmpty(cogo_radius) && IsEmpty(cogo_radius2) && IsEmpty(cogo_arclength)){
    return ""
}

function NorthAzimuth2Quadbearing(azimuth){
    return ConvertDirection(azimuth, {directionType:'North', angleType: 'Degrees'}, {directionType:'Quadrant', angleType: 'DMS', outputType: 'text', format: 'pd[°]mm[\']ss["]b'})
}

function DMS_North(azimuth){
    return ConvertDirection(azimuth, {directionType:'North', angleType: 'Degrees'}, {directionType:'North', angleType: 'DMS', outputType: 'text', format: 'd[°]mm[\']ss["]'})
}

function DMS_South(azimuth){
    return ConvertDirection(azimuth, {directionType:'North', angleType: 'Degrees'}, {directionType:'South', angleType: 'DMS', outputType: 'text', format: 'd[°]mm[\']ss["]'})
}

function IsValidCOGO(cogo_direction, cogo_distance, cogo_radius, cogo_arclength, cogo_radius2) {
    binaryDictionary= Dictionary('dir', 1, 'dist',2, 'rad',4, 'arc',8, 'rad2',16)
    if (!IsEmpty(cogo_direction)) {checksum+=binaryDictionary.dir}
    if (!IsEmpty(cogo_distance)) {checksum+=binaryDictionary.dist}
    if (!IsEmpty(cogo_radius)) {checksum+=binaryDictionary.rad}
    if (!IsEmpty(cogo_arclength)) {checksum+=binaryDictionary.arc}
    if (!IsEmpty(cogo_radius2)) {checksum+=binaryDictionary.rad2}
    
    validValuesArray=[0,3,13,29]; //array of valid combinations: '0' for nothing, ... '13' for direction & radius & arclength ...
    partialValuesArray=[1,2,4,5,8,9,12,16,17,20,21,24,25,27,28]; //array of partial combinations: '1' for only direction, '2' for only distance, '4' for only radius...
    //Invalid Values = [6,7,10,11,14,15,18,19,22,23,26,30,31]


    if (IndexOf(validValuesArray,checksum)>-1) { // a negative value is returned if checksum value is not in the a valid combination array
        return "valid";
    }
    if (IndexOf(partialValuesArray,checksum)>-1){
        return "partial";        
    }
    return "invalid";
}

function COGOTypePrefixPostfix(cogotypeValue){
    if (ShowCOGOType){
        if (cogotypeValue == 1) { //Entered
           return COGOType_Entered
        }
        else if(cogotypeValue == 2) { //From Geometry
           return COGOType_FromGeom
        }
        else if(cogotypeValue == 3) { //Computed
           return COGOType_Computed
        }
        else { //If not set or invalid value
           return ['', '']
        }
    }
    else{
       return(['', ''])
    }
}

COGOValidity = IsValidCOGO(cogo_direction, cogo_distance, cogo_radius, cogo_arclength, cogo_radius2);
if ( COGOValidity == "invalid") { //if invalid COGO return error string
    return "<BOL><CLR " + invalidCOGOColor + ">" + fontNameSize + ErrorString + "</FNT></CLR></BOL>";    
}

else if (COGOValidity == "partial") { //if a partial COGO change colors
    distanceColor = partialCOGOColor;
    directionColor = partialCOGOColor;
    radiusColor = partialCOGOColor;
    curveParamColor = partialCOGOColor;
}

// Direction string
if (ShowDirection) {
    if (IsEmpty(cogo_direction)==false) {
        if (DirectionType == 1) {  //using quadrant bearing format
            directionStr = NorthAzimuth2Quadbearing(cogo_direction);
        }
        else if (DirectionType == 2) {  //using north azimuth format
            directionStr = DMS_North(cogo_direction);
        }
        else if (DirectionType == 3) { //using south azimuth format
            directionStr = DMS_South(cogo_direction);
        }
    }
}

// Distance string
if (ShowDistance) {
    if (IsEmpty(cogo_distance)==false) {
    distanceStr = text(round(cogo_distance,DistUnitRounding), NumberFormat);
    }
}

//Radius String
if (ShowRadius) {
    if (!IsEmpty(cogo_radius)) { //it can be a curve or a spiral
        if (IsEmpty(cogo_radius2)) { //if radius2 is empty this is a curve
            radiusStr = RadiusAbbr + " " + text(round(cogo_radius, DistUnitRounding), NumberFormat);
        }
        else { // it is a spiral
            radiusStr = RadiusAbbr + " " + text(round(cogo_radius, DistUnitRounding),NumberFormat);
            radius2Str = Radius2Abbr + " " + text(round(cogo_radius2, DistUnitRounding),NumberFormat);
            if (cogo_radius == 0) { //substitute to infinity sign
                radiusStr = RadiusAbbr + " ∞ ";
            }
            if (cogo_radius2 == 0) { //substitute to infinity sign
                radius2Str = Radius2Abbr + " ∞ ";
            }
        }    
        
    }
}

// Curve Parameter
if (ShowCurveParameter) {
        if (!IsEmpty(cogo_arclength)) {
            if (CurveParameter == 'ArcLength') {
                curveStr = text(round(cogo_arclength, DistUnitRounding), NumberFormat); //return Arc length
            }
            angleRad = cogo_arclength/(abs(cogo_radius)) //calculate angle in radians
            if (CurveParameter == 'Angle') {
                curveStr = DMS_North(angleRad * 180 / pi); // convert radian to degrees and show as DMS
            }
            if (CurveParameter == 'Chord') {
                curveStr = text(round((2 * abs(cogo_radius) * Sin(angleRad/2)),DistUnitRounding), NumberFormat); //calculate chord length
            }            
        }
}

//Determine type of curve displayed
var CurveTypePrefix = ""
if (!IsEmpty(curveStr)){
    if (CurveParameter == 'ArcLength'){
        CurveTypePrefix = ArclengthAbrr
    }
    else if (CurveParameter == 'Angle'){
        CurveTypePrefix = AngleAbbr
    }
    else if (CurveParameter == 'Chord'){
        CurveTypePrefix = ChordAbbr
    }
}

var isStraightLine = IsEmpty(radiusStr) && IsEmpty(radius2Str) && IsEmpty(curveStr)

// Assemble label string

//Get prefix and postfix if either distance or curve is not empty. NOTE If both aren't empty it's invalid COGO
if (!IsEmpty(distanceStr) || !IsEmpty(curveStr)){
    prefixPostfix = COGOTypePrefixPostfix(cogotype)
}

var sharedLabelBuffer = ""
if (labelPosition == 3) {
    sharedLabelBuffer = " \n"
}

//Straight lines
if (isStraightLine){
    if (!IsEmpty(directionStr) && !IsEmpty(distanceStr)){ //If Direction and Distance are both NOT Empty
        return fontNameSize + "<CLR " + directionColor + ">" + directionStr  + "</CLR>" + "\n" +
                              "<CLR " + distanceColor + ">" + prefixPostfix[0] + distanceStr + prefixPostfix[1] + "</CLR></FNT>";
    }
    else if (IsEmpty(directionStr)){  //If Direction is empty
        return fontNameSize + sharedLabelBuffer + "<CLR " + distanceColor + ">" +
                               prefixPostfix[0] + distanceStr + prefixPostfix[1] + "</CLR></FNT>";
    }
    else{  //If Distance is empty
        return fontNameSize + sharedLabelBuffer + "<CLR " + directionColor + ">" + directionStr +  "</CLR></FNT>";
    }
}

//Curves
//If one or both radii and the curve string are NOT empty show the full curve
if ((!IsEmpty(radiusStr) || !IsEmpty(radius2Str)) && !IsEmpty(curveStr)){
    return fontNameSize + "<CLR " + radiusColor + ">" + radiusStr + "</CLR>" + " " +
                          "<CLR " + radiusColor + ">" + radius2Str + "</CLR>" + "\n" +
                          "<CLR " + curveParamColor + ">" + CurveTypePrefix + ' ' +
                          prefixPostfix[0] + curveStr + prefixPostfix[1] + "</CLR></FNT>";
}
//If the curve is empty
else if (IsEmpty(curveStr)){
    return fontNameSize + sharedLabelBuffer + "<CLR " + radiusColor + ">" + radiusStr + "</CLR>" + "  " +
                          "<CLR " + radiusColor + ">" + radius2Str + "</CLR></FNT>"
}
//If both radius are empty
else{
    return fontNameSize + sharedLabelBuffer + "<CLR " + curveParamColor + ">" + CurveTypePrefix + ' ' +
                          prefixPostfix[0] + curveStr + prefixPostfix[1] + "</CLR></FNT>";
}
0 Kudos
1 Solution

Accepted Solutions
AmirBar-Maor
Esri Regular Contributor

Hello @RobertChaney 

A "COGO Error" is returned when there are too many parameters. For example, if Direction, Distance, and Radius are all populated.
It looks like the conversion is placing a zero ('0') if the original value is NULL, instead of keeping it empty.

This can be solved by checking and only converting the units if the attribute is not empty:

AmirBarMaor_0-1739178740962.png

if (!IsEmpty($feature.Distance)) cogo_distance = cogo_distance*3.28084;

 

Add this check for any value that you convert (distance, radius, arclength, radius2)

Please let us know if this solves the issue

View solution in original post

2 Replies
AmirBar-Maor
Esri Regular Contributor

Hello @RobertChaney 

A "COGO Error" is returned when there are too many parameters. For example, if Direction, Distance, and Radius are all populated.
It looks like the conversion is placing a zero ('0') if the original value is NULL, instead of keeping it empty.

This can be solved by checking and only converting the units if the attribute is not empty:

AmirBarMaor_0-1739178740962.png

if (!IsEmpty($feature.Distance)) cogo_distance = cogo_distance*3.28084;

 

Add this check for any value that you convert (distance, radius, arclength, radius2)

Please let us know if this solves the issue

RobertChaney
Frequent Contributor

Your expression solved the issue, thanks Amir.

Robert.