DEV Community

Gavin Rehkemper
Gavin Rehkemper

Posted on • Updated on • Originally published at gavinr.com

Query All Features from a Feature Service

When querying an ArcGIS Feature Service, there is typically a maximum number of features (records) that will be returned from any query – usually set to 1000. If you want to query for all the features in the service, ArcGIS REST JS does not currently do this (see this discussion) - you’ll need to make multiple REST calls to get them all. Use the package query-all-features to do this.

First install the package:

npm install query-all-features
Enter fullscreen mode Exit fullscreen mode

Then use it in your code. It takes as input the same object as the queryFeatures endpoint of ArcGIS REST JS.

import { queryAllFeatures } from "query-all-features";

queryAllFeatures({
    url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"
}).then((results) => {
    console.log('results', results);
}, (err) => {
    console.error('err', err);
});
Enter fullscreen mode Exit fullscreen mode

You can also use it in NodeJS, in the browser via ES Modules (via CDN), and in the browser via a script tag. Here's a full code sample in action:

https://codepen.io/gavinr/pen/ExQYegd

Top comments (0)