<?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: Create polylines of sertain length with attribute rules in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/create-polylines-of-sertain-length-with-attribute/m-p/1161071#M6239</link>
    <description>&lt;P&gt;Thank you very much, &lt;SPAN&gt;Johannes! I didn't expect the solution so soon.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;It works, fantastic!&lt;/P&gt;</description>
    <pubDate>Tue, 05 Apr 2022 09:53:43 GMT</pubDate>
    <dc:creator>ОльгаПинчук</dc:creator>
    <dc:date>2022-04-05T09:53:43Z</dc:date>
    <item>
      <title>Create polylines of sertain length with attribute rules</title>
      <link>https://community.esri.com/t5/developers-questions/create-polylines-of-sertain-length-with-attribute/m-p/1160622#M6235</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have an editing task on the portal to create polyline features in the feature service , that will have&amp;nbsp;aliquot (integer) length in meters (like 1m, 2m, 3m, etc). I know, it is possible to do with ArcGIS Pro, but I need this option on the portal.&lt;/P&gt;&lt;P&gt;It means that user will not be able to create the line with length 2.5 meters and 3.8 meters, only 2 and 4 m.&lt;/P&gt;&lt;P&gt;I thought it is possible to do with attribute rules and geometry functions in Arcade, but didn't find the right function for this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Probably, there are some other ways to make this operation posible during editing on the portal.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Apr 2022 20:50:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/create-polylines-of-sertain-length-with-attribute/m-p/1160622#M6235</guid>
      <dc:creator>ОльгаПинчук</dc:creator>
      <dc:date>2022-04-03T20:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create polylines of sertain length with attribute rules</title>
      <link>https://community.esri.com/t5/developers-questions/create-polylines-of-sertain-length-with-attribute/m-p/1160665#M6236</link>
      <description>&lt;P&gt;There isn't a dedicated function for that, but you can do it using a little math and array manipulation:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get the new distance of the polyline
// we should make sure it isn't zero.
var old_length = Length(Geometry($feature), "meters")
var new_length = Max(1, Round(old_length))  // 4.2 -&amp;gt; 4; 4.5 -&amp;gt; 5; 0.1 -&amp;gt; 1

// we want to change the geometry of the $feature, which means changing the 
// paths attribute, where the points are stored.
// this is an array, and arrays can't be changed, so we have to copy all
// points except the last one (because we want to change that) into a new array.
var path = Geometry($feature).paths[0]
var new_path = []
for(var p = 0; p &amp;lt; Count(path)-1; p++) {
    Push(new_path, [path[p].x, path[p].y])
}
// we only change the last segment of the polyline, so we have to get the 
// new length and the angle of that segment
var last_length = Distance(path[-2], path[-1])
var new_last_length = last_length + (new_length - old_length)
var a = Angle(path[-2], path[-1]) * PI / 180  // degrees to radians

// now we can use simple trigonometry to calculate the new last point and
// append it to the array.
Push(new_path, [
    new_path[-1][0] + new_last_length * Cos(a),  // new_x = old_x + distance * cos(angle)
    new_path[-1][1] + new_last_length * Sin(a)   // new_y = old_x + distance * sin(angle)
    ])

// and then we convert the point array to a polyline and return that.
return Polyline({"paths": [new_path], "spatialReference": Geometry($feature).spatialReference})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use this expression as a Calculation Attribute Rule on the Shape field, triggers: Insert and Update.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will change the last segment of the polyline to make the polyline an integer length. Well, almost: there seem to be some rounding errors...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1649052835353.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/38064iB3A09F656625521E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1649052835353.png" alt="JohannesLindner_0-1649052835353.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1649052850182.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/38065i8D6146C05E86EE31/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1649052850182.png" alt="JohannesLindner_1-1649052850182.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_2-1649052877984.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/38066iAC470F68A1A06523/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_2-1649052877984.png" alt="JohannesLindner_2-1649052877984.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 06:15:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/create-polylines-of-sertain-length-with-attribute/m-p/1160665#M6236</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-04-04T06:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create polylines of sertain length with attribute rules</title>
      <link>https://community.esri.com/t5/developers-questions/create-polylines-of-sertain-length-with-attribute/m-p/1161071#M6239</link>
      <description>&lt;P&gt;Thank you very much, &lt;SPAN&gt;Johannes! I didn't expect the solution so soon.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;It works, fantastic!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 09:53:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/create-polylines-of-sertain-length-with-attribute/m-p/1161071#M6239</guid>
      <dc:creator>ОльгаПинчук</dc:creator>
      <dc:date>2022-04-05T09:53:43Z</dc:date>
    </item>
  </channel>
</rss>

