Limit esriRequest query results to area of interest

2746
4
Jump to solution
10-26-2015 01:19 PM
VygintasCesnauskas
New Contributor III

Is there a way to limit results of the esriRequest query below to extents of the area of interest?

                    var qrequest = esriRequest({
                        url: test_url,
                        content: {
                            where: "objectid > 0",
                            returnGeometry: true,
                            outFields: "name",
                            outSR: configuration.wkid,
                            f: "json"
                        },
                        handleAs: "json",
                        callbackParamName: 'callback'
                    });

One way I can think of would be iterating through the returned feature set and checking which ones intersect the extent, but I would prefer to have this done server side, as these feature sets could be quite large.

0 Kudos
1 Solution

Accepted Solutions
DanielGarcia
New Contributor III

I recommend you to use QueryTask Object, but if you want to use esriRequest, you can specify a spatial clause using geometryType and geometry params

geometryType=esriGeometryEnvelope&geometry=<xmin>,<ymin>,<xmax>,<ymax>

var qrequest = esriRequest({
  url : test_url,
  content : {
     where : "objectid > 0",
     returnGeometry : true,
     outFields : "name",
     outSR : configuration.wkid,
     geometryType: "esriGeometryEnvelope",
     geometry: "<xmin>,<ymin>,<xmax>,<ymax>"
     f : "json"
  },
  handleAs : "json",
  callbackParamName : 'callback'
});

Regards

View solution in original post

4 Replies
SteveCole
Frequent Contributor

Maybe you have reasons for not using it but esri/tasks/query has a geometry option for evaluating intersects.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Vygintas,

   You should use QueryTask instead, to enable you to specify a geometry to limit the query.

0 Kudos
DanielGarcia
New Contributor III

I recommend you to use QueryTask Object, but if you want to use esriRequest, you can specify a spatial clause using geometryType and geometry params

geometryType=esriGeometryEnvelope&geometry=<xmin>,<ymin>,<xmax>,<ymax>

var qrequest = esriRequest({
  url : test_url,
  content : {
     where : "objectid > 0",
     returnGeometry : true,
     outFields : "name",
     outSR : configuration.wkid,
     geometryType: "esriGeometryEnvelope",
     geometry: "<xmin>,<ymin>,<xmax>,<ymax>"
     f : "json"
  },
  handleAs : "json",
  callbackParamName : 'callback'
});

Regards

TracySchloss
Frequent Contributor

Nice to know it's possible.  Is there any scenario you can think of where esriRequest would be the better solution over queryTask?  

0 Kudos