<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Code Review: Set polyline M-values to cumulative length of line in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157702#M53244</link>
    <description>&lt;P&gt;Thanks. Good suggestion about the variables. I tried to clean them up:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var geom_text = Text(Geometry($feature));

if (geom_text == Text(Geometry($originalfeature))) {
    return
}  

function pythagoras(x1, y1, x2, y2) {
    return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

var geom = Dictionary(geom_text);
var paths = geom['paths'];
var oldX = paths[0][0][0];
var oldY = paths[0][0][1];
var line_length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0];
        var newY = paths[path_idx][point_idx][1];
        if (point_idx != 0) {
            line_length += pythagoras(oldX, oldY, newX, newY);
        }
        paths[path_idx][point_idx][-1] = line_length;
        oldX = newX;
        oldY = newY;
    }
}
return { "result": { "geometry": Polyline(geom) } };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2022 08:37:03 GMT</pubDate>
    <dc:creator>Bud</dc:creator>
    <dc:date>2022-03-25T08:37:03Z</dc:date>
    <item>
      <title>Arcade Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1153012#M52698</link>
      <description>&lt;P&gt;&lt;BR /&gt;I have an Arcade calculation attribute rule that &lt;U&gt;sets polyline M-values&lt;/U&gt; to the &lt;U&gt;cumulative length of the line&lt;/U&gt;.&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_1-1647021579427.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36155iE34735EA67F6695C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Bud_1-1647021579427.png" alt="Bud_1-1647021579427.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The script works as expected. But I'm still a novice, so I thought I'd ask:&amp;nbsp;&lt;U&gt;Can the script be improved?&lt;/U&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;Notes about the script: &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;- It works for both singlepart and multipart features.&lt;BR /&gt;&lt;/EM&gt;&lt;EM&gt;- It densifies true curves (unavoidable, since Arcade pre-densifies true curves).&lt;BR /&gt;- The code below is out-of-date. I've posted an updated version in a reply...further down in this post.&lt;/EM&gt;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#999999"&gt;//var paths = [[[0, 5, null], [10, 10, null], [30, 0, null], [50, 10, null], [60, 10, null]]];  //JS

