After returning my featureSet from a query, I want to be able to pass an array to d3 to do some visualizations and analyses. How do I either convert the returned featureSet to an array or get the attributes returned from a feature? The only thing I've managed to do is get a count of features.
array.forEach(featureSet.features, function(feature) {
featureCount += 1;
console.log("feature attributes are" + Would love to display a value from an attribute here);
});
How do I access field values on the feature?
Solved! Go to Solution.
Ken,
What does your query code look like?
What outFields are you specifying in the query parameters?
Ken in your feature loop you just use feature.attributes.yourAttributeName
The feature in your function has attributes you can examine. If you know what those attributes are named, then you can specify them. For example, if one of the attributes is called "Class", you can use
array.forEach(featureSet.features, function(feature) { featureCount += 1; console.log("Class: " + feature.attributes.Class ); });
I've been trying that exact syntax for hours and all I get in the console window is undefined. I have an info template for the same unfiltered feature service which works fine so I'm assuming I have the feature names correct. I get a different feature count depending on my query parameter so I'm pretty positive its returning the right stuff. So if there are 62 features returned the console window has a 62 in a little circle with the message "feature attributes are undefined" which I believe means here are 62 rows with the same output.
Ken,
What does your query code look like?
What outFields are you specifying in the query parameters?
Bingo! I was assuming (stupidly) the simple query returned all fields. That would obviously waste bandwidth and slow down response times so why would that be the default? I had no outFields. Thank you thank you!!
Ken
Can you amend your answer to ask about the outFields? I’m happy to pick that as correct but I want to make sure it notes the actual problem for other folks who may come across it.
Ken
Ken,
I did mention outFields of the Query parameters in my last reply, so you can mark that one as the correct answer.
Hadn't noticed these emails were all being captured. I'm a geonet noob. Thanks!