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.
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)
I think what I need to do is to use the Contains() function and loop through each point in fs, find the polygon in poly_fs that it falls within, grab the value in the NAME field of poly_fs, and append it to the dictionary that I'm building that contains my modified fs table.
Seeking any advice on an efficient way to loop through this given that the geometry function may make this slow to execute anyway.
The only change that I've made to prepare for this new function is adding a new variable in line 13
//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;