AnsweredAssumed Answered

What kind of query does queryFeatures support?

Question asked by Dschontzler_pulsiam on Dec 26, 2018
Latest reply on Jan 1, 2019 by rscheitlin

I am attempting to query some FeatureLayers, but I cannot seem to construct a query that works.

 

If you click on the map in the following demo the promise returns an error: ArcGIS: queryFeatures - Unsupported query error 

  1. message: "Unsupported query"
  2. name: "esri.layers.graphics.QueryEngine"

I've tried a number of searches with different geometry types (extent, circle, geodesic buffer). I've also tried center and distance, but they are all unsupported.

 

Question: how can I find out what kinds of queries FeatureLayers support? I have not come across docs that have helped in that regard. Besides my sample FeatureLayer there are other FeatureLayers I will be querying (e.g. remote ones) and I would like to figure out what I can and cannot send in a query.

 

FYI, here is the code:

    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer",
      "esri/geometry/geometryEngine",
      "esri/Graphic",
      "esri/layers/GraphicsLayer",
      "esri/tasks/support/Query",
      "esri/widgets/CoordinateConversion",
      "esri/geometry/support/webMercatorUtils",
      "esri/geometry/Point",
      "dojo/domReady!"
    ], function(Map, MapView, FeatureLayer, geometryEngine, Graphic, GraphicsLayer, Query, CC, wMU, Point) {

      map = new Map({
        basemap: "topo-vector"
      });
     
      view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-118.739851, 34.090456],
        zoom: 14
      });
     
      view.ui.add(new CC({ view: view }), 'bottom-right');
     
      featureLayer = new FeatureLayer({
        id: 'dots',
        title: 'dots on a map',
        geometryType: 'point',
        objectIdField: 'id',
        spatialReference: { wkid: 4326 },
        source: [],
        fields: [
          {
            name: 'id',
            alias: 'ID',
            type: 'oid',
          },
          {
            name: 'mapObject',
            alias: 'mapObject',
            type: 'object'
          }
        ]
      });
     
      map.layers.add(featureLayer);
     
      var circleGraphic;
     
      points = [];
     
      [
        '-118.742555, 34.095076',
        '-118.747447, 34.094010',
        '-118.749593, 34.090811',
        '-118.734658, 34.088039',
        '-118.736032, 34.091735',
        '-118.743070, 34.091096'
      ].forEach(pair => {
        var ll = pair.split(', ');
        addPoint(new Point({
          type: 'point',
          spatialReference: { wkid: 4326 },
          x: ll[0],
          y: ll[1]
        }));
      });
     
      view.on('click', function (e) {
        var centerPt = e.mapPoint;
        if (e.native.ctrlKey) {
          // add more points to the map
          addPoint(centerPt);
        } else {
          // search in the clicked area for points
          var geom = geometryEngine.geodesicBuffer(centerPt, 400, 'meters');
          if (circleGraphic) view.graphics.remove(circleGraphic);
          circleGraphic = new Graphic({
            geometry: geom,
            symbol: {
              type: 'simple-fill',
              color: [140, 140, 222, 0.5]
            }
          });
          view.graphics.add(circleGraphic);
         
          query = featureLayer.createQuery();
          query.geometry = geom;
          query.spatialRelationship = 'contains';
         
          featureLayer.queryFeatures(query)
            .then(result => {
              console.log('This area contains', inPts.length, 'points');
            }).catch(error => {
              console.error(error);
            });
        }
      });
     
      function addPoint(geo) {
        if (geo.spatialReference.isGeographic) {
          geo = wMU.geographicToWebMercator(geo);
          console.log('converting geography');
        }
        var pt = new Graphic({
          geometry: geo,
          symbol: {
            type: 'simple-marker',
            style: 'circle',
            color: 'black',
            size: '8px'
          }
        });
        // console.log('adding point at:', pt.geometry.x, pt.geometry.y);
        view.graphics.add(pt);
        points.push(pt);
      }
    });

Outcomes