7 Replies Latest reply on Apr 24, 2012 1:25 PM by DSwingley-esristaff

    QueryTask not returning results when it should!

    crackernutter
      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
        • Re: QueryTask not returning results when it should!
          hzhu
          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.
          • Re: QueryTask not returning results when it should!
            tannerjt
            Try unprojecting the coordinates:

            Code:

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

            -Josh
            • Re: QueryTask not returning results when it should!
              crackernutter
              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
              • Re: QueryTask not returning results when it should!
                rduke40
                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,
                • Re: QueryTask not returning results when it should!
                  DSwingley-esristaff
                  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.
                  • Re: QueryTask not returning results when it should!
                    rduke40
                    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
                    • Re: QueryTask not returning results when it should!
                      DSwingley-esristaff
                      Thanks. Would have been useful to know you're using Flex, not JavaScript ;).