+ Reply to Thread
Results 1 to 8 of 8

Thread: QueryTask not returning results when it should!

  1. #1
    Jay Gregory
    Join Date
    Apr 2012
    Posts
    47
    Points
    2
    Answers Provided
    1


    0

    Default QueryTask not returning results when it should!

    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...ta/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

    Code:
          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!

    Code:
    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

  2. #2
    Heming Zhu

    Join Date
    May 2010
    Posts
    514
    Points
    47
    Answers Provided
    7


    0

    Default Re: QueryTask not returning results when it should!

    Quote Originally Posted by jaygregory View Post
    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...ta/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

    Code:
          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!

    Code:
    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.

  3. #3
    Joshua Tanner
    Join Date
    Mar 2011
    Posts
    1
    Points
    0
    Answers Provided
    0


    0

    Default Re: QueryTask not returning results when it should!

    Try unprojecting the coordinates:

    Code:

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

    -Josh

  4. #4
    Jay Gregory
    Join Date
    Apr 2012
    Posts
    47
    Points
    2
    Answers Provided
    1


    0

    Default Re: QueryTask not returning results when it should!

    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

  5. #5
    Ray Duke
    Join Date
    Jan 2012
    Posts
    44
    Points
    0
    Answers Provided
    2


    0

    Default Re: QueryTask not returning results when it should!

    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,

  6. #6
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    893
    Answers Provided
    165


    0

    Default Re: QueryTask not returning results when it should!

    Quote Originally Posted by rduke40 View Post
    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.
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

  7. #7
    Ray Duke
    Join Date
    Jan 2012
    Posts
    44
    Points
    0
    Answers Provided
    2


    0

    Default Re: QueryTask not returning results when it should!

    I have posted the answer that I found, which worked for me in a seperate post: http://forums.arcgis.com/threads/561...when-it-should

  8. #8
    Derek Swingley

    Join Date
    May 2010
    Posts
    1,859
    Points
    893
    Answers Provided
    165


    0

    Default Re: QueryTask not returning results when it should!

    Thanks. Would have been useful to know you're using Flex, not JavaScript .
    --
    @derekswingley | ArcGIS API for JavaScript Team Member.

    If you're posting a code or html sample, please wrap it in code tags.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts