<?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 Expression to count points intersecting multiple polygons in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030166#M38652</link>
    <description>&lt;P&gt;Yes sir, that worked perfectly!&amp;nbsp; Thank you, I really appreciate the help!&lt;/P&gt;&lt;P&gt;Funny, I too tried the union.&amp;nbsp; My logic was to turn the featureset into a single polygon.&amp;nbsp; Seems this isn;t an option.&lt;/P&gt;&lt;P&gt;Clearly I need to do some researching on for loops in Arcade.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thank you very much!&lt;/P&gt;</description>
    <pubDate>Wed, 24 Feb 2021 19:55:11 GMT</pubDate>
    <dc:creator>JasonGlidewell</dc:creator>
    <dc:date>2021-02-24T19:55:11Z</dc:date>
    <item>
      <title>Arcade Expression to count points intersecting multiple polygons</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030084#M38644</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to count the number of point features intersecting multiple polygons.&amp;nbsp; I have filtered the polygons by an attribute value.&lt;/P&gt;&lt;P&gt;I have included what I have below but I keep getting an error stating, "&lt;SPAN&gt;Spatial Relation cannot accept this parameter type"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My goal is to click on a polygon and count all the points intersecting all polygon with the same text attribute.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help would be greatly appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JasonGlidewell_2-1614188056373.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/6796i0A20F4235B4278CC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JasonGlidewell_2-1614188056373.png" alt="JasonGlidewell_2-1614188056373.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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 17:34:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030084#M38644</guid>
      <dc:creator>JasonGlidewell</dc:creator>
      <dc:date>2021-02-24T17:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to count points intersecting multiple polygons</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030090#M38646</link>
      <description>&lt;P&gt;Just a general tip, don't forget about the &lt;STRONG&gt;Code Sample&lt;/STRONG&gt; option on here, it can make your post a lot easier to read for other users.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1614188861002.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/6797iBE88736C4383C156/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1614188861002.png" alt="jcarlson_0-1614188861002.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It would help to know more about all of these layers. You mention points and "multiple" polygons; which layers are the points, and which are the polygons? Can you give an example situation and the output you'd expect to get from it?&lt;/P&gt;&lt;P&gt;I can see you're using the &lt;STRONG&gt;Console&lt;/STRONG&gt; function; are you getting messages from those? Does the error message specifically point to the &lt;STRONG&gt;Intersects&lt;/STRONG&gt; line?&lt;/P&gt;&lt;P&gt;I'm sure there's a way to address this, but I don't think I have enough information.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 17:54:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030090#M38646</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-02-24T17:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to count points intersecting multiple polygons</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030101#M38647</link>
      <description>&lt;P&gt;Hi Josh,&lt;/P&gt;&lt;P&gt;I appreciate your willingness to help.&amp;nbsp; I apologize for the question error.&amp;nbsp; This is my first post on here.&lt;/P&gt;&lt;P&gt;My polygons represent operating areas.&amp;nbsp; However, a single person oversees multiple operating areas.&amp;nbsp; By clicking on one polygon I would like to get the count of all points (in this case customer locations) within all polygons overseen by the same person.&amp;nbsp; The name of the supervisor is an attribute in all polygons.&lt;/P&gt;&lt;P&gt;My featureset after the filter includes the required polygons, confirmed by the Console Count on line 13.&amp;nbsp; However, it seems the intersect function can not accept more than one polygon, at least that is my guess.&lt;/P&gt;&lt;P&gt;My points have the variable prem and are brought in via portal.&amp;nbsp; My polygons have the variable PWSID and are also brought in via portal.&amp;nbsp; From there, I am filtering by the polygons by "OperatingDistrict".&amp;nbsp; However, it seems this filtered featureset is unacceptable to the intersects function.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// Sources: Meter Pits Clean-up, wMeterPit, Meter Pit Collection, Meter Collection, wPremiseLocation
