<?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: Arcade Error: intersection in the same layer in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-error-intersection-in-the-same-layer/m-p/1145320#M51661</link>
    <description>&lt;P&gt;I have tried it and I can't get it to work.&amp;nbsp; I hope I'm missing something simple and that I'm wrong here, but I think the problem is that we are assuming that Intersection is going to return a geometry of type point and I'm not sure from the documentation that it does.&lt;/P&gt;&lt;P&gt;The only work around I can think of is to return the path from $feature using something like this:&lt;/P&gt;&lt;P&gt;var pipeGeom = geometry($feature)&lt;BR /&gt;var paths = pipeGeom.paths&lt;/P&gt;&lt;P&gt;Then step through each point (vertice) in the "path" to determine if it intersects a pipe other than $feature.&amp;nbsp; By this I mean you'll have to do something like this to make sure you don't consider the pipe you are currently entering; because of course all the points on that pipe's "path" will be intersected:&lt;/P&gt;&lt;P&gt;var thisPipe = $feature.GlobalID&lt;BR /&gt;var pipe = Filter(FeatureSetByName($datastore, "pipe"),'GlobalID &amp;lt;&amp;gt; @thisPipe')&amp;nbsp;&lt;/P&gt;&lt;P&gt;When/if you find the point/vertice along the path that intersects another pipe, that will be the geometry you use to "edit:" your point layer.&lt;/P&gt;&lt;P&gt;Again, I hope I am wrong and that I'm missing something simple, but the Arcade documentation for Intersection doesn't mention "if you provide two line geometries as inputs a set of intersection points will be returned"....&lt;/P&gt;</description>
    <pubDate>Thu, 17 Feb 2022 19:45:07 GMT</pubDate>
    <dc:creator>KimberlyGarbade</dc:creator>
    <dc:date>2022-02-17T19:45:07Z</dc:date>
    <item>
      <title>Arcade Error: intersection in the same layer</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-error-intersection-in-the-same-layer/m-p/1145175#M51645</link>
      <description>&lt;P&gt;I have 2 layers (pipe layer&amp;lt;line&amp;gt;&amp;nbsp; and&amp;nbsp; fitting layer&amp;lt;point&amp;gt;) and the 2 layers is empty&amp;nbsp;&lt;BR /&gt;I assigned an attribute rule to the pipe layer,&lt;/P&gt;&lt;P&gt;this Rule manage me to draw new feature in the pipe layer and&lt;BR /&gt;if that new feature intersected with an existed feature in the same layer (pipe layer) =&amp;gt; new point will be created and inserted into the fitting layer&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Trigger types: insert and update&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;pipe&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;FeatureSetByName&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;$datastore&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"pipe"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;existed_feature&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Intersects&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;pipe&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;new_point&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Point&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Intersection&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;First&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;existed_feature&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;$feature&lt;/SPAN&gt;&lt;SPAN&gt;));&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;SPAN&gt; { &amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;"edit"&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt; [&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"className"&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;"test_point"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"adds"&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt; [{&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"geometry"&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;new_point&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;} &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;] &amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333399"&gt;&lt;SPAN&gt;};&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;BR /&gt;&amp;lt;&amp;lt; I Get "&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#339966"&gt;✓ Expression valid&lt;/FONT&gt;&lt;/STRONG&gt;" message on the rule &amp;gt;&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;STRONG&gt;The issue is, When I start drawing new pipe I get an &lt;FONT color="#FF6600"&gt;error&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;BR /&gt;"Failed to create new feature(s)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;invalid geometry[rule name: intersection , trigger event: insert, class name: pipe, GlopalID: **** ]&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;"&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Where is the problem, any help ?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 17 Feb 2022 15:28:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-error-intersection-in-the-same-layer/m-p/1145175#M51645</guid>
      <dc:creator>AhmedElagroudy</dc:creator>
      <dc:date>2022-02-17T15:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Error: intersection in the same layer</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-error-intersection-in-the-same-layer/m-p/1145320#M51661</link>
      <description>&lt;P&gt;I have tried it and I can't get it to work.&amp;nbsp; I hope I'm missing something simple and that I'm wrong here, but I think the problem is that we are assuming that Intersection is going to return a geometry of type point and I'm not sure from the documentation that it does.&lt;/P&gt;&lt;P&gt;The only work around I can think of is to return the path from $feature using something like this:&lt;/P&gt;&lt;P&gt;var pipeGeom = geometry($feature)&lt;BR /&gt;var paths = pipeGeom.paths&lt;/P&gt;&lt;P&gt;Then step through each point (vertice) in the "path" to determine if it intersects a pipe other than $feature.&amp;nbsp; By this I mean you'll have to do something like this to make sure you don't consider the pipe you are currently entering; because of course all the points on that pipe's "path" will be intersected:&lt;/P&gt;&lt;P&gt;var thisPipe = $feature.GlobalID&lt;BR /&gt;var pipe = Filter(FeatureSetByName($datastore, "pipe"),'GlobalID &amp;lt;&amp;gt; @thisPipe')&amp;nbsp;&lt;/P&gt;&lt;P&gt;When/if you find the point/vertice along the path that intersects another pipe, that will be the geometry you use to "edit:" your point layer.&lt;/P&gt;&lt;P&gt;Again, I hope I am wrong and that I'm missing something simple, but the Arcade documentation for Intersection doesn't mention "if you provide two line geometries as inputs a set of intersection points will be returned"....&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 19:45:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-error-intersection-in-the-same-layer/m-p/1145320#M51661</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-02-17T19:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Error: intersection in the same layer</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-error-intersection-in-the-same-layer/m-p/1147296#M51904</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/562205"&gt;@AhmedElagroudy&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119500"&gt;@KimberlyGarbade&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;When creating Attribute Rules you need to be sure to check for anything that could go wrong along the way:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For instance, when drawing your first line or any line that does not intersect another line, this will not return anything in the intersection and therefore "First" will fail.&lt;/LI&gt;&lt;LI&gt;The intersection (and this somewhat surprised me) only seems to work on polygons&lt;/LI&gt;&lt;LI&gt;You cannot cast the result of an intersection to a point&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;And really, you should take a look at this great repository created by Mike Miller with a lot of examples:&amp;nbsp;&lt;A href="https://github.com/MikeMillerGIS/arcade-expressions/tree/master/attribute_rule_calculation" target="_blank"&gt;https://github.com/MikeMillerGIS/arcade-expressions/tree/master/attribute_rule_calculation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to not overcomplicate the expression I did the following:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Query the pipe featureset for all features that are not the current one&lt;/LI&gt;&lt;LI&gt;Count the result of the intersects and if there is no pipe found (no intersection) do not return anything&lt;/LI&gt;&lt;LI&gt;Create a small buffer of the current feature and of each intersecting pipe,&lt;/LI&gt;&lt;LI&gt;Intersect the polygons&lt;/LI&gt;&lt;LI&gt;Extract the centroid of the intersecting polygon&lt;/LI&gt;&lt;LI&gt;Add the result(s) to an array to allow to add multiple points to the points layer&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Some more graphical explanations are below.&lt;/P&gt;&lt;P&gt;The initial situation, lines in blue and intersecting points displayed with red crosses:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="XanderBakker_0-1645654735171.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/34831i038F3F0BE7D25B06/image-size/medium?v=v2&amp;amp;px=400" role="button" title="XanderBakker_0-1645654735171.png" alt="XanderBakker_0-1645654735171.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Start drawing the line and create multiple intersections (only 1 per existing line):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="XanderBakker_1-1645654849117.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/34832i6F2736D18DD88604/image-size/medium?v=v2&amp;amp;px=400" role="button" title="XanderBakker_1-1645654849117.png" alt="XanderBakker_1-1645654849117.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The intersecting points are added to the points layer:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="XanderBakker_2-1645654891201.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/34833iDBCC24DF84EED8A1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="XanderBakker_2-1645654891201.png" alt="XanderBakker_2-1645654891201.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now there are some things you will have to take into account:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The points created are close to the intersection but not necessarily on the intersection since we are using a centroid of a polygon! So if you need the exact intersection you will need to explore the examples on Github to create a much more advanced expression to accomplish this.&lt;/LI&gt;&lt;LI&gt;When your new line crosses an existing line it will create a point in the center of the multiple polygon sin the multipart intersection polygon. To avoid this you could convert the multipart to single-part and loop over each part to create the centroid.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The expression used:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var globid = $feature.GlobalID;
var sql = "GLOBALID &amp;lt;&amp;gt; @globid";
var pipes = Filter(FeatureSetByName($datastore, "pipe"), sql);
if (Count(pipes) &amp;gt; 0) {
var intersecting_features = Intersects(pipes, $feature);
var cnt = Count(intersecting_features);

var adds = [];
if (cnt &amp;gt; 0) {
    var polf = Buffer($feature, 0.1, "m");
    for (var pipe in intersecting_features) {
        var poli = Buffer(pipe, 0.1, "m");
        var polint = Intersection(poli, polf);
        var pnt = Centroid(Polygon(polint));
        Push(adds, {"geometry": pnt});
    }
}

// don't try and return anything when there is no intersection!
if (Count(adds) &amp;gt; 0) {
  return {  
    "edit": [
     {"className": "test_point",
       "adds": adds
     }
   ]};
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 23 Feb 2022 22:26:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-error-intersection-in-the-same-layer/m-p/1147296#M51904</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2022-02-23T22:26:27Z</dc:date>
    </item>
  </channel>
</rss>

