Hi -
I'm hoping for some help with my syntax. The first part of this expression is working well. I can not figure out where I am going wrong starting at line 105 with the Clip function. I've verified everything above this is working thru use of Console, but can't get any further.
I am wondering if because I am trying to feed Clip a FeatureSet instead of a $feature (as shown in the documentation) I am getting an error.
Do any of the Arcade wizards on here have suggestions? @jcarlson @XanderBakker @JohannesLindner
The goal here is to use Dashboards/Arcade to provide non-GIS people with information needed for reporting w/o having to open Pro and do geoprocessing, or without needing a Creator license to use the AGOL Spatial Analysis tools. I was hoping this might be a viable workaround.
Thank you!
// custom memorize function to increase performance of featureset
function Memorize(fs) {
var temp_dict = {
fields: Schema(fs)['fields'],
geometryType: Schema(fs).geometryType,
features: []
}
for (var f in fs) {
var attrs = {}
for (var attr in f) {
attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
}
Push(
temp_dict['features'],
{attributes: attrs, geometry: Geometry(f)}
)
}
return FeatureSet(Text(temp_dict))
}
// variable to define the portal URL
var portal = Portal("https://mass-eoeea.maps.arcgis.com");
// Quabbin Drainage Basins
var QUAB = FeatureSetByPortalItem(portal, "6b878308af9646af8239d2251a26fe15", 0, ['DISTRICT', 'SUB_BASIN', 'AREA_ACRES'], true);
// Ware River Drainage Basins
var WARE = FeatureSetByPortalItem(portal, "60c237cb9b53472a91c331785c035954", 0, ['DISTRICT', 'SUBDISTRICT_BASIN', 'Acres'], true);
// Wachusett Subbasins
var WACH = FeatureSetByPortalItem(portal, "702f5bf477d7451aa27abc939c9b5b65", 0, ['Big_Wshed', 'Wshed', 'Area_Acres'], true);
// Create a FeatureSet with all Basins from Quabbin, Ware and Wachusett
var int_dict = {
fields: [
{name: "DistrictName", type: "esriFieldTypeString"},
{name: "BasinName", type: "esriFieldTypeString"},
{name: "Acres", type: "esriFieldTypeDouble"},
],
geometryType: "esriGeometryPolygon",
"spatialReference": {
"wkid":102100,
"latestWkid": 3857
},
features: [],
};
// Fill intermediate FeatureSet with Basin Info
var i = 0;
for (var q in QUAB) {
//Console(q)
int_dict.features[i] = {
attributes: {
'DistrictName': q["DISTRICT"],
'BasinName': q["SUB_BASIN"],
'Acres': q["AREA_ACRES"],
},
geometry: Geometry(q),
}
i++;
};
for (var w in WACH) {
int_dict.features[i] = {
attributes: {
'DistrictName': w["Big_Wshed"],
'BasinName': w["Wshed"],
'Acres': w["Area_Acres"],
},
geometry: Geometry(w),
}
i++;
};
for (var r in WARE) {
int_dict.features[i] = {
attributes: {
'DistrictName': r["DISTRICT"],
'BasinName': r["SUBDISTRICT_BASIN"],
'Acres': r["Acres"],
},
geometry: Geometry(r),
}
i++;
};
//Console(Text(int_dict));
//return FeatureSet(Text(int_dict));
var basinDict = FeatureSet(Text(int_dict));
//Console(Text(basinDict));
// DWSP Fee OpenSpace
var dwspOS = Memorize(Filter(FeatureSetByPortalItem(portal, "807b0f1e96444ec28fd06270fb8d3488", 0, ['GIS_ACRES'], true), "OWNER_ABRV ='DCRW'"))
// create an empty feature array
var features = []
// clip dwspOS by int_dict features to determine number acres dwspOS per basin
for (var b in basinDict) {
// get the envelope of each basin feature within int_dict
var envelope = Extent(b)
// determine acres per envelope (basin)
// is clip function limited to working with a single feature rather than a collection of features?
var areaOS = Area(Clip(Geometry(dwspOS), envelope), 'acres')
Console(areaOS)
for (var a in areaOS) {
// do math to determine percent ownership dwspOS acres per basin
var pctOwn = Round(a/basinDict.Acres*100, 1)
//add to array
var new_f = {attributes: {
DistName: a[basinDict.DistrictName],
Basin: a[basinDict.BasinName],
AcresBasin: a[basinDict.Acres],
AcresDWSP: areaOS,
PctOwnership: pctOwn,
}}
Push(features, new_f)
}
}
Console(Text(new_f));
// create a FeatureSet with all of these features
var combined_dict = {
fields: [
{name: "DistName", type: "esriFieldTypeString"},
{name: "Basin", type: "esriFieldTypeString"},
{name: "AcresBasin", type: "esriFieldTypeDouble"},
{name: "AcresDWSP", type: "esriFieldTypeDouble"},
{name: "PctOwnership", type: "esriFieldTypeDouble"},
],
geometryType: "esriGeometryPolygon",
"spatialReference": {
"wkid":102100,
"latestWkid": 3857
},
features: features,
}
//Console(Text(combined_dict));
//return FeatureSet(Text(combined_dict));
return combined_dict