AnsweredAssumed Answered

Subqueries using Features/Polygons in ArcGIS JS

Question asked by TacoB0T on Feb 12, 2017
Latest reply on Feb 13, 2017 by TacoB0T

Essentially, I'm trying to perform a second spatial query on a set of returned results from a previous query. The source runs, but it doesn't return any results for floodCalcs.business in the second for-loop. I do not get any errors from this and I do check to make sure that polygons have been loaded into polygons

 

 

 

 

Just realized I don;t know how to insert formatted code in here. Help?

 

 

queryShapes = function () {
for (var v = 0; v < shapes.length; v++) {

query = new Query();
select = shapes[v];
query.geometry = shapes[v].getExtent();
query.returnGeometry = true;

businessLayer.queryFeatures(query, selectBusiness);
//featureLayer.queryFeatures(query, selectInBuffer);

//perform query on business layer using user drawn shape's bounding box (extent)
function selectBusiness(response) {
var feature;
var features = response.features;
var floodFeatures = [];
var floodFeature;
var inBuffer = [];
var floodBuffer = [];

var q = new Query();
q.geometry = shapes[v].getExtent();
q.where = "1=1";
q.outSpatialReference = map.spatialReference;
q.outFields = ["*"];
q.returnGeometry = true;
var qTask = new QueryTask("url");
qTask.execute(q);
qTask.on("complete", queryBlock);
//query flood layer using user drawn shapes and cast the returned features as polygons
function queryBlock(f) {
for (var i = 0; i < f.featureSet.features.length; i++) {
polygons.push(new Polygon({ "rings": f.featureSet.features[i].geometry.rings, "spatialReference": f.featureSet.features[i].geometry.spatialReference }));
}
}

//filter out features that are not actually in buffer, since we got all points in the buffer's bounding box
for (var c = 0; c < features.length; c++) {
feature = features[c];
if (shapes[v].contains(feature.geometry)) {
inBuffer.push(feature.attributes[businessLayer.objectIdField]);
}
//use flood polygons that were returned in queryBlock function to find points in flood zones
for (var b = 0; b < polygons.length; b++) {
var poly = polygons[b];
if (poly.contains(feature.geometry)) {
floodCalcs.businessF += 1;
}
}
}

 

var subQuery = new Query();
subQuery.objectIds = inBuffer;
//use a fast objectIds selection query (should not need to go to the server)
featureLayer.selectFeatures(subQuery, FeatureLayer.SELECTION_NEW, function (results) {
floodCalcs.business += sumPopulation(results);
});

}
function sumPopulation(features) {
var popTotal = 0;
popTotal = features.length;
return popTotal;
}

}


}

Outcomes