Select to view content in your preferred language

Dictionary to FeatureSet issues. Probably the dictionary format?

613
2
Jump to solution
10-25-2024 12:49 AM
Labels (1)
BlakeMorrison
Frequent Contributor

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},..............

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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);

 

View solution in original post

0 Kudos
2 Replies
CodyPatterson
MVP Regular Contributor

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

0 Kudos
KenBuja
MVP Esteemed Contributor

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);

 

0 Kudos