<?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: Apply count of intersecting features to another features attribue field in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1132357#M282</link>
    <description>&lt;P&gt;For code display:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1641884667644.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31165i342B826A9EAC6045/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1641884667644.png" alt="JohannesLindner_0-1641884667644.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1641884685610.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31166i3ABF26675F3F871D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1641884685610.png" alt="JohannesLindner_1-1641884685610.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/community-ideas/please-move-the-quot-insert-code-sample-quot/idi-p/1063970" target="_blank"&gt;Please move the "Insert code sample" button - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The count in PolygonsA changes when&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;a feature is added in B&lt;/LI&gt;&lt;LI&gt;a feature is updated in B&lt;/LI&gt;&lt;LI&gt;a feature is deleted in B&lt;/LI&gt;&lt;LI&gt;a feature is added in A&lt;/LI&gt;&lt;LI&gt;a feature is updated in A&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;For A, it's easy:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attribute Rule in PolygonA (L16GridSystem15NM)
// field: RangeUsage
// triggers: insert, update

// if you want to get fancy, you can return early if neither the geometry
// nor the count field changed:
if(Equals(Geometry($feature), Geometry($originalfeature)) &amp;amp;&amp;amp; $feature.RangeUsage == $originalfeature.RangeUsage) {
  return $feature.RangeUsage
}

// return the count of intersecting features of PolygonsB
var fs_polygons_b = FeatureSetByName($datastore, "PolygonsB", ["GlobalID"], true)
var intersecting_b = Intersects($feature, fs_polygons_b)
return Count(intersecting_b)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For PolygonsB it's a little more complicated. Basically, whenever a feature is added/updated/deleted in B, you want to trigger the calculation rule in the intersecting A features. In this example I do that by setting the count field to null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attriute Rule in PolygonsB
// field: empty
// triggers: insert, update, delete

var fs_polygons_a = FeatureSetByName($datastore, "PolygonsA", ["GlobalID"], true)
var updates = []

// update all A features that intersect the new or updated B feature
if(Includes(["INSERT", "UPDATE"], $editcontext.editType)) {
  for(var a in Intersects($feature, fs_polygons_a)) {
    Push(updates, {globalID: a.GlobalID, attributes: {RangeUsage: null}})
  }
}

// update all A features that intersected the original feature (before update or deletion)
if(Includes(["UPDATE", "DELETE"], $editcontext.editType)) {
  for(var a in Intersects($originalfeature, fs_polygons_a)) {
    Push(updates, {globalID: a.GlobalID, attributes: {RangeUsage: null}})
  }
}

