Select to view content in your preferred language

Limit esriRequest query results to area of interest

2972
4
Jump to solution
10-26-2015 01:19 PM
VygintasCesnauskas
Occasional Contributor

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
Regular Contributor

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
Honored 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
Regular Contributor

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
Honored 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