Hello, I have an Arcade script for a Dashboards project that's meant to return any points that fall within a fire zone or a weather event (both polygons) and return information of that point and the areas they fall within. The script works with small sets of points but crashes if there's more than about 100 points, which is a problem because the feature set I'm using has about 150k points.
var portal = Portal("https://www.arcgis.com");
var fire_poly = FeatureSetByPortalItem(
portal,
'd957997ccee7408287a963600a77f61f',
1,
[
'IncidentName'
],
true
);
var weather_poly = FeatureSetByPortalItem(
portal,
'a6134ae01aad44c499d12feec782b386',
6,
[
'Event',
'Severity'
],
true
);
var pt_fs = FeatureSetByPortalItem(
portal,
'item_id_removed_for_security',
0,
[
'SAP_EQUIP_',
'SAP_STRUCT',
'TLINE_NM',
'SAP_FUNC_L',
'GIS_LAT',
'GIS_LONG'
],
true
);
var features = [];
var feat;
for (var pnt in pt_fs) {
var in_fire = [];
var in_event = [];
if (Count(Within(pnt, fire_poly)) > 0 || Count(Within(pnt, weather_poly)) > 0) {
for (var poly in fire_poly) {
if (Within(pnt, poly)) {
Push(in_fire, poly['IncidentName']);
}
}
for (var poly in weather_poly) {
if (Within(pnt, poly)) {
Push(in_event, poly['Severity'] + " " + poly['Event']);
}
}
feat = {
'attributes': {
'SAP_EQUIP': pnt['SAP_EQUIP_'],
'STRUCT_NO': pnt['SAP_STRUCT'],
'TLINE_NM': pnt['TLINE_NM'],
'FUNC_LOC': pnt['SAP_FUNC_L'],
'GIS_LAT': pnt['GIS_LAT'],
'GIS_LONG': pnt['GIS_LONG'],
'fire': IIf(IsEmpty(First(in_fire)), "N/A", Concatenate(in_fire, ", ")),
'weather_event': IIf(IsEmpty(First(in_event)), "N/A", Concatenate(in_event, ", "))
}
};
Push(features, feat);
}
}
var out_dict = {
'fields': [
{'name': 'SAP_EQUIP', 'alias': 'SAP Equipment ID', 'type': 'esriFieldTypeString'},
{'name': 'STRUCT_NO', 'alias': 'Structure Number', 'type': 'esriFieldTypeString'},
{'name': 'TLINE_NM', 'alias': 'Transmission Line', 'type': 'esriFieldTypeString'},
{'name': 'FUNC_LOC', 'alias': 'SAP Functional Location', 'type': 'esriFieldTypeString'},
{'name': 'GIS_LAT', 'alias': 'Latitude', 'type': 'esriFieldTypeDouble'},
{'name': 'GIS_LONG', 'alias': 'Longitude', 'type': 'esriFieldTypeDouble'},
{'name': 'fire', 'alias': 'Name of Fire', 'type': 'esriFieldTypeString'},
{'name': 'weather_event', 'alias': 'Weather Event', 'type': 'esriFieldTypeString'}
],
'geometryType': '',
'features': features
};
return FeatureSet(out_dict);From testing it, along with help from @KenBuja in my previous post Execution Error in Arcade Script , it seems to usually crash at the conditional on line 46. I've been trying to find a way to create a subset of the points that fall within the 2 polygons before starting the main loop, eliminating the need for the conditional and using a smaller set of points, by using Union and Within but it seems that Union only works with individual features and not with feature sets.
Is there some way of making this script more efficient that I'm overlooking? Is it possible to return an array of features from a feature set to make my idea with Union work?