QueryTask not returning results when it should!

2591
7
04-14-2012 12:03 PM
JayGregory
New Contributor III
So I am trying to do something very simple - return the points for the USGS Steam Flow Station layer (http://rmgsc.cr.usgs.gov/ArcGIS/rest/services/nhss_usdata/MapServer/0) that fall within the District of Columbia.  There should be 3. 

First I construct a QueryTask to get the District of Columbia layer

      var queryTask = new esri.tasks.QueryTask(districtURL);
  var query = new esri.tasks.Query();
               query.returnGeometry = true;
               query.outFields = ["*"];
        query.where = "CITY_NAME = 'Washington'"
               query.outSpatialReference = map.spatialReference;
        queryTask.execute(query, queryResults, errorCall);


I've verified that this works - one feature is returned.  However, when I try to query the points in Steam Flow Station layer against this result, I get an error since null results are returned!

function queryResults(featureSet){
      console.log(featureSet.spatialReference);
     console.log(map.spatialReference);
     var queryTaskWithin = new esri.tasks.QueryTask("http://rmgsc.cr.usgs.gov/ArcGIS/rest/services/nhss_usdata/MapServer/0");
     var query = new esri.tasks.Query();
            query.returnGeometry = true;
     query.outFields = ["*"];
     query.outSpatialReference = map.spatialReference;
     query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_WITHIN;
     query.geometry = featureSet.features[0].geometry;
     queryTaskWithin.execute(query)
     dojo.connect(queryTaskWithin, "onComplete", function(fset) {
 console.log(fset.features.length);
 }, function(error){console.log("error" + error)});
}


At one point I was getting 0 results and no error, but now I'm just getting an error.  I thought this should be a simple task - any assistance would be of great help. 

Also, the spatial references of the district layer and the Steam Flow Station layer are seemingly different.  One is 102100 and the other is 3857.  But I think those are both web mercator so it shouldn't matter too much, right?

Thanks!

Jay
0 Kudos
7 Replies
HemingZhu
Occasional Contributor III
So I am trying to do something very simple - return the points for the USGS Steam Flow Station layer (http://rmgsc.cr.usgs.gov/ArcGIS/rest/services/nhss_usdata/MapServer/0) that fall within the District of Columbia.  There should be 3. 

First I construct a QueryTask to get the District of Columbia layer

      var queryTask = new esri.tasks.QueryTask(districtURL);
  var query = new esri.tasks.Query();
               query.returnGeometry = true;
               query.outFields = ["*"];
        query.where = "CITY_NAME = 'Washington'"
               query.outSpatialReference = map.spatialReference;
        queryTask.execute(query, queryResults, errorCall);


I've verified that this works - one feature is returned.  However, when I try to query the points in Steam Flow Station layer against this result, I get an error since null results are returned!

function queryResults(featureSet){
      console.log(featureSet.spatialReference);
     console.log(map.spatialReference);
     var queryTaskWithin = new esri.tasks.QueryTask("http://rmgsc.cr.usgs.gov/ArcGIS/rest/services/nhss_usdata/MapServer/0");
     var query = new esri.tasks.Query();
            query.returnGeometry = true;
     query.outFields = ["*"];
     query.outSpatialReference = map.spatialReference;
     query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_WITHIN;
     query.geometry = featureSet.features[0].geometry;
     queryTaskWithin.execute(query)
     dojo.connect(queryTaskWithin, "onComplete", function(fset) {
 console.log(fset.features.length);
 }, function(error){console.log("error" + error)});
}


At one point I was getting 0 results and no error, but now I'm just getting an error.  I thought this should be a simple task - any assistance would be of great help. 

Also, the spatial references of the district layer and the Steam Flow Station layer are seemingly different.  One is 102100 and the other is 3857.  But I think those are both web mercator so it shouldn't matter too much, right?

Thanks!

Jay


I think the issue is your  query.spatialRelationship. Comment it out, and see what happen.
0 Kudos
JoshuaTanner
New Contributor II
Try unprojecting the coordinates:

Code:

query.geometry =  esri.geometry.webMercatorToGeographic(featureSet.features[0].geometry);

-Josh
0 Kudos
JayGregory
New Contributor III
Josh - thanks for the suggestion.  I tried that, and it still doesn't work.  When I set the extent to the returned geometry of the first query (returning the DC borders), it zooms to the coast of Africa like there was no project, although the spatial Reference is 3857, and the original DC layer draws in the correct location on a base map.  Any suggestions?

Thanks, Jay
0 Kudos
by Anonymous User
Not applicable
I am having the same issue with the querytask.  I am getting a null returned as well.  My code is similar to Jay's although I am using a different Map service and layer of course.  Can someone help with this issue??? 

Thanks,
0 Kudos
derekswingley1
Frequent Contributor
I am having the same issue with the querytask.  I am getting a null returned as well.  My code is similar to Jay's although I am using a different Map service and layer of course.  Can someone help with this issue??? 

Thanks,


Please start a new thread and post some code that shows the issue.
0 Kudos
by Anonymous User
Not applicable
I have posted the answer that I found, which worked for me in a seperate post:  http://forums.arcgis.com/threads/56118-QueryTask-not-showing-results-when-it-should
0 Kudos
derekswingley1
Frequent Contributor
Thanks. Would have been useful to know you're using Flex, not JavaScript ;).
0 Kudos