<?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: Spatial join for serial chart - efficiently using the Contains function in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145128#M5855</link>
    <description>&lt;P&gt;Since you're working with points (that is, there's no possibility for partial containment), you can just do &lt;STRONG&gt;Intersects&lt;/STRONG&gt;. Throw these lines into your for loop:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var xs_poly = First(Intersects(feature, poly_fs))

var poly_name = xs_poly['NAME']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then pipe &lt;STRONG&gt;poly_name&lt;/STRONG&gt; into the feature attributes. Oh, and make a field for it in your dictionary, obviously.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Feb 2022 13:51:30 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-02-17T13:51:30Z</dc:date>
    <item>
      <title>Spatial join for serial chart - efficiently using the Contains function</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145055#M5854</link>
      <description>&lt;P&gt;Hi community. I have the data expression below pulling some data from one of my hosted layers with point features, and reformatting it to drive some charts in my Dashboard. So far so good.&lt;/P&gt;&lt;P&gt;What I'm needing to do now is add an attribute to every point/record based on the REGION polygon that it falls within (a good old spatial join)&lt;/P&gt;&lt;P&gt;I think what I need to do is to use the Contains() function and loop through each point in &lt;STRONG&gt;fs&lt;/STRONG&gt;, find the polygon in &lt;STRONG&gt;poly_fs&lt;/STRONG&gt; that it falls within, grab the value in the&amp;nbsp;NAME field of&amp;nbsp;poly_fs, and append it to the dictionary that I'm building that contains my modified&lt;STRONG&gt; fs&lt;/STRONG&gt; table.&lt;/P&gt;&lt;P&gt;Seeking any advice on an efficient way to loop through this given that the geometry function may make this slow to execute anyway.&lt;/P&gt;&lt;P&gt;The only change that I've made to prepare for this new function is adding a new variable in line 13&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//ground actions - time of day
//obtains the hour in military (long) format from the creation_date field

// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz



// Create a FeatureSet from the Feature Layer containing the Ground action data.
var fs =FeatureSetByPortalItem(Portal('https://gis.ABCCD.au/portal'), '0116ef7ee89c4de0829fe554315e2177', 0)

var poly_fs =FeatureSetByPortalItem(Portal('https://gis.ABCCD.au/portal'), 'e09bf35374724d04b413bbb09db9ff40', 3)


var outDict = { 
  'fields': [{ 'name': 'hr_num', 'type': 'esriFieldTypeInteger'},
  {'name': 'OBJECTID','type': 'esriFieldTypeInteger'},
  {'name': 'creation_date','type': 'esriFieldTypeDate'},
  {'name': 'militaryhr', 'type': 'esriFieldTypeString'},
  {'name': 'ABC_Organisation','type': 'esriFieldTypeString'},
  {'name': 'Operation_Number','type': 'esriFieldTypeString'},
  {'name': 'species', 'type': 'esriFieldTypeString'}], 
  'geometryType': '', 
  'features': [] 
}; 

var index = 0; 

for (var feature in fs) { 

    outDict.features[index] = { 
        'attributes': { 
            'hr_num': Hour(feature['creation_date']), 
            'objectid': feature['OBJECTID'],
            'creation_date': number(feature['creation_date']),
            'militaryhr': Text(feature['creation_date'], 'HH'),
            'ABC_Organisation': feature['ABC_Organisation'],
            'Operation_Number': feature['Operation_Number'],
            'species': feature['species_common_name'] 
        }} 
    index++;} 

// Convert dictionary to feature set. 
var fs_dict = FeatureSet(Text(outDict)); 

// Return data 
return fs_dict;&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>Thu, 17 Feb 2022 08:33:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145055#M5854</guid>
      <dc:creator>ChrisH2</dc:creator>
      <dc:date>2022-02-17T08:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial join for serial chart - efficiently using the Contains function</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145128#M5855</link>
      <description>&lt;P&gt;Since you're working with points (that is, there's no possibility for partial containment), you can just do &lt;STRONG&gt;Intersects&lt;/STRONG&gt;. Throw these lines into your for loop:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var xs_poly = First(Intersects(feature, poly_fs))

var poly_name = xs_poly['NAME']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then pipe &lt;STRONG&gt;poly_name&lt;/STRONG&gt; into the feature attributes. Oh, and make a field for it in your dictionary, obviously.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 13:51:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145128#M5855</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-02-17T13:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial join for serial chart - efficiently using the Contains function</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145488#M5861</link>
      <description>&lt;P&gt;thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;that's almost got me over the line. I was chasing an error until I realised that the test polygon dataset that I'm using doesn't always completely cover the point dataset. When I switch over to the real polygon dataset this should be unlikely, but there's still the chance that a user may add a point over the ocean somewhere, so best I counter this in the code!! Thus I've been trying to check for where the Intersects returns a null but without much success&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I was trying to do with line 42 was to insert "None" into the table if there wasn't a result from the point in polygon intersection, otherwise use the real value from xs_poly.&amp;nbsp; Line 43 will work, but when I switch this out and replace it with line 42 still fails everytime time a 0 is encountered&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//ground action - time of day
//obtains the hour in military (long) format from the creation_date field

// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz



// Create a FeatureSet from the Feature Layer containing the Ground action data.
var fs =FeatureSetByPortalItem(Portal('https://gis.ABCD.au/portal'), '0116ef7ee89c4de0829fe554315e2177', 0)