var mpcu = FeatureSetByPortalItem(Portal('https://maps.arcgis.com/'), '060fbd931a9d4736bfc495839c6279bf', '0')
var mpsde = FeatureSetByPortalItem(Portal('https://maps.arcgis.com/'), 'e56c278361ee4e758bff62bea1eb1a27', '0')
var mpcol = FeatureSetByPortalItem(Portal('https://maps.arcgis.com/'), '5abe4e6ee79341a4a3cb6264a0774409', '15')
var mcol = FeatureSetByPortalItem(Portal('https://maps.arcgis.com/'), '5abe4e6ee79341a4a3cb6264a0774409', '16')
var prem = FeatureSetByPortalItem(Portal('https://maps.arcgis.com/'), 'c64a2c678acf46b098f0c063797a2474', '0')

var PWSID = FeatureSetByPortalItem(Portal('https://inaw.maps.arcgis.com/'), '10e903ae8c11435c80667d764ec1b226', '0')
var opdist = $feature.OperatingDistrict
Console(opdist)
var premsql = "OperatingDistrict LIKE @opdist"
var opdistfilter = Filter(PWSID, premsql)

var intcount = Count(Intersects(opdistfilter,prem))

return intcount&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 18:08:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030101#M38647</guid>
      <dc:creator>JasonGlidewell</dc:creator>
      <dc:date>2021-02-24T18:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to count points intersecting multiple polygons</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030154#M38651</link>
      <description>&lt;P&gt;Gotcha!&lt;/P&gt;&lt;P&gt;Well, this is certainly still possible, but it could be a really laggy expression. &lt;STRONG&gt;Intersects&lt;/STRONG&gt; wants either two geometries, or a geometry and a FeatureSet, but not two FeatureSets.&lt;/P&gt;&lt;P&gt;To deal with this, you've got to run your Intersection against a single district feature. Initially, I'd thought to use the &lt;STRONG&gt;Union&lt;/STRONG&gt; function to merge the districts first, but my test said I used an "Illegal Argument", so I went with plan B: a for-loop.&lt;/P&gt;&lt;P&gt;I'll use a layer of house locations and Tax Districts for my example. Here in orange are all the tax districts (there are 4 of them) with a particular value in their "Park District" field.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1614193226290.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/6813i3DDE40A5BDB91FF8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1614193226290.png" alt="jcarlson_0-1614193226290.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;// Get park dist ID
var p_id = $feature.park

// Filter layer for all matching park IDs
var dists = Filter($layer, "park = @p_id")
Console(Count(dists) + ' districts')

// Houses layer
var houses = FeatureSetByName($map,"CAMA ")

// Instantiate final count at 0
var final_count = 0

// Iterate over dists FeatureSet and get intersected houses for each
for(var d in dists){
    var h_count = Count(Intersects(houses, d))
    Console(h_count + ' houses')
    
    final_count += h_count
}

Console('Total: ' + final_count)
return final_count&lt;/LI-CODE&gt;&lt;P&gt;Which returns:&lt;/P&gt;&lt;PRE&gt;CONSOLE:&lt;BR /&gt;4 districts&lt;BR /&gt;21 houses&lt;BR /&gt;48 houses&lt;BR /&gt;0 houses&lt;BR /&gt;9 houses&lt;BR /&gt;&lt;BR /&gt;RESULT:&lt;BR /&gt;78&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Depending on how many points and districts we're talking about, your popup expression could be evaluating dozens of separate intersections, but this should work.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 19:33:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030154#M38651</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-02-24T19:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to count points intersecting multiple polygons</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030166#M38652</link>
      <description>&lt;P&gt;Yes sir, that worked perfectly!&amp;nbsp; Thank you, I really appreciate the help!&lt;/P&gt;&lt;P&gt;Funny, I too tried the union.&amp;nbsp; My logic was to turn the featureset into a single polygon.&amp;nbsp; Seems this isn;t an option.&lt;/P&gt;&lt;P&gt;Clearly I need to do some researching on for loops in Arcade.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 19:55:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1030166#M38652</guid>
      <dc:creator>JasonGlidewell</dc:creator>
      <dc:date>2021-02-24T19:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to count points intersecting multiple polygons</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1203976#M47486</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/290195"&gt;@JasonGlidewell&lt;/a&gt;&amp;nbsp;&amp;amp;&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;&lt;P&gt;I'm fairly new to writing code and can't seem to get this to work for me. I only have two hosted feature layers that I want to intersect. I can't write the Arcade Expression correctly for a Pop-Up but can't figure out how to get it to work in a Data Expression. Below is the Data Expression I wrote. I want to count how many NNO locations are in each of the Boundaries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var boundaries = FeatureSetByPortalItem(Portal('https://arcgis.com/'),'a1795cc14f9744d68787f649a7865715', 0, ['*'], true);