//Only do the calculation if the geometry was changed/edited.
if (!Equals(Geometry($feature), Geometry($originalfeature))) { 
    var geom = Dictionary(Text(Geometry($feature))); 
    var paths = geom['paths']; 

    //Alternatively, this could be done with the Arcade distance() function. I chose to do the math manually so that the script can be used elsewhere, such as VSCode (for debugging).
    function pythagoras(x1, y1, x2, y2) {
        return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    }
    for (var path_idx in paths) {
        var oldX = paths[0][0][0], oldY = paths[0][0][1], length = 0;
        for (var point_idx in paths[path_idx]) {
            var newX = paths[path_idx][point_idx][0], newY = paths[path_idx][point_idx][1];
            length += pythagoras(oldX, oldY, newX, newY);
            paths[path_idx][point_idx][2] = length;
            oldX = newX;
            oldY = newY;
        }
    }  
    console(paths);
    return { "result": { "geometry": Polyline(geom) } };

    //Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]
} &lt;/FONT&gt; &lt;/PRE&gt;&lt;P&gt;(The script was adapted from this GitHub sample:&amp;nbsp;&lt;A href="https://github.com/Esri/arcade-expressions/blob/master/attribute_rule_calculation/SetMsToIndex.md" target="_self"&gt;Set Ms to Index&lt;/A&gt;.)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 02:40:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1153012#M52698</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-06-24T02:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1153198#M52725</link>
      <description>&lt;P&gt;Looks pretty good, minor tweaks and comments&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;//Only do the calculation if the geometry was changed/edited.&lt;BR /&gt;// I like to exit early when condition is not met, makes the code a little more readable&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;if &lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;Equals&lt;SPAN&gt;(&lt;/SPAN&gt;Geometry&lt;SPAN&gt;(&lt;/SPAN&gt;$feature&lt;SPAN&gt;), &lt;/SPAN&gt;Geometry&lt;SPAN&gt;(&lt;/SPAN&gt;$originalfeature&lt;SPAN&gt;))) { &lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;return&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;geom &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;Dictionary&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Text&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;Geometry&lt;SPAN&gt;(&lt;/SPAN&gt;$feature&lt;SPAN&gt;))); &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;paths &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;geom&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;'paths'&lt;/SPAN&gt;&lt;SPAN&gt;]; &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;//Alternatively, this could be done with the Arcade distance() function. I chose to do the math manually so that the script can be used elsewhere, such as VSCode (for debugging).&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;function &lt;/SPAN&gt;&lt;SPAN&gt;pythagoras&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;x1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;y1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;x2&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;y2&lt;/SPAN&gt;&lt;SPAN&gt;) {&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;sqrt&lt;SPAN&gt;(&lt;/SPAN&gt;pow&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;x2 &lt;/SPAN&gt;&lt;SPAN&gt;- &lt;/SPAN&gt;&lt;SPAN&gt;x1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;) + &lt;/SPAN&gt;pow&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;y2 &lt;/SPAN&gt;&lt;SPAN&gt;- &lt;/SPAN&gt;&lt;SPAN&gt;y1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;));&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;// Easier to read when on multi lines and moved out of the loop, it was being reset on each part, not sure that is what you wanted&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;oldX &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;paths&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;];&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;oldY &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;paths&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;];&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;// dont use length, that is a reserved function name&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;line_length &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;path_idx &lt;/SPAN&gt;&lt;SPAN&gt;in &lt;/SPAN&gt;&lt;SPAN&gt;paths&lt;/SPAN&gt;&lt;SPAN&gt;) {&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;point_idx &lt;/SPAN&gt;&lt;SPAN&gt;in &lt;/SPAN&gt;&lt;SPAN&gt;paths&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;path_idx&lt;/SPAN&gt;&lt;SPAN&gt;]) {&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;newX &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;paths&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;path_idx&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;point_idx&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;];&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;newY &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;paths&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;path_idx&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;point_idx&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;];&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;line_length &lt;/SPAN&gt;&lt;SPAN&gt;+= &lt;/SPAN&gt;&lt;SPAN&gt;pythagoras&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;oldX&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;oldY&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;newX&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;newY&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;// can use a negative slice, will work when there is no Z&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;paths&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;path_idx&lt;/SPAN&gt;&lt;SPAN&gt;][&lt;/SPAN&gt;&lt;SPAN&gt;point_idx&lt;/SPAN&gt;&lt;SPAN&gt;][-&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;] = &lt;/SPAN&gt;&lt;SPAN&gt;line_length&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;oldX &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;newX&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;oldY &lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;newY&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    }&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;}  &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;console&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;paths&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;return &lt;/SPAN&gt;&lt;SPAN&gt;{ &lt;/SPAN&gt;&lt;SPAN&gt;"result"&lt;/SPAN&gt;&lt;SPAN&gt;: { &lt;/SPAN&gt;&lt;SPAN&gt;"geometry"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;Polyline&lt;SPAN&gt;(&lt;/SPAN&gt;geom&lt;SPAN&gt;) } };&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;//Output: [[[0,5,0],[10,10,11.180339887498949],[30,0,33.54101966249685],[50,10,55.90169943749475],[60,10,65.90169943749476]]]&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;}  &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;//Generic JS version: https://jsfiddle.net/5m1c69g3/&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Mar 2022 12:16:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1153198#M52725</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2022-03-13T12:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1153307#M52732</link>
      <description>&lt;P&gt;Thanks very much Mike. That really helps.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 12:23:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1153307#M52732</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-03-14T12:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1155762#M53058</link>
      <description>&lt;P&gt;Hi Mike, here's my latest version, in case you're interested. I used your suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//Script title: Set polyline M-values to cumulative length of line

var geom = Dictionary(Text(Geometry($feature)));
var paths = geom['paths'];

