GEOG 863:
Web Application Development for Geospatial Professionals

6.2.2 Getting Feature Counts


As mentioned, Esri’s API provides methods for getting a count of features meeting some selection criteria, getting the IDs of those features, or getting the features themselves. Regardless of which kind of response you require, the first step in the process is creating an object of the Query class. Perhaps the most-used property on the Query class is where, which takes the same sort of SQL where clause that we saw earlier when discussing the definitionExpression property.

There are many other Query properties, some of which we’ll discuss momentarily. For now, let’s look at this example that reports the number of counties in Jen & Barry’s world that meet the criterion of NO_FARMS87 > 150.

See the Pen queryFeatureCount() Demo by Jim Detwiler (@jimdetwiler) on CodePen.

Note that after creating a FeatureLayer of the counties, a Query object is created on lines 30-32. The object’s where property is set to a variable that was defined near the top of the script on line 9. The Query object is then used on line 35 as the argument to the queryFeatureCount() method (a method of the FeatureLayer class). Line 36 contains the alert() statement that produces the message you saw when you first opened this page. What we skipped over at the end of line 35 is some code that handles what’s returned by the queryFeatureCount() method: a promise. You’ve probably seen references to promises while poking around the SDK. Well, now we’re finally going to discuss what a promise is.