<?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 Data Expression - Create dictionary from Geometry in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-data-expression-create-dictionary-from/m-p/1156467#M45023</link>
    <description>&lt;P&gt;OK. I was able to get it to work finally. The issue was that I was not passing in a FeatureSet for the inside geometry (points) as part of the Contains function, which caused an error. I looped through the returned points after creating the list of points that intersected each polygon. Working code below.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Create empty feature array and feat object for output
var features = [];
var feat;



// Iterate over districts
for (var poly in poly_fs) {

    // Filter points by polygon
    var pts = Contains(poly, pt_fs);
    
    for (var pt in pts) {
    
        // Create feature with aggregated values
        feat = { 
            'attributes': { 
                'district': poly['ORG_UNIT'], 
                'fire': pt['FIRE_NUMBER']
            }
        };
        
        // Push feature into array
        Push(features, feat);
    };
};

// Create dict for output FeatureSet
var out_dict = { 
    'fields': [
        {'name': 'district', 'alias': 'Districts', 'type': 'esriFieldTypeString'},
        {'name': 'fire', 'alias': 'Fire Number', 'type': 'esriFieldTypeString'}
    ],
  'geometryType': '', 
  'features': features 
}; 

// Convert dictionary to feature set. 
return FeatureSet(Text(out_dict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Mar 2022 22:58:28 GMT</pubDate>
    <dc:creator>SteveRichards1</dc:creator>
    <dc:date>2022-03-22T22:58:28Z</dc:date>
    <item>
      <title>Arcade Data Expression - Create dictionary from Geometry</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-data-expression-create-dictionary-from/m-p/1156443#M45020</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am new to Arcade Data Expressions and I would like to return a Feature Set that contains all of the "Fire Numbers" and the corresponding "District" (polygon) that it falls within. I started off with the code in the below link and tried to modify it a little to make it work for my situation. Mainly, I added an additional sub "for-loop" to iterate through the points and for each point determine the district it falls within and put that into an array and finally a dictionary.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/SpatialAggregation.md" target="_blank" rel="noopener"&gt;https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/SpatialAggregation.md&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The Data Expression will be used within a Category Selector so I can filter the fire numbers out that only fall within a specific district (a district selector would filter out this data expression feature set to show only relevant fire numbers )&lt;/P&gt;&lt;P&gt;I am not able to get this to work and I am unsure what to try next. Can anyone potentially guide me in the right direction or maybe show another approach? Any help is very much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Portal
var portal = Portal('https://governmentofbc.maps.arcgis.com/');

// Create FeatureSet for polygons
var poly_fs = FeatureSetByPortalItem(
    portal,
    '5ccd439dd835451aa304468ebdce0427',
    58,
    [
        'ORG_UNIT'
    ],
    true
);

// Create Featureset for points
var pt_fs = FeatureSetByPortalItem(
    portal,
    '397a1defe7f04c2b8ef6511f6c087dbf',
    0,
    [
        'FIRE_NUMBER'
    ],
    true
);

// Create empty feature array and feat object for output
var features = [];
var feat;

// Iterate over fire points
for (var pt in pt_fs) {
    // Iterate over districts
    for (var poly in poly_fs) {
    
        // Filter points by polygon
        var pts = Contains(poly, pt);
        
        // Create feature with aggregated values
        feat = { 
            'attributes': { 
                'district': poly['ORG_UNIT'], 
                'fire': pt['FIRE_NUMBER']
            }
        };
        
        // Push feature into array
        Push(features, feat);
    };
};

// Create dict for output FeatureSet
var out_dict = { 
    'fields': [
        {'name': 'district', 'alias': 'Districts', 'type': 'esriFieldTypeString'},
        {'name': 'fire', 'alias': 'Fire Number', 'type': 'esriFieldTypeString'}
    ],
  'geometryType': '', 
  'features': features 
}; 

// Convert dictionary to feature set. 
return FeatureSet(Text(out_dict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 22:23:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-data-expression-create-dictionary-from/m-p/1156443#M45020</guid>
      <dc:creator>SteveRichards1</dc:creator>
      <dc:date>2022-03-22T22:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression - Create dictionary from Geometry</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-data-expression-create-dictionary-from/m-p/1156467#M45023</link>
      <description>&lt;P&gt;OK. I was able to get it to work finally. The issue was that I was not passing in a FeatureSet for the inside geometry (points) as part of the Contains function, which caused an error. I looped through the returned points after creating the list of points that intersected each polygon. Working code below.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Create empty feature array and feat object for output
var features = [];
var feat;



// Iterate over districts
for (var poly in poly_fs) {

    // Filter points by polygon
    var pts = Contains(poly, pt_fs);
    
    for (var pt in pts) {
    
        // Create feature with aggregated values
        feat = { 
            'attributes': { 
                'district': poly['ORG_UNIT'], 
                'fire': pt['FIRE_NUMBER']
            }
        };
        
        // Push feature into array
        Push(features, feat);
    };
};

// Create dict for output FeatureSet
var out_dict = { 
    'fields': [
        {'name': 'district', 'alias': 'Districts', 'type': 'esriFieldTypeString'},
        {'name': 'fire', 'alias': 'Fire Number', 'type': 'esriFieldTypeString'}
    ],
  'geometryType': '', 
  'features': features 
}; 

// Convert dictionary to feature set. 
return FeatureSet(Text(out_dict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 22:58:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-data-expression-create-dictionary-from/m-p/1156467#M45023</guid>
      <dc:creator>SteveRichards1</dc:creator>
      <dc:date>2022-03-22T22:58:28Z</dc:date>
    </item>
  </channel>
</rss>