//Using the Equals() function doesn't work as expected. See: Arcade: Editing M-values not treated as change to geometry (https://community.esri.com/t5/arcgis-pro-questions/arcade-editing-m-values-not-treated-as-change-to/m-p/1153917)
//if (Equals(Geometry($feature), Geometry($originalfeature)) ) { 
if (Text(Geometry($feature)) == Text(Geometry($originalfeature))) {
    console("The geometry has not changed. We don't need to redefine the M-Values.")
    return
} else {
    //Alternatively, this could be done with the Arcade distance() function. I chose to do the math manually so that the script can be used elsewhere, such as VSCode (for debugging).
    function pythagoras(x1, y1, x2, y2) {
        return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    }

    var oldX = paths[0][0][0];
    var oldY = paths[0][0][1];
    var line_length = 0;

    for (var path_idx in paths) {
        for (var point_idx in paths[path_idx]) {
            var newX = paths[path_idx][point_idx][0];
            var newY = paths[path_idx][point_idx][1];
            //For multi-part features, we want the M-value for additional parts to start at the last M-value from the last part. We don't want to measure the distance *between* parts.
            //So, for the first vertex in a given part, we will skip calculating the length between vertices.
            if (point_idx != 0) {
                line_length += pythagoras(oldX, oldY, newX, newY);
            }
            //We can use a negative slice: it will work when there is no Z.
            paths[path_idx][point_idx][-1] = line_length;
            oldX = newX;
            oldY = newY;
        }
    }
    console("The geometry has changed. So we *will* redefine the M-Values.")
    return { "result": { "geometry": Polyline(geom) } };
}  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;might find this interesting.&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 15:56:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1155762#M53058</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-03-21T15:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1155856#M53075</link>
      <description>&lt;P&gt;The else is redundant, easier to read without the indent&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//Script title: Set polyline M-values to cumulative length of line

var geom = Dictionary(Text(Geometry($feature)));
var paths = geom['paths'];

//Using the Equals() function doesn't work as expected. See: Arcade: Editing M-values not treated as change to geometry (https://community.esri.com/t5/arcgis-pro-questions/arcade-editing-m-values-not-treated-as-change-to/m-p/1153917)
//if (Equals(Geometry($feature), Geometry($originalfeature)) ) { 
if (Text(Geometry($feature)) == Text(Geometry($originalfeature))) {
    console("The geometry has not changed. We don't need to redefine the M-Values.")
    return
}  
//Alternatively, this could be done with the Arcade distance() function. I chose to do the math manually so that the script can be used elsewhere, such as VSCode (for debugging).
function pythagoras(x1, y1, x2, y2) {
    return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

var oldX = paths[0][0][0];
var oldY = paths[0][0][1];
var line_length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0];
        var newY = paths[path_idx][point_idx][1];
        //For multi-part features, we want the M-value for additional parts to start at the last M-value from the last part. We don't want to measure the distance *between* parts.
        //So, for the first vertex in a given part, we will skip calculating the length between vertices.
        if (point_idx != 0) {
            line_length += pythagoras(oldX, oldY, newX, newY);
        }
        //We can use a negative slice: it will work when there is no Z.
        paths[path_idx][point_idx][-1] = line_length;
        oldX = newX;
        oldY = newY;
    }
}
console("The geometry has changed. So we *will* redefine the M-Values.")
return { "result": { "geometry": Polyline(geom) } };&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 19:50:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1155856#M53075</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2022-03-21T19:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1155979#M53095</link>
      <description>&lt;P&gt;Looks good!&lt;/P&gt;&lt;P&gt;As Mike said, the else is unnecessary and makes it a little harder to read. Personally, I would declare &lt;STRONG&gt;geom&lt;/STRONG&gt; and &lt;STRONG&gt;paths&lt;/STRONG&gt; right before &lt;STRONG&gt;oldX&lt;/STRONG&gt;, so that they are closer to where you actually use them.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 06:41:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1155979#M53095</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-22T06:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157702#M53244</link>
      <description>&lt;P&gt;Thanks. Good suggestion about the variables. I tried to clean them up:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var geom_text = Text(Geometry($feature));

if (geom_text == Text(Geometry($originalfeature))) {
    return
}  

