Select to view content in your preferred language

Attribute Rule when splitting a line

894
6
Jump to solution
11-02-2023 10:12 AM
DominicRoberge2
Frequent Contributor

Hello,

I am looking for an Attribute Rule that would allow me to split a line (water main) and for one segment retain the original unique ID and the other segment, get the next available ID. Is that doable?

Any guidance would be much appreciated.

Thanks!

D

 

DominicRoberge2_0-1698944868615.png

DominicRoberge2_1-1698944930248.png

 

0 Kudos
1 Solution

Accepted Solutions
TobeyKane-Seitz
Occasional Contributor

I just tested it, and I think it's failing because of lines 52-54. If the field already has an ID value, it doesn't get overwritten. If it's empty, it gets a new ID. Try commenting out those lines and splitting the line. 

View solution in original post

0 Kudos
6 Replies
TobeyKane-Seitz
Occasional Contributor

If you have an attribute rule setup that assigns a new ID "on insert", the action of splitting the line should cause the shorter segment of the line to be created as a new feature, which would trigger the attribute rule and give that line segment a new ID. The longer segment of the original line would retain the original ID. 

0 Kudos
DominicRoberge2
Frequent Contributor

that doesn't seem to be working for me. Below is the code I am using (which is from the UN water foundation)

 

 

 

var assigned_to_field = $feature.FUID;
var id_selector_value = $feature.assetgroup;

function get_id(selector_value) {
    var id_format = {}
    var seq_val = null;
    var selector_value_txt = Text(selector_value)
    if (selector_value_txt == '1') {
                            id_format = {
                                'prefix': "DRSQ1",
                                'join_char': '',
                                'suffix': ''
                            }
                            seq_val = NextSequenceValue('DR_DB_SEQ_1');
                        }else if (selector_value_txt == '50') {
                            id_format = {
                                'prefix': "Wr-Jnctn",
                                'join_char': '-',
                                'suffix': ''
                            }
                            seq_val = NextSequenceValue('W_J_Wr_Jnctn_50_seq');
                        }else if (selector_value_txt == '51') {
                            id_format = {
                                'prefix': "Insltn-Jnctn",
                                'join_char': '-',
                                'suffix': ''
                            }
                            seq_val = NextSequenceValue('W_J_Insltn_Jnctn_51_seq');
                        } else {
        return null;
    }
        var id_parts = remove_empty([id_format['prefix'], seq_val, id_format['suffix']])
        return   id_format['prefix'] + Text(seq_val , "00000")
    }
// ************* End User Variables Section *************

// *************       Functions            *************
function remove_empty(arr) {
   var new_arr = [];
   var j = 0;
   for (var i = 0; i < Count(arr); i++) {
       if (!IsEmpty(arr[i]) && arr[i] != '') {
           new_arr[j++] = arr[i];
       }
   }
   return new_arr;
}

// ************* End Functions Section *****************


if (IsEmpty(assigned_to_field) == false && assigned_to_field != '') {
            return assigned_to_field
}
var new_id = get_id(id_selector_value)

if (IsEmpty(new_id)) {
    return assigned_to_field;
}

return new_id

0 Kudos
TobeyKane-Seitz
Occasional Contributor

Does the above code work when digitizing completely new line features?

0 Kudos
DominicRoberge2
Frequent Contributor

Yes, if I create a new line, no problem I get the next UID as expected. The issue is when splitting a line .

0 Kudos
TobeyKane-Seitz
Occasional Contributor

I just tested it, and I think it's failing because of lines 52-54. If the field already has an ID value, it doesn't get overwritten. If it's empty, it gets a new ID. Try commenting out those lines and splitting the line. 

0 Kudos
DominicRoberge2
Frequent Contributor

Thank you! That did the trick. I though I had tested it before but I guess not.🤣

D

0 Kudos