return {
  edit: [{className: "L16GridSystem15NM", updates: updates}]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The rule for PolygonsB currently works for inserting and updating features. It does not work for deleting features, I have absolutely no idea why. Maybe someone else can shed light on that. Maybe&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;?&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jan 2022 09:33:47 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-01-11T09:33:47Z</dc:date>
    <item>
      <title>Apply count of intersecting features to another features attribue field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1132239#M281</link>
      <description>&lt;P&gt;Hey all, im looking to use attribute rules to populate a field of another featureclass with the count of intersecting features.&lt;/P&gt;&lt;P&gt;For example, Polygon B intersects Polygon A, in Polygons A table there is a field that has the count of all Polygons in Polygon B intersecting it, so if Polygon B has three polygons intersecting A, A's field shows the integer 3.&lt;/P&gt;&lt;P&gt;I was able to achieve this in a pop-up easy enough, but i cant quite get it to work in attribute rules.&lt;/P&gt;&lt;P&gt;"L16GridSystem15NM" would be "Polygon A" in the above exmaple, $feature would be B, This is what I have so far:&lt;/P&gt;&lt;P&gt;var geom2 = FeatureSetByName($datastore,"L16GridSystem15NM");&lt;BR /&gt;var Intersect = Intersects(geom2, $feature);&lt;BR /&gt;var AddList = []&lt;BR /&gt;var counter = 0&lt;BR /&gt;var total = Count(Intersect);&lt;BR /&gt;if (total &amp;gt; 0) {&lt;BR /&gt;for (var i in Intersect) {&lt;BR /&gt;AddList[total] + {&lt;BR /&gt;'globalid' : i.globalid,&lt;BR /&gt;'attributes': {&lt;BR /&gt;'RangeUsage': total&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;counter++&lt;BR /&gt;}&lt;BR /&gt;return {&lt;BR /&gt;"edit": [&lt;BR /&gt;{&lt;BR /&gt;'className' : "L16GridSystem15NM",&lt;BR /&gt;'updates' : [&lt;BR /&gt;{&lt;BR /&gt;'attributes' : {&lt;BR /&gt;'RangeUsage' : total&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have played around with different options from here:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/advanced-gdb-attribute-rules-editing-external-features-with-attribute-rules/" target="_blank" rel="noopener"&gt;https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/advanced-gdb-attribute-rules-editing-external-features-with-attribute-rules/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and documentation here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/help/data/geodatabases/overview/attribute-rule-script-expression.htm#anchor4" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/2.8/help/data/geodatabases/overview/attribute-rule-script-expression.htm#anchor4&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I either had a error stating that globalid was not defined in the edit function or if i changed it to the current one above, it says that the Index is out of bounds (script line &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/P&gt;&lt;P&gt;any help with this would be great!&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Keiran&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jan 2022 22:55:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1132239#M281</guid>
      <dc:creator>KeiranBray</dc:creator>
      <dc:date>2022-01-10T22:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: Apply count of intersecting features to another features attribue field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1132357#M282</link>
      <description>&lt;P&gt;For code display:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1641884667644.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31165i342B826A9EAC6045/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1641884667644.png" alt="JohannesLindner_0-1641884667644.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1641884685610.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31166i3ABF26675F3F871D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1641884685610.png" alt="JohannesLindner_1-1641884685610.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/community-ideas/please-move-the-quot-insert-code-sample-quot/idi-p/1063970" target="_blank"&gt;Please move the "Insert code sample" button - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The count in PolygonsA changes when&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;a feature is added in B&lt;/LI&gt;&lt;LI&gt;a feature is updated in B&lt;/LI&gt;&lt;LI&gt;a feature is deleted in B&lt;/LI&gt;&lt;LI&gt;a feature is added in A&lt;/LI&gt;&lt;LI&gt;a feature is updated in A&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;For A, it's easy:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attribute Rule in PolygonA (L16GridSystem15NM)
// field: RangeUsage
// triggers: insert, update

// if you want to get fancy, you can return early if neither the geometry
// nor the count field changed:
if(Equals(Geometry($feature), Geometry($originalfeature)) &amp;amp;&amp;amp; $feature.RangeUsage == $originalfeature.RangeUsage) {
  return $feature.RangeUsage
}

// return the count of intersecting features of PolygonsB
var fs_polygons_b = FeatureSetByName($datastore, "PolygonsB", ["GlobalID"], true)
var intersecting_b = Intersects($feature, fs_polygons_b)
return Count(intersecting_b)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For PolygonsB it's a little more complicated. Basically, whenever a feature is added/updated/deleted in B, you want to trigger the calculation rule in the intersecting A features. In this example I do that by setting the count field to null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attriute Rule in PolygonsB
// field: empty
// triggers: insert, update, delete

var fs_polygons_a = FeatureSetByName($datastore, "PolygonsA", ["GlobalID"], true)
var updates = []

// update all A features that intersect the new or updated B feature
if(Includes(["INSERT", "UPDATE"], $editcontext.editType)) {
  for(var a in Intersects($feature, fs_polygons_a)) {
    Push(updates, {globalID: a.GlobalID, attributes: {RangeUsage: null}})
  }
}

// update all A features that intersected the original feature (before update or deletion)
if(Includes(["UPDATE", "DELETE"], $editcontext.editType)) {
  for(var a in Intersects($originalfeature, fs_polygons_a)) {
    Push(updates, {globalID: a.GlobalID, attributes: {RangeUsage: null}})
  }
}

return {
  edit: [{className: "L16GridSystem15NM", updates: updates}]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The rule for PolygonsB currently works for inserting and updating features. It does not work for deleting features, I have absolutely no idea why. Maybe someone else can shed light on that. Maybe&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 09:33:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1132357#M282</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-01-11T09:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Apply count of intersecting features to another features attribue field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1132665#M283</link>
      <description>&lt;P&gt;Hey Johannes, thanks for getting back to me and spending the time to take a look,&lt;/P&gt;&lt;P&gt;What you have for A is what I had too with which is good to see!&lt;/P&gt;&lt;P&gt;For B, that works for me as well which is great, i also have the same issue with deletes though, but this is still pretty good and achieves just about what I need, I'll have another look today at the delete option and see if I can get it to work,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Keiran&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 23:51:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1132665#M283</guid>
      <dc:creator>KeiranBray</dc:creator>
      <dc:date>2022-01-11T23:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Apply count of intersecting features to another features attribue field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1184776#M442</link>
      <description>&lt;P&gt;Hi Johannes,&lt;/P&gt;&lt;P&gt;I am trying to do something very similar but in my case I want to count the points inside a polygon when a new point is inserted.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I applied this code and when I add a new point&amp;nbsp; the field that captures how many points are in the polygon changes to null, so the code works as expected. I was wondering within this code I could I get it to update the count field in the polygon layer with the correct number of points in the polygon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Donovan&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 17:49:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1184776#M442</guid>
      <dc:creator>DonovanC</dc:creator>
      <dc:date>2022-06-21T17:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Apply count of intersecting features to another features attribue field</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1184986#M443</link>
      <description>&lt;P&gt;It sounds like you did not create the rule for the polygon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your polygons are static (you don't edit them), you can do all of the work from within the point fc:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attriute Rule in TestPoints
// field: empty
// triggers: insert, update, delete

var fs_polygons = FeatureSetByName($datastore, "TestPolygons", ["GlobalID"], true)
var updates = []

// update all polygons that intersect the feature
for(var poly in Intersects($feature, fs_polygons)) {
  var point_count = Count(Intersects(poly, $featureset))
  if($editcontext.editType == "DELETE") {
    // $feature is still there hwen this rule is executed, so we have to substract 1
    point_count -= 1
  }
  Push(updates, {globalID: poly.GlobalID, attributes: {IntegerField: point_count}})
}

// update all polygons that intersected the original feature (before update)
if($editcontext.editType == "UPDATE") {
  for(var poly in Intersects($originalfeature, fs_polygons)) {
    var point_count = Count(Intersects(poly, $featureset))
    Push(updates, {globalID: poly.GlobalID, attributes: {IntegerField: point_count}})
  }
}

return {
  edit: [{className: "TestPolygons", updates: updates}]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1655886453252.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43995iC04E9D4E02E56CB7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1655886453252.png" alt="JohannesLindner_0-1655886453252.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Creating points:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1655886491017.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43996iD2B488368387D191/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1655886491017.png" alt="JohannesLindner_1-1655886491017.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Moving points:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_2-1655886531504.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43997i71B77BBBB2DAAA46/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_2-1655886531504.png" alt="JohannesLindner_2-1655886531504.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Deleting points:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_3-1655886550980.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43998i257A02871E2DE5F9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_3-1655886550980.png" alt="JohannesLindner_3-1655886550980.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Literal edge cases:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_4-1655886605810.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43999i5B1CA3BD0C0E7C45/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_4-1655886605810.png" alt="JohannesLindner_4-1655886605810.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 08:32:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/apply-count-of-intersecting-features-to-another/m-p/1184986#M443</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-22T08:32:06Z</dc:date>
    </item>
  </channel>
</rss>

