<?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: Count Points in Polygon and symbolize on number of occurrences in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060478#M73241</link>
    <description>&lt;P&gt;I found this for python and I think it will work but I have to loop through each time with a different species name.&amp;nbsp; The example just calculates the total number of points...&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/289273/counting-points-within-polygon-with-arcpy" target="_blank"&gt;https://gis.stackexchange.com/questions/289273/counting-points-within-polygon-with-arcpy&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CAN I DO THIS?&lt;/P&gt;&lt;P&gt;I can create a list of all the unique Species Names&lt;/P&gt;&lt;P&gt;Then Step through each Species Name and set a definition query on the Points Layer&lt;/P&gt;&lt;P&gt;Use this DEFINITION query result and then get the counts and update a field with the count&lt;/P&gt;&lt;P&gt;Then move on to the next Species Name etc etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 May 2021 16:13:04 GMT</pubDate>
    <dc:creator>jaykapalczynski</dc:creator>
    <dc:date>2021-05-21T16:13:04Z</dc:date>
    <item>
      <title>Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1059845#M73202</link>
      <description>&lt;P&gt;I have an app that searches for a particular species from a point file&lt;/P&gt;&lt;P&gt;Once found it creates graphics for the point locations and grid polygons that encompass those points.&lt;/P&gt;&lt;P&gt;What I want to do now is symbolize those polygons based on how many points are found within them.&amp;nbsp; I am not sure how to approach this.&amp;nbsp; I think I would have to read through each polygon and determine how many points are in there and set the symbology?&lt;/P&gt;&lt;P&gt;So the result would be a graphics layer of polygons of varying color based on how many points are within them&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone have any ideas?&lt;/P&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="jaykapalczynski_0-1621508788062.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/13738i353FB2721B394175/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jaykapalczynski_0-1621508788062.png" alt="jaykapalczynski_0-1621508788062.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 11:07:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1059845#M73202</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-20T11:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1059984#M73218</link>
      <description>&lt;P&gt;I recently did a video on this type of thing.&lt;/P&gt;&lt;P&gt;&lt;div class="video-embed-center video-embed"&gt;&lt;iframe class="embedly-embed" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFWM35IfvjVs%3Ffeature%3Doembed&amp;amp;display_name=YouTube&amp;amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFWM35IfvjVs&amp;amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFWM35IfvjVs%2Fhqdefault.jpg&amp;amp;type=text%2Fhtml&amp;amp;schema=youtube" width="200" height="112" scrolling="no" title="Spatial Joins with ArcGIS JSAPI - You can do it, but do you want to" frameborder="0" allow="autoplay; fullscreen; encrypted-media; picture-in-picture;" allowfullscreen="true"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/P&gt;&lt;P&gt;Here is a codepen to look at&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/odoe/pen/vYxYxXm" target="_blank" rel="noopener"&gt;https://codepen.io/odoe/pen/vYxYxXm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In your case, since it's just counts, it's fairly straight forward, but could be an intensive task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const query = {
  returnGeometry: true,
};
const cityResults = await cityLayerView.queryFeatures(query);
const frsResults = await frsLayerView.queryFeatures(query);
const features = [];
let temp = [...frsResults.features];
let temp2 = [];
// the loop is where you could block UI.
// You loop over polygons, then each polygon
// loops over each point to check if it's contained.
// You can mitigate this by removing found points from
// array of points with Array.splice()
for (let feat of cityResults.features) {
  const graphic = feat.clone();
  graphic.attributes.count = 0;
  temp2 = [...temp];
  for (let i = 0; i &amp;lt; temp2.length; i++) {
    const x = temp[i];
    if (
      x &amp;amp;&amp;amp;
      graphic.geometry &amp;amp;&amp;amp;
      x.geometry &amp;amp;&amp;amp;
      graphic.geometry.contains(x.geometry)
    ) {
      graphic.attributes.count++;
      temp.splice(i, 1);
    }
  }
  features.push(graphic);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added a comment in there about the performance hit you can take and one way to mitigate it. If it's a lot of points, you might need to run this iteration in a worker.&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 15:34:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1059984#M73218</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-05-20T15:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060358#M73234</link>
      <description>&lt;P&gt;Thanks a bunch and you aint kidding that this is a heavy lift.&amp;nbsp; Shifting gears a bit....wondering if I can do this via python or something.&amp;nbsp; Run a script against the dataset....&lt;/P&gt;&lt;P&gt;Polygon Dataset with multiple fields for individual species&lt;/P&gt;&lt;P&gt;Run a script and have it count the number of point occurrences (species specific) in each polygon for Species A and write the number in the corresponding field.&amp;nbsp; Then do this for every species.&amp;nbsp; Then I have a polygon FC that I can symbolize by a given field.&amp;nbsp; This should do what I want and not have to do it on the fly.&lt;/P&gt;&lt;P&gt;Do you know of any examples to accomplish this via python or geoprocessing tools?&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 12:14:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060358#M73234</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-21T12:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060427#M73238</link>
      <description>&lt;P&gt;I found this but I need something that I can run and let it go through everything....this is far to manual...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/264697/counting-number-of-points-differing-in-specific-attribute-within-polygon-in-arcg" target="_blank"&gt;https://gis.stackexchange.com/questions/264697/counting-number-of-points-differing-in-specific-attribute-within-polygon-in-arcg&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 14:35:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060427#M73238</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-21T14:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060433#M73239</link>
      <description>&lt;P&gt;Why not just count the number of results (points) you get when querying the specific species &lt;EM&gt;before&lt;/EM&gt; you create the polygon? Then you can add it as an attribute on the polygon graphic when you create it and symbolize with that.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 14:46:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060433#M73239</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-05-21T14:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060478#M73241</link>
      <description>&lt;P&gt;I found this for python and I think it will work but I have to loop through each time with a different species name.&amp;nbsp; The example just calculates the total number of points...&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/289273/counting-points-within-polygon-with-arcpy" target="_blank"&gt;https://gis.stackexchange.com/questions/289273/counting-points-within-polygon-with-arcpy&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CAN I DO THIS?&lt;/P&gt;&lt;P&gt;I can create a list of all the unique Species Names&lt;/P&gt;&lt;P&gt;Then Step through each Species Name and set a definition query on the Points Layer&lt;/P&gt;&lt;P&gt;Use this DEFINITION query result and then get the counts and update a field with the count&lt;/P&gt;&lt;P&gt;Then move on to the next Species Name etc etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 16:13:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060478#M73241</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-21T16:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060492#M73242</link>
      <description>&lt;P&gt;I should have asked this to start, but if you are using Online or Enterprise, you can use the Summarize Within analysis tool in the MapViewer Classic to do this. It will do counts and stats for you.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ReneRubalcava_0-1621615200701.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/13885i45712B7C8FE86C15/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ReneRubalcava_0-1621615200701.png" alt="ReneRubalcava_0-1621615200701.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But you're on the right track, pre-processing is definitely the way to go if you can. I am not strong with Python though, I can fake it when I need to.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 16:40:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060492#M73242</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-05-21T16:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060493#M73243</link>
      <description>&lt;P&gt;If using Python, I would use &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/dissolve.htm" target="_self"&gt;Dissolve&lt;/A&gt;. You can specify a Statistics Field with count, to count the number of dissolved points for each species (by name or id or whatever key field you have). Note that&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;If the&lt;SPAN class="uicontrol"&gt;Input Features&lt;/SPAN&gt;geometry type is either point or multipoint and&lt;SPAN class="uicontrol"&gt;Create multipart features&lt;/SPAN&gt;is checked (&lt;SPAN class="usertext"&gt;MULTI_PART&lt;/SPAN&gt;in Python), the output will be a multipoint feature class. Otherwise, if&lt;SPAN class="uicontrol"&gt;Create multipart features&lt;/SPAN&gt;is unchecked (&lt;SPAN class="usertext"&gt;SINGLE_PART&lt;/SPAN&gt;in Python), the output will be a point feature class.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So this would give you a new output feature class with a count field you can symbolize on.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 16:41:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060493#M73243</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-05-21T16:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060528#M73245</link>
      <description>&lt;P&gt;I am trying this....&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Loop though the Points Feature Class to get a list of Unique Species&lt;/LI&gt;&lt;LI&gt;After each iteration in the loop call a Function and pass that species name&lt;/LI&gt;&lt;LI&gt;In the Function I am just trying to get a count for that species.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;This should loop through for each species and get me a count.&lt;/P&gt;&lt;P&gt;ANY thoughts to why I am getting this error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR :&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "E:\ArcGIS_Server_aws\Python_Scripts\CountBBASpecies\CountSpeciesinPolygon.py", line 61, in &amp;lt;module&amp;gt;&lt;BR /&gt;uniques = unique_values(expressionValue, species)&lt;BR /&gt;File "E:\ArcGIS_Server_aws\Python_Scripts\CountBBASpecies\CountSpeciesinPolygon.py", line 47, in unique_values&lt;BR /&gt;for row in cursor:&lt;BR /&gt;RuntimeError: Underlying DBMS error [[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near 'Vireo'.] [BBA2.DBO.JaysTest_BirdLocations_Test]&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CODE:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# COUNT NUMBER OF RECORDS FOR EACH SPECIES
def unique_values(table, field):
    expressionValue = table
    species = field
    with arcpy.da.SearchCursor(Points, "common_name", where_clause=expressionValue) as cursor:
      for row in cursor:
        print row[0]
    
# GET UNIQUE SPECIES FROM FEATURE CLASS
for feature in arcpy.ListFeatureClasses():
    with arcpy.da.SearchCursor(Points,"common_name", sql_clause=(None,'ORDER BY common_name DESC')) as SCur:
      for row in SCur:
        if not row[0] in bList: # if not in list then add to list
          bList.append(row[0])
          species = row[0]
          expressionValue = "common_name = " + species
          # PASS species name to Function to Count
          uniques = unique_values(expressionValue, species)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 17:38:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060528#M73245</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-21T17:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060530#M73246</link>
      <description>&lt;P&gt;your expressionValue needs to put quotes around the species to be a valid SQL statement&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;expressionValue = "common_name = '{}'".format(species)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 21 May 2021 17:42:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060530#M73246</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-05-21T17:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060535#M73248</link>
      <description>&lt;P&gt;OK I think I have it working now...Now onto the next piece&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# COUNT NUMBER OF RECORDS FOR EACH SPECIES
def unique_values(table, field):
expressionValue = table
species = field
expressionValue2 = "common_name = '{}'".format(species)
with arcpy.da.SearchCursor(bba_Points, "common_name", where_clause=expressionValue2) as cursor:
for row in cursor:
print row[0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 17:47:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060535#M73248</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-21T17:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060544#M73249</link>
      <description>&lt;P&gt;OK I am trying to get a tally of each species and their counts...&lt;/P&gt;&lt;P&gt;But I just get a big list of each one as it passes through the loop....not totals....where am I going wrong&lt;/P&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="jaykapalczynski_0-1621620635827.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/13891i1E9A75B85416AF61/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jaykapalczynski_0-1621620635827.png" alt="jaykapalczynski_0-1621620635827.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;LI-CODE lang="python"&gt;# COUNT NUMBER OF RECORDS FOR EACH SPECIES
def unique_values(table, field):
    resultspecies = ""
    expressionValue = table
    species = field
    expressionValue2 = "common_name = '{}'".format(species)
    with arcpy.da.SearchCursor(Points, "common_name", where_clause=expressionValue2) as cursor:
      for row in cursor:
        resultspecies = row[0]
        rowCount = 0
        rowCount = rowCount + 1
    print "There are " + str(rowCount) + " of " + resultspecies

    
# GET UNIQUE SPECIES FROM TABLE
for feature in arcpy.ListFeatureClasses():
    #print feature
    with arcpy.da.SearchCursor(Points,"common_name", sql_clause=(None,'ORDER BY common_name DESC')) as SCur:
      for row in SCur:
        if not row[0] in bList: # if not in list then add to list
          bList.append(row[0])
          species = row[0]
          expressionValue = "common_name = '{}'".format(species)
        uniques = unique_values(expressionValue, species)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 18:11:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060544#M73249</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-21T18:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060555#M73250</link>
      <description>&lt;P&gt;Now that I have the Unique Species I need to pass them 1 by one to a function that will either QUERY the point Feature Class and do something to JUST those records or Create a DEFINITION query and do something with just those point records.&lt;/P&gt;&lt;P&gt;In the DEF I have a unique Species name sent to it.&amp;nbsp; Whats the best way to query the points Feature Class and just work with those records?&lt;/P&gt;&lt;P&gt;Query or Definition Query....any examples?&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 18:45:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060555#M73250</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-21T18:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060556#M73251</link>
      <description>&lt;P&gt;If I could figure out how to create a definition query based on a field value WHERE clause and then run code against just those records I would be ecstatic....&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 18:50:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060556#M73251</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-21T18:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Count Points in Polygon and symbolize on number of occurrences</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060929#M73258</link>
      <description>&lt;P&gt;First off THANK YOU ALL FOR YOUR THOUGHTS AND COMMENTS&lt;/P&gt;&lt;P&gt;They really helped steer me in the path and direction I took...&lt;/P&gt;&lt;P&gt;OK this is what I did and its working....&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a List of Unique types in the point Feature Class&lt;/LI&gt;&lt;LI&gt;Call Function that reads this List by looping though that created unique list&lt;/LI&gt;&lt;LI&gt;Each loop takes those unique value and calls another function that gets the correct field name and for that TYPE&lt;/LI&gt;&lt;LI&gt;It then passes the (expression, type name and field name) to the last function which processes the data&lt;/LI&gt;&lt;LI&gt;In the last function I am selecting the point records that match that TYPE value, I then create a new Point&amp;nbsp; Layer that has only those records.&amp;nbsp; I use that New Layer to Spatial Join, Statistics Analysis, Join Field Management, Calculate Field Management to Update the Polygon Layer with the number of occurrences for that TYPE in the Correct Field name that was set in the If Then Else&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I used the If Then to change the TYPE value in the Data to a value that would work as a field name...so I can update the Polygon Layer as some of the TYPE values were really long&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

arcpy.env.workspace = r"E:/xxxxx/xxxx/Projects/xxx/xxx.sde"
Points = r"E:/xxxxx/xxxx/Projects/xxx/xxx.sde/Locations"
Grids = r"E:/xxxxx/xxxx/Projects/xxx/xxx.sde/Grids"

print "Started"

bList = []
expression = ""
expressionValue = ""
type= ""
rowCount = 0
uniquetypeList = []
countList = []   
txt_list = ""


# COUNT NUMBER OF RECORDS FOR EACH TYPE
def getFieldName(type):
    if type == "Needs Repair":
        return "NeedsRepair"
    elif type == "Broken":
        return "Broken"
    elif type == "Needs Replacement":
        return "NeedsReplacement"
    elif type == "Schedule Fix":
        return "ScheduleFix"
    else:
        return "nothing"

def processTypeUpdate(expressionValue, typeValues, fieldName):

    expressionValue2 = expressionValue
    typeName = typeValues
    fieldUpdateName = fieldName

    rowCount = 0
        
    arcpy.Delete_management('in_memory/PointsInPolys')   
    arcpy.Delete_management('in_memory/SS_PointsInPolys')
    arcpy.Delete_management('points_lyr')
    arcpy.Delete_management('points_lyr2')

    arcpy.MakeFeatureLayer_management(r'E:/xxxxx/xxxx/Projects/xxx/xxx.sde/Locations_Test', 'points_lyr')
    results = arcpy.SelectLayerByAttribute_management ('points_lyr', 'NEW_SELECTION', expressionValue2)
    arcpy.MakeFeatureLayer_management(results, 'points_lyr2')

    polygonID = "ID" ## unique polygon field name
    countField = fieldUpdateName  # The field name in the Grids FC to update 
    expression = "recalc(!FREQUENCY!)"
    codeblock = """def recalc(freq):
        if freq &amp;gt; -1:
            return freq
        else:
            return 0"""

    arcpy.SpatialJoin_analysis('points_lyr2', Grids, "in_memory/PointsInPolys")
        ### case field returns count per unique UID
    arcpy.Statistics_analysis ("in_memory/PointsInPolys", "in_memory/SS_PointsInPolys", [[polygonID, "Count"]], polygonID)
    arcpy.JoinField_management(Grids, polygonID, "in_memory/SS_PointsInPolys", polygonID, "FREQUENCY")
    arcpy.CalculateField_management(Grids, countField, expression, "PYTHON", codeblock)
    arcpy.DeleteField_management(Grids, "FREQUENCY")
    
    # GET THE CODES FROM THE RESULTS OF THE SELECTION
    rows = arcpy.SearchCursor('points_lyr2',"","","type_name")
    for row in rows:
        rowCount = rowCount + 1
        typeVal = str(row.type_name)  
        countList.append(typeVal)  
        txt_list = ','.join(countList)
    print "number of " + typeVal + " : " + str(rowCount)

    arcpy.Delete_management('in_memory/PointsInPolys')   
    arcpy.Delete_management('in_memory/SS_PointsInPolys')
    arcpy.Delete_management('points_lyr')
    arcpy.Delete_management('points_lyr2')  


    
# TAKE TYPE NAME AND GET THE CORRECT FIELD NAME
def processtypeNames(expressionValue, typeValues):
    type= str(typeValues)
    expressionValue2 = "type_name = '{}'".format(type)
    # GET THE CORRECT FIELD NAME
    fieldName = getFieldName(type)
    
    if fieldName == "nothing":
        print "No Value"
    else:
        # Call the function to actually update the Field Values
        uniques2 = processtypeUpdate(expressionValue2, type, fieldName)
        print "corrected field name is: " + fieldName
        

def uniquetypeList(uniquetypeValues):
    typeList = uniquetypeValues
    #print typeList
    for type in typeList:
        #print type
        expressionValue = "type_name = '{}'".format(type)
        uniques = processtypeNames(expressionValue, type)

    
# GET UNIQUE TYPS FROM FC CREATE LIST
for feature in arcpy.ListFeatureClasses():
    #print feature
    with arcpy.da.SearchCursor(Points,"type_name", sql_clause=(None,'ORDER BY type_name ASC')) as SCur:
      for row in SCur:
        if not row[0] in bList: # if not in list then add to list
          bList.append(row[0])
          type = row[0]
    del SCur
uniquetype = uniquetypeList(bList)&lt;/LI-CODE&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>Mon, 24 May 2021 18:51:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/count-points-in-polygon-and-symbolize-on-number-of/m-p/1060929#M73258</guid>
      <dc:creator>jaykapalczynski</dc:creator>
      <dc:date>2021-05-24T18:51:27Z</dc:date>
    </item>
  </channel>
</rss>