var poly_fs =FeatureSetByPortalItem(Portal('https://gis.ABCD.au/portal'), 'e09bf35374724d04b413bbb09db9ff40', 3)


var outDict = { 
  'fields': [{ 'name': 'hr_num', 'type': 'esriFieldTypeInteger'},
  {'name': 'OBJECTID','type': 'esriFieldTypeInteger'},
  {'name': 'creation_date','type': 'esriFieldTypeDate'},
  {'name': 'militaryhr', 'type': 'esriFieldTypeString'},
  {'name': 'actioner_Organisation','type': 'esriFieldTypeString'},
  {'name': 'Operation_Number','type': 'esriFieldTypeString'},
  {'name': 'species', 'type': 'esriFieldTypeString'}, 
  {'name': 'pvregion', 'type': 'esriFieldTypeString'}], 
  'geometryType': '', 
  'features': [] 
}; 

var index = 0; 


for (var feature in fs) { 

    var int_poly = Intersects(feature, poly_fs)
	var xs_poly = First(int_poly)
	//var poly_name = xs_poly['VEA_NAME']
	
	var countPolys = Count(int_poly)
	
	Console(countPolys)
	
  //  var poly_name = iif(countPolys&amp;gt;0,'None',xs_poly['VEA_NAME'])
	var poly_name = iif(countPolys&amp;gt;0,'PolygonIntersected','NoPolygonintersection')
	
    Console(poly_name)

    outDict.features[index] = { 
        'attributes': { 
            'hr_num': Hour(feature['creation_date']), 
            'objectid': feature['OBJECTID'],
            'creation_date': number(feature['creation_date']),
            'militaryhr': Text(feature['creation_date'], 'HH'),
            'actioner_Organisation': feature['actioner_Organisation'],
            'Operation_Number': feature['Operation_Number'],
            'species': feature['species_common_name'],
			'pvregion': poly_name
        }} 
    index++;} 

// Convert dictionary to feature set. 
var fs_dict = FeatureSet(Text(outDict)); 

// Return data 
return fs_dict;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 05:32:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145488#M5861</guid>
      <dc:creator>ChrisH2</dc:creator>
      <dc:date>2022-02-18T05:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial join for serial chart - efficiently using the Contains function</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145565#M5862</link>
      <description>&lt;P&gt;Try using a real if/else statement, rather than iif.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var int_poly = Intersects(feature, poly_fs)

if (Count(int_poly) &amp;gt; 0){
    var poly_name = First(int_poly)['VEA_NAME']
} else {
    var poly_name = 'None'
}&lt;/LI-CODE&gt;&lt;P&gt;Any luck?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 13:42:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145565#M5862</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-02-18T13:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial join for serial chart - efficiently using the Contains function</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145922#M5868</link>
      <description>&lt;P&gt;perfect!! Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;Hope you have a lovely weekend wherever you are!&lt;/P&gt;&lt;P&gt;final code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//ground action - time of day
//obtains the hour in military (long) format from the creation_date field

// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz



// Create a FeatureSet from the Feature Layer containing the Ground action data.
var fs =FeatureSetByPortalItem(Portal('https://gis.ABCD.au/portal'), '0116ef7ee89c4de0829fe554315e2177', 0)

var poly_fs =FeatureSetByPortalItem(Portal('https://gis.ABCD.au/portal'), 'e09bf35374724d04b413bbb09db9ff40', 3)


var outDict = { 
  'fields': [{ 'name': 'hr_num', 'type': 'esriFieldTypeInteger'},
  {'name': 'OBJECTID','type': 'esriFieldTypeInteger'},
  {'name': 'creation_date','type': 'esriFieldTypeDate'},
  {'name': 'militaryhr', 'type': 'esriFieldTypeString'},
  {'name': 'actioner_Organisation','type': 'esriFieldTypeString'},
  {'name': 'Operation_Number','type': 'esriFieldTypeString'},
  {'name': 'species', 'type': 'esriFieldTypeString'}, 
  {'name': 'pvregion', 'type': 'esriFieldTypeString'}], 
  'geometryType': '', 
  'features': [] 
}; 

var index = 0; 


for (var feature in fs) { 

    var int_poly = Intersects(feature, poly_fs)
	var xs_poly = First(int_poly)
	
	
   // If statement to check if there is a successful point in polygon intersection. 
   // If successful, then relevant values from the VEA_NAME field are appended to the Ground action table. If not, then insert 'None' into the table.

	if (Count(int_poly) &amp;gt; 0){
		var poly_name = First(int_poly)['VEA_NAME']
	} else {
		var poly_name = 'None'
	}

    outDict.features[index] = { 
        'attributes': { 
            'hr_num': Hour(feature['creation_date']), 
            'objectid': feature['OBJECTID'],
            'creation_date': number(feature['creation_date']),
            'militaryhr': Text(feature['creation_date'], 'HH'),
            'actioner_Organisation': feature['actioner_Organisation'],
            'Operation_Number': feature['Operation_Number'],
            'species': feature['species_common_name'],
			'pvregion': poly_name
        }} 
    index++;} 

// Convert dictionary to feature set. 
var fs_dict = FeatureSet(Text(outDict)); 

// Return data 
return fs_dict;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Feb 2022 04:59:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/spatial-join-for-serial-chart-efficiently-using/m-p/1145922#M5868</guid>
      <dc:creator>ChrisH2</dc:creator>
      <dc:date>2022-02-19T04:59:38Z</dc:date>
    </item>
  </channel>
</rss>

