I have a query that:
I am not seeing a fully unique return set....as you can see in the attachment there are two "sunfish, bluespotted" being returned even thought he COMMON_NAME field is the same as specified in the Unique Filter.
I am wondering if this is not working correctly?
do I have something set up wrong?
It is decreasing the number of returned records but does not seem to be getting all of unique values....I checked my data and this field seems to be unique, wondering if I am doing something wrong.
// SNIP.....
var query3 = new Query();
query3.geometry = bufferGeometry;
// Select the Points within the Buffer and show them
featureLayerVAFWIS.selectFeatures(query3, FeatureLayer.SELECTION_NEW, function(results){
});
// Query for the records with the given object IDs and populate the grid
featureLayerVAFWIS.queryFeatures(query3, function (featureSet) {
updateGrid3(featureSet);
});
function updateGrid3(featureSet) {
var data = arrayUtils.map(featureSet.features, function (entry, i) {
return {
id: entry.attributes.OBJECTID,
ObsID: entry.attributes.ObsID,
SppBova: entry.attributes.SppBova,
COMMON_NAME: entry.attributes.COMMON_NAME,
GENUS: entry.attributes.GENUS,
SPECIES: entry.attributes.SPECIES,
Tier: entry.attributes.Tier,
FedStatus: entry.attributes.FedStatus,
TaxaGrp: entry.attributes.TaxaGrp,
};
});
var uniqueName = [];
var UniquValues = array.filter(data, function (item) {
var IsNameUnique = true;
array.forEach(uniqueName, function (value) {
if (value == (item.COMMON_NAME)) {
IsNameUnique = false;
}
});
if (IsNameUnique) {
uniqueName.push(item.COMMON_NAME);
}
return IsNameUnique;
});
var i;
var out = "<table id=t01>";
for(i = 0; i < uniqueName.length; i++) {
out += "<tr><td>" +
arr.id +
"</td><td>" +
arr.ObsID +
"</td><td>" +
arr.SppBova +
"</td><td>" +
arr.COMMON_NAME +
"</td><td>" +
arr.GENUS +
"</td><td>" +
arr.SPECIES +
"</td><td>" +
arr.Tier +
"</td><td>" +
arr.FedStatus +
"</td><td>" +
arr.TaxaGrp +
"</td></tr>";
}
out += "</table>";
document.getElementById("id01").innerHTML = out;
dom.byId('upload-function').innerHTML = "See Results below";
domStyle.set(loadingShapefile, "display", "none");
}
Try filtering your array like this
function filterUnique(values){
var unique = {};
return dojo.filter(values, function(value) {
if (!unique[value]) {
unique[value] = true;
return true;
}
return false;
});
}
Sound I put that function outside the existing function and pass the array "data" to it?
Untested, but I think you could also do this
var UniqueValues = return array.filter(data, function(value) { if (!unique[value]) { unique[value] = true; return true; } return false; });
I tried this and get error: "unexpected Token Return"
I changed values to the array name data
var UniqueValues = return dojo.filter(data, function(value) {
if (!unique[value]) {
unique[value] = true;
return true;
}
return false;
});
Sorry, I was updating the code when you copied it out.
Am I missing a reference to something?
My other issue is that I am trying to get the unique records from 1 or 2 fields...not the entire item list.
function updateGrid3(featureSet) {
var data = arrayUtils.map(featureSet.features, function (entry, i) {
return {
id: entry.attributes.OBJECTID,
ObsID: entry.attributes.ObsID,
SppBova: entry.attributes.SppBova,
COMMON_NAME: entry.attributes.COMMON_NAME,
GENUS: entry.attributes.GENUS,
SPECIES: entry.attributes.SPECIES,
Tier: entry.attributes.Tier,
FedStatus: entry.attributes.FedStatus,
TaxaGrp: entry.attributes.TaxaGrp,
};
});
var UniqueValues = array.filter(data, function(value) {
if (!unique[value]) {
unique[value] = true;
return true;
}
return false;
});
Still getting errors from the "return" from your code so I tried it this way but not getting Unique values....
var newarr = [];
var unique = {};
dojo.forEach(data, function(item) {
if (!unique[item.GENUS + item.SPECIES]) {
newarr.push(item);
unique[item.GENUS + item.SPECIES] = item;
}
});
Hello jay
i wa look at the part where you build the html,and was not able to understand where arr came from. try looking at that variable and see if something is wrong there.
var i;
var out = "<table id=t01>";
for(i = 0; i < uniqueName.length; i++) {
out += "<tr><td>" +
arr.id +
"</td><td>" +
arr.ObsID +
"</td><td>" +
arr.SppBova +
"</td><td>" +
arr.COMMON_NAME +
"</td><td>" +
arr.GENUS +
"</td><td>" +
arr.SPECIES +
"</td><td>" +
arr.Tier +
"</td><td>" +
arr.FedStatus +
"</td><td>" +
arr.TaxaGrp +
"</td></tr>";
}
out += "</table>";
document.getElementById("id01").innerHTML = out;
Think I may have it....another colleague pointed something out...have to test and then will post all code.