function pythagoras(x1, y1, x2, y2) {
    return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

var geom = Dictionary(geom_text);
var paths = geom['paths'];
var oldX = paths[0][0][0];
var oldY = paths[0][0][1];
var line_length = 0;

for (var path_idx in paths) {
    for (var point_idx in paths[path_idx]) {
        var newX = paths[path_idx][point_idx][0];
        var newY = paths[path_idx][point_idx][1];
        if (point_idx != 0) {
            line_length += pythagoras(oldX, oldY, newX, newY);
        }
        paths[path_idx][point_idx][-1] = line_length;
        oldX = newX;
        oldY = newY;
    }
}
return { "result": { "geometry": Polyline(geom) } };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 08:37:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157702#M53244</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-03-25T08:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157708#M53246</link>
      <description>&lt;P&gt;You could use the&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#equals" target="_blank"&gt;https://developers.arcgis.com/arcade/function-reference/geometry_functions/#equals&lt;/A&gt;&amp;nbsp;function to compare Geo instead of a text comparison.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 08:49:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157708#M53246</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2022-03-25T08:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157718#M53247</link>
      <description>&lt;P&gt;Yeah, although Equals() doesn’t work the way I would have expected…it doesn’t consider changes to M-values:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/arcade-editing-m-values-not-treated-as-change-to/m-p/1153917" target="_self"&gt;Arcade: Editing M-values not treated as change to geometry&lt;/A&gt;&lt;/P&gt;&lt;P&gt;So that’s why I went with the text comparison.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 10:01:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157718#M53247</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-03-25T10:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157719#M53248</link>
      <description>&lt;P&gt;Ahh good point, forgot about that.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 10:05:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1157719#M53248</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2022-03-25T10:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1273939#M67428</link>
      <description>&lt;P&gt;It looks like someone posted a similar script on GitHub:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Create SetMValues&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcade-expressions/pull/72/commits/7a6c0c824dfc3ee24252a7a6dd57556875589399" target="_blank"&gt;https://github.com/Esri/arcade-expressions/pull/72/commits/7a6c0c824dfc3ee24252a7a6dd57556875589399&lt;/A&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I wonder what this comment refers to:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;This Arcade expression will calculates field values from intersecting point layer&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Does the attribute rule actually do that? I’m a bit rusty on Arcade.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 02:00:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1273939#M67428</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2023-03-31T02:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1273965#M67433</link>
      <description>&lt;P&gt;No, it doesn't. I guess they copied the rule template and forgot to delete the comment.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 05:29:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1273965#M67433</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-03-31T05:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1297244#M70016</link>
      <description>&lt;P&gt;Related:&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/attribute-rules-questions/can-t-modify-geometries-with-m-values-in-arcgis/m-p/1291479/thread-id/911" target="_self"&gt;Can't modify geometries with m-Values in ArcGIS Pro 3.0 / 3.1 with calculation rules&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/petroleum/maintain-measure-attributes/" target="_self"&gt;Maintain Measure Attributes&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-roads-and-highways-blog/arcade-for-measure-attribute-rule/ba-p/1306711" target="_self"&gt;Arcade for Measure Attribute Rule&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/attribute-rules-questions/update-line-z-values/m-p/1504741/highlight/true#M1509" target="_self"&gt;Update Line Z Values&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Fri, 12 Jul 2024 14:56:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1297244#M70016</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2024-07-12T14:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1365445#M76856</link>
      <description>&lt;P&gt;For future reference, when my organization moves from Pro 2.6.8 to Pro 3.x:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;...copy your geoemtry(can do this by calling Dictionary(geo) on it, prior to 3.2, you need to call Dictionary(Text(geo))).&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/attribute-rules-questions/arcade-modify-only-z-geometry/m-p/1365442/highlight/true#M1227" target="_self"&gt;Arcade modify only Z geometry&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2025 15:35:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1365445#M76856</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2025-01-29T15:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Code Review: Set polyline M-values to cumulative length of line</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1579962#M92422</link>
      <description>&lt;P&gt;A related Arcade solution:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/how-to-batch-edit-z-values-and-set-them-all-to/m-p/1579857/highlight/true#M92408" target="_self"&gt;How to batch edit Z values and set them all to zero&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2025 15:35:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-code-review-set-polyline-m-values-to/m-p/1579962#M92422</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2025-01-29T15:35:37Z</dc:date>
    </item>
  </channel>
</rss>

