Coder Social home page Coder Social logo

gavinr / query-all-features Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 2.0 607 KB

Query all features of an ArcGIS Feature Service

Home Page: https://codepen.io/gavinr/pen/ExQYegd?editors=0010

JavaScript 79.82% HTML 20.18%
arcgis arcgis-developers arcgis-rest-api arcgis-rest-js feature-service

query-all-features's Introduction

Query All Features

npm

Query all features of an ArcGIS Feature Service

This package calls queryFeatures from ArcGIS REST JS multiple times until it gets all the features.

Quick Start

npm install query-all-features

Then:

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);
});

API Reference

queryAllFeatures

queryAllFeatures(requestOptions, additionalOptions): Promise<IQueryFeaturesResponse>

Query a feature service, repeatedly paging through the results to get all the features.

Parameters

Parameter Type Notes
requestOptions IQueryFeaturesOptions This is the same input object that you would pass into ArcGIS REST JS queryFeatures.
additionalOptions IQueryFeaturesAllAdditionalOptions Additional options specific to this module. See table below.
IQueryFeaturesAllAdditionalOptions
Parameter Type Notes
pageBy (optional) number How many records to request from the service at a time. By default, the service info will be checked to find the maxRecordCount of the service, and that will be used as the pageBy value. If this pageBy value is provided, that additional request will not be made.
import { queryAllFeatures } from "query-all-features";

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

Returns

Promise<IQueryFeaturesResponse>

A Promise that will resolve with the same query response as queryFeatures.

Usage

Node JS

npm install query-all-features

Then:

const { queryAllFeatures } = require("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);
});

Browser - ES Modules

Distributed as an ES module which should work "out-of-the-box" with most popular module bundlers. See "Quick Start" above.

Browser - ES Modules via CDN

<script type="module">
    import { queryAllFeatures } from "https://cdn.skypack.dev/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);
    });
</script>

Example in action

Browser - Script tag via UMD CDN

<!-- arcgis-rest-request and arcgis-rest-feature-service are dependencies: -->
<script src="https://unpkg.com/@esri/arcgis-rest-request@4"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-feature-service@4"></script>
<script src="https://unpkg.com/query-all-features"></script>

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

Example in action

License

Copyright 2022 Gavin Rehkemper

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

query-all-features's People

Contributors

gavinr avatar gavinr-maps avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

query-all-features's Issues

Writing large results to file

Thank you for writing this! This is great. I've been using it for a few datasets and it works great.

However, I'm now trying to query all of large dataset (tax parcels): https://map9.incog.org/arcgis9wa/rest/services/Parcels_TulsaCo/FeatureServer/1.

There are several hundred thousand features in this.

I'm wondering what might be a good way to handle this? Maybe the easiest would be an optional callback where a user could intercept the new page of results and incrementally write to a file on their own.

There are also streams, but I'm not as familiar with those.

Open to trying out some approaches but wanted to get your thoughts on this!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.