I'm struggling to work out what I'm doing wrong trying to convert this Dictionary to a FeatureSet. I'm getting an invalid parameter error.
var fs = FeatureSetByPortalItem(
portal,
id,
0,
fields,
False
)
var combinedFeatures = [];
for (var f in fs) {
Push(combinedFeatures, {
"Variety": f["variety1"],
"Area": f["var1_perc"]
});
Push(combinedFeatures, {
"Variety": f["variety2"],
"Area": f["var2_perc"]
});
Push(combinedFeatures, {
"Variety": f["variety3"],
"Area": f["var3_perc"]
});
};
var schema = { fields: [
{ name: "Variety", type: "esriFieldTypeString" },
{ name: "Area", type: "esriFieldTypeSmallInteger" }
]};
var d = Dictionary(Text(combinedFeatures, schema));
Console(d)
return FeatureSet(d)
My dictionary, as shown by Console(), looks like this:
{"0":{"Variety":null,"Area":0},"1":{"Variety":null,"Area":0},"2":{"Variety":null,"Area":0},"3":{"Variety":null,"Area":0},"4":{"Variety":null,"Area":0},"5":{"Variety":null,"Area":0},"6":{"Variety":null,"Area":0},"7":{"Variety":null,"Area":0},"8":{"Variety":null,"Area":0},"9":{"Variety":null,"Area":0},"10":{"Variety":null,"Area":0},"11":{"Variety":null,"Area":0},"12":{"Variety":null,"Area":0},..............
Solved! Go to Solution.
I believe what you're trying to do would be like this
var fs = FeatureSetByPortalItem(
portal,
id,
0,
fields,
False
)
var combinedFeatures = [];
for (var f in fs) {
Push(
combinedFeatures,
{ attributes: { Variety: f["variety1"], Area: f["var1_perc"] } }
);
Push(
combinedFeatures,
{ attributes: { Variety: f["variety2"], Area: f["var2_perc"] } }
);
Push(
combinedFeatures,
{ attributes: { Variety: f["variety3"], Area: f["var3_perc"] } }
);
}
var combinedDict = {
fields: [
{ name: "Variety", type: "esriFieldTypeString" },
{ name: "Area", type: "esriFieldTypeInteger" }
],
geometryType: "",
features: combinedFeatures
};
var d = Dictionary(combinedDict);
Console(d);
return FeatureSet(d);
Hey @BlakeMorrison
Could you try replacing your var d with this here and then console/return it:
var featureSet = FeatureSet(Text(combinedFeatures), schema);
I'm wondering if there is a difference between the dictionary and its current formatting, and the creation of the FeatureSet, as schema looks properly placed together, but combinedFeatures may need moved to Text.
Cody
I believe what you're trying to do would be like this
var fs = FeatureSetByPortalItem(
portal,
id,
0,
fields,
False
)
var combinedFeatures = [];
for (var f in fs) {
Push(
combinedFeatures,
{ attributes: { Variety: f["variety1"], Area: f["var1_perc"] } }
);
Push(
combinedFeatures,
{ attributes: { Variety: f["variety2"], Area: f["var2_perc"] } }
);
Push(
combinedFeatures,
{ attributes: { Variety: f["variety3"], Area: f["var3_perc"] } }
);
}
var combinedDict = {
fields: [
{ name: "Variety", type: "esriFieldTypeString" },
{ name: "Area", type: "esriFieldTypeInteger" }
],
geometryType: "",
features: combinedFeatures
};
var d = Dictionary(combinedDict);
Console(d);
return FeatureSet(d);