schlot

polygon input as geometry to a query/queryTask

Discussion created by schlot on Apr 11, 2014
Latest reply on Apr 16, 2014 by schlot
I have a basic county boundary service that I'm using as input to a FindTask, based on a county name pick list.  Later, the user should have the option to use the geometry of that found polygon as the input geometry of a querytask which searches on other county polygon layers.  My basic county service is in UTM, but my project is wkid 102100 and so is the layer I'm trying to search in the queryTask. I have the output spatialReference of my findParameters set to that same wkid, which I assume should make the geometry from the find be in the right coordinates.

If the use clicks the "find neighbors" button, it executes the findAdjacentCounties function, which runs a query/QueryTask using Query.SPATIAL_REL_TOUCHES.  The query executes without error, but it never returns any features, I assume because the inputGeometry I'm providing doesn't actually touch any of other features.  The coordinates of the countyGeometry variable says it's wkid 102100. 

//This functions searches the countyLayer, defined earlier to zoom to a county and saves the geometry
   function zoomCounty () {
    var findTask = new FindTask(countyLayer.url);  //layer defined earlier
     var findParams = new FindParameters();
     findParams.returnGeometry = true;
     findParams.layerIds = [0];
     findParams.searchFields = ["COUNTYNAME"]; 
    findParams.outSpatialReference = spatialReference;    
     var countyName = registry.byId("countySelect").value;
     findParams.searchText = countyName;
     findTask.execute(findParams, function (results) {
        map.setExtent(results[0].feature.geometry.getExtent());
        currentExtent = map.extent;
        currentCenter = results[0].feature.geometry.getCentroid();
        countyGeometry = results[0].feature.geometry;  // polygon geometry getting stored
    });
} 
//this executes when the user selects the 'find neighbor' button
  function findAdjacentCounty() {
    var currentVis = ncdmLayer.visibleLayers;//layer defined earlier
    var queryTask = new QueryTask(ncdmLayer.url+"/" +currentVis);
    var query = new Query();
    query.geometry = countyGeometry;
    query.outSpatialReference = spatialReference;
    query.spatialRelationship = Query.SPATIAL_REL_TOUCHES;
    query.outFields=["NAME", "NAME2", "RATE"];
  //  query.returnGeometry = true;
    queryTask.on('error', taskErrorHandler);
    queryTask.execute(query, adjacentResultHandler);
  }
//this function executes, but results is always empty!
     function adjacentResultHandler(results) {
       countyList.length = 0; //arrays defined earlier
       countyRateList.length = 0;
      arrayUtil.forEach(results.features, function(feature){
        countyList.push(feature.attributes.NAME);
        countyRateList.push(feature.attributes.RATE);     
         });
       console.log(countyList);
       console.log(countyRateList);

    }   


I made a basic sample before I started, but it was using all the same layer, both for the find and query tasks.  Now I need to use two different ones.

Outcomes