var nno = FeatureSetByPortalItem(Portal('https://arcgis.com/'),'6d13be8f482e434ea129f751c00385b0', 0, ['*'], true);  
   
var intcount = Count(Intersects(boundaries,nno));

return intcount&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error that I got when I tested it.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JerrySneary_0-1660771481276.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48865i0263BBB88F066478/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JerrySneary_0-1660771481276.png" alt="JerrySneary_0-1660771481276.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I even tried using&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;'s code and swapping in my feature layers but that doesn't work either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var dists = FeatureSetByPortalItem(Portal('https://arcgis.com/'),'a1795cc14f9744d68787f649a7865715', 0,['*'],true);

// Houses layer
var houses = FeatureSetByPortalItem(Portal('https://arcgis.com/'),'6d13be8f482e434ea129f751c00385b0',0,['*'],true);

// Instantiate final count at 0
var final_count = 0

// Iterate over dists FeatureSet and get intersected houses for each
for(var d in dists){
    var h_count = Count(Intersects(houses, d))
    Console(h_count + ' houses')
    
    final_count += h_count
}

Console('Total: ' + final_count)
return final_count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is the error I got when I tested it:&amp;nbsp;&lt;SPAN class=""&gt;Execution Error:&lt;/SPAN&gt;&lt;SPAN&gt;Error&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Can you guys help point me in the right direction.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Jerry&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 21:28:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1203976#M47486</guid>
      <dc:creator>JerrySneary</dc:creator>
      <dc:date>2022-08-17T21:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression to count points intersecting multiple polygons</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1206546#M47584</link>
      <description>&lt;P&gt;To anyone who is viewing this post. I was able to get the intersects to work with a count and sum but the problem I have now is that it is very slow to load.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var boundaries = FeatureSetByPortalItem(
    Portal('https://arcgis.com/'),
    'a1795cc14f9744d68787f649a7865715',
    1);
    
var nno = FeatureSetByPortalItem(
    Portal('https://arcgis.com/'),
    '6d13be8f482e434ea129f751c00385b0',
    0);
    
var outputDict = {'fields': [
    { 'name': 'MEMBER', 'type': 'esriFieldTypeString'},
    { 'name': 'Type', 'type': 'esriFieldTypeString'},
    { 'name': 'DISTRICT', 'type': 'esriFieldTypeString'},
    { 'name': 'District_Sort', 'type': 'esriFieldTypeString'},
    { 'name': 'NNO_Count', 'type': 'esriFieldTypeInteger'},
    { 'name': 'NNO_Attendance', 'type': 'esriFieldTypeInteger'}], 
    'geometryType': '', 'features': []};

var index = 0;

for (var boundary in boundaries) {
   var nnoint = Intersects(boundary,nno)
   var nnocount = Count(nnoint)
   var nnosum = Sum(nnoint, 'Expected_Attendance')
   outputDict.features[index++] = { 
            'attributes': {'MEMBER': boundary['MEMBER'],
            'Type': boundary['Type'],
            'DISTRICT': boundary['DISTRICT'],
            'District_Sort': boundary['District_Sort'],
            'NNO_Count': nnocount,
            'NNO_Attendance': nnosum}
            
}}

return FeatureSet(Text(outputDict));&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 25 Aug 2022 21:12:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-to-count-points-intersecting/m-p/1206546#M47584</guid>
      <dc:creator>JerrySneary</dc:creator>
      <dc:date>2022-08-25T21:12:04Z</dc:date>
    </item>
  </channel>
</rss>

