Hello,
I would like to add features in a featureSet, I initialize a featureSet and depending on other features I would like to push elements of these features on conditions :
var myFeatureSet = FeatureSet({
layerDefinition: {
objectIdField: "FID",
geometryType: "esriGeometryPolygon",
fields: [
{ name: "FID", alias: "FID", type: "esriFieldTypeOid" },
{ name: "attributeX", alias: "attributeX", type: "esriFieldTypeDate" },
{ name: "attributeY", alias: "attributeY", type: "esriFieldTypeString" }
]
},
featureset: {
features: [Feature(null, "FID", 1, "attributeX", "Hello World")]
}
});
var features = FeatureSetByName($map, myLayer,["*"],false)
var filteredFeature = Filter(features,
'attributeZ is not null')
for(var feat in filteredFeature){
// Push the feat in myFeatureSet
}
I tried to do it with Push function but I get Invalid Input ERROR
How can I do it ?
Thanks !
Solved! Go to Solution.
Your code doesn't follow the way that a FeatureSet is established, according to the docs.
https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featureset
Try defining the geometryType, fields, and features, but don't nest them in separate layerDefinition an dfeatureset objects.
var fs_json = {
geometryType: "esriGeometryPolygon",
fields: [
{ name: "FID", alias: "FID", type: "esriFieldTypeOid" },
{ name: "attributeX", alias: "attributeX", type: "esriFieldTypeDate" },
{ name: "attributeY", alias: "attributeY", type: "esriFieldTypeString" }
],
features: [
{attributes: {FID: 1, attributeX: "Hello World"}}
]
};
Also, once your FeatureSet is created, you won't be able to push features into it. You'll need to add the features to a dictionary, then create the FeatureSet once all your features have been loaded in.
var features = FeatureSetByName($map, myLayer, ['*'], false)
var filteredFeature = Filter(features, 'attributeZ is not null')
for ( var feat in feilteredFeature) {
Push(
fs_json['features'],
{
attributes: {
FID: feat['FID'],
attributeX: feat['attributeX'],
attributeY: feat['attributeY']
},
geometry: Geometry(feat)
}
)
}
return FeatureSet(fs_json)
Your code doesn't follow the way that a FeatureSet is established, according to the docs.
https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featureset
Try defining the geometryType, fields, and features, but don't nest them in separate layerDefinition an dfeatureset objects.
var fs_json = {
geometryType: "esriGeometryPolygon",
fields: [
{ name: "FID", alias: "FID", type: "esriFieldTypeOid" },
{ name: "attributeX", alias: "attributeX", type: "esriFieldTypeDate" },
{ name: "attributeY", alias: "attributeY", type: "esriFieldTypeString" }
],
features: [
{attributes: {FID: 1, attributeX: "Hello World"}}
]
};
Also, once your FeatureSet is created, you won't be able to push features into it. You'll need to add the features to a dictionary, then create the FeatureSet once all your features have been loaded in.
var features = FeatureSetByName($map, myLayer, ['*'], false)
var filteredFeature = Filter(features, 'attributeZ is not null')
for ( var feat in feilteredFeature) {
Push(
fs_json['features'],
{
attributes: {
FID: feat['FID'],
attributeX: feat['attributeX'],
attributeY: feat['attributeY']
},
geometry: Geometry(feat)
}
)
}
return FeatureSet(fs_json)
Thank you, it helped solve my issue ! 👍😁