Query Records by Buffer - All features returned

424
2
12-11-2012 11:56 AM
BrianLord1
Occasional Contributor
I am working on configuring the Javascript Park Finder app from the local government resource center.  I have set the app up to use our local data and changed the spatial reference throughout the app to match what our data uses and what my geometry service uses. 

When I run a query on my parks layer using a 1 mile buffer, all the parks are returned by the querytask.  I have tried mutliple spatial relationships in the query and the result is always the same.  Here is the code.

//function for Displaying the buffer
function ShowBuffer(geometries) {
    ClearBuffer();
    var lineColor = new dojo.Color();
    lineColor.setColor(rendererColor);
    var fillColor = new dojo.Color();
    fillColor.setColor(rendererColor);
    fillColor.a = 0.55;
    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
        new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
        lineColor, 2),
        fillColor);
    dojo.forEach(geometries, function (geometry) {
        AddGraphic(map.getLayer(tempBufferLayer), symbol, geometry);
    });
    map.setExtent(geometries[0].getExtent().expand(1.6));
    QueryLayer(geometries[0]);
}

//function for getting the features and their length with in the buffer region
function QueryLayer(geometry) {
    var qTask = 'qTask';
    qTask = new esri.tasks.QueryTask(devPlanLayerURL);
    var query = new esri.tasks.Query();
    query.geometry = geometry;
    query.where = "1=1";
    query.outFields = ["*"];
    query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
    query.returnGeometry = true;

    qTask.execute(query, function (featureset) {
        if (dojo.byId('spanParkActivityContainer')) {
            dojo.byId('spanParkActivityContainer').style.display = 'none';
        }
        dojo.byId('spanParkListContainer').innerHTML = 'Found ' + featureset.features.length + ' park(s) near the address';
        CreateDistance(featureset);
    });
}


I did (just for testing purposes) write a more restrictive Where statement and that querytask did come back with the correct amount of records so I am thinking it must have to do with the spatial reference. 

My app does still use an arcgis online routing task, but I do not believe that would have anything to do with this query. 

Anyone ever experience this or have any ideas as to what might be causing this? 

Thanks,
Mark
0 Kudos
2 Replies
BrianLord1
Occasional Contributor
So I removed all references to the arcgis online routing task, and the buffer still selects everything.  The only data in my app now is my own that all use the same spatial reference.

While debugging, I was able to see the extent that is used and it seems to be correct so I am at a loss as to why it would select all the records as opposed to just the ones located in the buffer.
0 Kudos
YongjunLei
New Contributor
Try make the changes in your code for QueryLayer function: This will select the extent (which will be a rectangle area) for the buffer if it works. I could not make my code to work if I just use the code query.geometry = geometry. I am looking for a solution.

function QueryLayer(geometry) {
var qTask = 'qTask';
qTask = new esri.tasks.QueryTask(devPlanLayerURL);
var query = new esri.tasks.Query();
query.geometry = geometry.getExtent();
query.where = "1=1";
query.outFields = ["*"];
query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
query.returnGeometry = true;

qTask.execute(query, function (featureset) {
if (dojo.byId('spanParkActivityContainer')) {
dojo.byId('spanParkActivityContainer').style.display = 'none';
}
dojo.byId('spanParkListContainer').innerHTML = 'Found ' + featureset.features.length + ' park(s) near the address';
CreateDistance(featureset);
});
}




So I removed all references to the arcgis online routing task, and the buffer still selects everything. The only data in my app now is my own that all use the same spatial reference. 

While debugging, I was able to see the extent that is used and it seems to be correct so I am at a loss as to why it would select all the records as opposed to just the ones located in the buffer.
0 Kudos