3

I am using a QueryTask to select data from a Feature Service and pass the attribute values to a dGrid. I am using a where statement (query.where) to select only certain polygons from this service and I would like to also be able to pass a point to the query to further narrow the results. The Feature Service, where statement, and xy coordinates are passed as URL parameters. I am able to query the data using the just a query.where or just the query.geometry, but I am getting no results when I use both query.where and query.geometry (I have checked the data and there is data that satisfies both criteria.

The polygon feature service I am querying has about 10,000 polygons so perhaps it is a memory issue?

Note that I have removed the code to create the grid due to character limits.

require([
"esri/layers/FeatureLayer",
"esri/tasks/QueryTask",
"esri/tasks/query",
"dojo/ready",
"dojo/number",
"dojo/dom",
"dojo/on",
"dojo/parser",
"dojo/_base/array",
"dijit/form/Select",
"dojo/dom-style",
"dojo/dom-construct",
"dojo/_base/connect",
"dojo/_base/declare",
"dojo/store/Memory",
"dojo/store/Observable",
"dojo/number",
"dstore/Trackable",
"dstore/RequestMemory",
"dijit/registry",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dgrid/Grid",
"dgrid/editor",
"dgrid/Keyboard",
"dgrid/Selection",
"dgrid/extensions/ColumnHider",
"dgrid/extensions/Pagination",
"esri/geometry/Point",
"esri/SpatialReference",
"esri/geometry/webMercatorUtils",
"dojo/domReady!"
],

function (
    FeatureLayer,
    QueryTask,
    Query,
    ready,
    number,
    dom,
    on,
    parser,
    array,
    Select,
    domStyle,
    domConstruct,
    connect,
    declare,
    Memory,
    Observable,
    dojoNum,
    Trackable,
    RequestMemory,
    registry,
    BorderContainer,
    ContentPane,
    Grid,
    Editor,
    Keyboard,
    Selection,
    ColumnHider,
    Pagination,
    Point,
    SpatialReference,
    webMercatorUtils
) {

    "use strict";
    var memStore, data, mapServ, strHref, strURLParamReturn, URLQuery, coords, newcoords, gsvc, geom, URL, Index, layer, feature, ResFields, ResCols, grid, GMap, AGOL, Street, Search, strQueryString, iParam, aQueryString, aParam, i, MyGrid, qt, query;
    mapServ = "https://gisq.in.gov/arcgis/rest/services/ISDH/PHG_Data/FeatureServ";

    function getSingleURLParameter(ParamName) {
        strURLParamReturn = "";
        strHref = window.location.href;
        if (strHref.indexOf("?") > -1) {
            strQueryString = strHref.substr(strHref.indexOf("?"));
            aQueryString = strQueryString.split("&");
            for (iParam = 0; iParam < aQueryString.length; iParam++) {
                if (aQueryString[iParam].indexOf(ParamName + "=") > -1) {
                    aParam = aQueryString[iParam].split("=");
                    //---start patch for equal sign in argument
                    if (aParam.length > 2) {
                        for (i = 2; i < aParam.length; i++) {
                            aParam[1] += '=' + aParam[i];
                        }
                    }
                    //---end patch
                    strURLParamReturn = aParam[1];
                    break;
                }
            }
        }
        return unescape(strURLParamReturn);
    }

    URLQuery = getSingleURLParameter("where");
    //console.log(URLQuery);

    geom = getSingleURLParameter("geom").split(",");
    if (geom[0] > 37 && geom[0] < 42 && geom[1] < -84 && geom[1] > -89) {
        //coords = new Point("geom", new SpatialReference({wkid: 4326}));
        coords = new Point(-87, 41);
        coords.setSpatialReference(new SpatialReference({"wkid":8307}));
        newcoords = webMercatorUtils.geographicToWebMercator(coords);
    }

    URL = getSingleURLParameter("url");
    if (URL !== "") {
        mapServ = URL;
    }

    Index = getSingleURLParameter("layer");
    if (Index === "") {
        Index = 0;
    }

    console.log(Index);
    layer = mapServ.concat('/', Index);
    feature = new FeatureLayer(layer);

    qt = new QueryTask(layer);
    console.log(newcoords)
    query = new Query();
    //console.log(query);
    //query.where = URLQuery;
    query.text = URLQuery;
    query.geometry = newcoords;
    query.returnGeometry = true;
    query.outFields = ResFields;
    console.log(query);
        //qt.execute();
    qt.execute(query, function (results) {
        console.log(results);
    });

});
1

the code snippet you've provided throws an error because you're making the request to an invalid url (FeatureServ/0/ instead of FeatureServer/0/). that said, you're also passing quite a few undefined/invalid parameters.

geometry: undefined
outFields: undefined
text:""

some things to keep in mind:

  • a point will never intersect another point unless they have identical/coincident geometry (see this blog for more info)
  • its not necessary to reproject geometries to the spatial reference of the layer you're querying. you can pass in geometries in any known coordinate system and ask for geometries back from the service in any coordinate system you want using outSpatialReference.
  • both using break points in the browser developer tools and sniffing the web traffic to inspect the web requests that are being triggered are both crucial for debugging.

working sample here.

your (broken) sample here.

  • Thank you for your response. But, the FeatureService that I am querying/intersecting is a polygon layer that is being passed through a URL parameter, along with the xy coordinates of the geometry and the query text. The code works when providing only query.geometry, or only query.where. But, does not work when both are provided. – A. Suiter Apr 25 '16 at 11:09
  • 1
    im happy to help, but you need to provide a simplified repro case that demonstrates that behavior – John Gravois Apr 25 '16 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.