-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ArcGIS/demographics
initial demographics package (getAvailableDataCollections())
- Loading branch information
Showing
10 changed files
with
2,882 additions
and
1,758 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
[![npm version][npm-img]][npm-url] | ||
[![build status][travis-img]][travis-url] | ||
[![gzip bundle size][gzip-image]][npm-url] | ||
[![Coverage Status][coverage-img]][coverage-url] | ||
[![apache licensed](https://img.shields.io/badge/license-Apache-green.svg?style=flat-square)](https://raw.githubusercontent.com/Esri/arcgis-rest-js/master/LICENSE) | ||
|
||
[npm-img]: https://img.shields.io/npm/v/@esri/arcgis-rest-demographics.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/@esri/arcgis-rest-demographics | ||
[travis-img]: https://img.shields.io/travis/Esri/arcgis-rest-js/master.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/Esri/arcgis-rest-js | ||
[gzip-image]: https://img.badgesize.io/https://unpkg.com/@esri/arcgis-rest-demographics/dist/umd/demographics.umd.min.js?compression=gzip | ||
[coverage-img]: https://codecov.io/gh/Esri/arcgis-rest-js/branch/master/graph/badge.svg | ||
[coverage-url]: https://codecov.io/gh/Esri/arcgis-rest-js | ||
|
||
# @esri/arcgis-rest-demographics | ||
|
||
> Demographics helpers for [`@esri/arcgis-rest-request`](https://github.com/Esri/arcgis-rest-js). | ||
### Example | ||
|
||
```bash | ||
npm install @esri/arcgis-rest-request | ||
npm install @esri/arcgis-rest-demographics | ||
``` | ||
|
||
```js | ||
import { getAvailableDataCollections } from '@esri/arcgis-rest-demographics'; | ||
|
||
getAvailableDataCollections() | ||
.then((response) => { | ||
response.DataCollections; | ||
// => [{ dataCollectionId: "KeyGlobalFacts", metadata: { ... }, data: [ ... ] }, ... ] | ||
}); | ||
``` | ||
|
||
### [API Reference](https://esri.github.io/arcgis-rest-js/api/demographics/) | ||
|
||
* [`getAvailableDataCollections({countryCode: 'us'})`](https://esri.github.io/arcgis-rest-js/api/demographics/getAvailableDataCollections/) | ||
|
||
### Issues | ||
|
||
If something isn't working the way you expected, please take a look at [previously logged issues](https://github.com/Esri/arcgis-rest-js/issues) first. Have you found a new bug? Want to request a new feature? We'd [**love**](https://github.com/Esri/arcgis-rest-js/issues/new) to hear from you. | ||
|
||
If you're looking for help you can also post issues on [GIS Stackexchange](http://gis.stackexchange.com/questions/ask?tags=esri-oss). | ||
|
||
### Versioning | ||
|
||
For transparency into the release cycle and in striving to maintain backward compatibility, @esri/arcgis-rest-js is maintained under Semantic Versioning guidelines and will adhere to these rules whenever possible. | ||
|
||
For more information on SemVer, please visit <http://semver.org/>. | ||
|
||
### Contributing | ||
|
||
Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](CONTRIBUTING.md). | ||
|
||
### [Changelog](https://github.com/Esri/arcgis-rest-js/blob/master/CHANGELOG.md) | ||
|
||
### License | ||
|
||
Copyright © 2017-2019 Esri | ||
|
||
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. | ||
|
||
A copy of the license is available in the repository's [LICENSE](../../LICENSE) file. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"name": "@esri/arcgis-rest-demographics", | ||
"version": "2.18.0", | ||
"description": "Demographics data helpers for @esri/arcgis-rest-js", | ||
"main": "dist/node/index.js", | ||
"unpkg": "dist/umd/geocoding.umd.js", | ||
"module": "dist/esm/index.js", | ||
"js:next": "dist/esm/index.js", | ||
"sideEffects": false, | ||
"types": "dist/esm/index.d.ts", | ||
"license": "Apache-2.0", | ||
"files": [ | ||
"dist/**" | ||
], | ||
"dependencies": { | ||
"@esri/arcgis-rest-types": "^2.18.0", | ||
"tslib": "^1.13.0" | ||
}, | ||
"devDependencies": { | ||
"@esri/arcgis-rest-auth": "^2.18.0", | ||
"@esri/arcgis-rest-request": "^2.18.0" | ||
}, | ||
"peerDependencies": { | ||
"@esri/arcgis-rest-auth": "^2.0.0", | ||
"@esri/arcgis-rest-request": "^2.0.0" | ||
}, | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"build": "npm run build:node && npm run build:umd && npm run build:esm", | ||
"build:esm": "tsc --module es2015 --outDir ./dist/esm --declaration", | ||
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js", | ||
"build:node": "tsc --module commonjs --outDir ./dist/node", | ||
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration", | ||
"dev:umd": "rollup -w -c ../../umd-base-profile.js", | ||
"dev:node": "tsc -w --module commonjs --outDir ./dist/node" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Esri/arcgis-rest-js.git", | ||
"directory": "packages/arcgis-rest-demographics" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Patrick Arlt", | ||
"email": "parlt@esri.com", | ||
"url": "http://patrickarlt.com/" | ||
}, | ||
{ | ||
"name": "Gavin Rehkemper", | ||
"email": "grehkemper@esri.com", | ||
"url": "http://gavinr.com/" | ||
} | ||
], | ||
"bugs": { | ||
"url": "https://github.com/Esri/arcgis-rest-js/issues" | ||
}, | ||
"homepage": "https://github.com/Esri/arcgis-rest-js#readme", | ||
"keywords": [ | ||
"typescript", | ||
"promise", | ||
"fetch", | ||
"arcgis", | ||
"esri", | ||
"ES6" | ||
] | ||
} |
164 changes: 164 additions & 0 deletions
164
packages/arcgis-rest-demographics/src/getAvailableDataCollections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* Copyright (c) 2020 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { | ||
request, | ||
cleanUrl, | ||
appendCustomParams, | ||
IRequestOptions | ||
} from "@esri/arcgis-rest-request"; | ||
|
||
import { ARCGIS_ONLINE_GEOENRICHMENT_URL } from "./helpers"; | ||
|
||
export interface IGetAvailableDataCollectionsOptions extends IRequestOptions { | ||
/** | ||
* Optional parameter to specify an array of string values that describe what derivative variables to include in the output. | ||
*/ | ||
addDerivativeVariables?: string[]; | ||
/** | ||
* Optional parameter to return only values that are not NULL in the output response. | ||
*/ | ||
suppressNullValues?: boolean; | ||
/** | ||
* View a description for a single data collection within a given country. If not specified, will return a list of data collections that can be run in any country. | ||
*/ | ||
countryCode?: string; | ||
dataCollection?: string; | ||
} | ||
|
||
|
||
export interface IGetAvailableDataCollectionsResponse { | ||
DataCollections?: (IDataCollection)[] | null; | ||
} | ||
export interface IDataCollection { | ||
dataCollectionID: string; | ||
metadata: IMetadata; | ||
data?: (IDataInfo)[] | null; | ||
} | ||
export interface IMetadata { | ||
title: string; | ||
name: string; | ||
shortDescription: string; | ||
longDescription: string; | ||
url: string; | ||
keywords: string; | ||
creationDate: number; | ||
lastRevisionDate: number; | ||
webmap: string; | ||
author: string; | ||
countries?: string | null; | ||
IsRoyalties: boolean; | ||
categories?: ICategory[] | null; | ||
filters?: (IFilter)[] | null; | ||
datasets?: string | null; | ||
hierarchies: string; | ||
coverage?: string | null; | ||
mobileinfographics?: string | null; | ||
icon?: string | null; | ||
} | ||
export interface ICategory { | ||
id: string; | ||
name: string; | ||
alias: string; | ||
description: string; | ||
displayOrder: string; | ||
} | ||
export interface IFilter { | ||
id: string; | ||
name: string; | ||
aliasname: string; | ||
type: string; | ||
rangeMax?: string | null; | ||
rangeMin?: string | null; | ||
enumValues?: string | null; | ||
} | ||
export interface IDataInfo { | ||
id: string; | ||
alias: string; | ||
type: string; | ||
precision: number; | ||
length?: null; | ||
averageBase?: null; | ||
averageBaseAlias?: null; | ||
description: string; | ||
fieldCategory: string; | ||
indexBase?: number | null; | ||
percentBase?: string | null; | ||
percentBaseAlias?: string | null; | ||
popularity?: number | null; | ||
units: string; | ||
vintage?: string | null; | ||
hideInDataBrowser: boolean; | ||
filteringTags?: IFilteringTag[] | null; | ||
derivative: boolean; | ||
provider: string; | ||
indexType?: string | null; | ||
} | ||
export interface IFilteringTag { | ||
id: string; | ||
name: string; | ||
value: string; | ||
} | ||
|
||
|
||
/** | ||
* ```js | ||
* import { getAvailableDataCollections } from '@esri/arcgis-rest-demographics'; | ||
* // | ||
* getAvailableDataCollections() | ||
* .then((response) => { | ||
* response; // => { DataCollections: [ ... ] } | ||
* }); | ||
* // | ||
* getAvailableDataCollections({ | ||
* countryCode: "se", | ||
* dataCollection: "EducationalAttainment" | ||
* }) | ||
* .then((response) => { | ||
* response.; // => { DataCollections: [ ... ] } | ||
* }); | ||
* ``` | ||
* Used to determine the data collections available for usage with the Geoenrichment service. See the [REST Documentation](https://developers.arcgis.com/rest/geoenrichment/api-reference/data-collections.htm) for more information. | ||
* @param requestOptions Options to pass through to the geoenrichment service. | ||
* @returns A Promise that will resolve with data collections for the request. | ||
*/ | ||
export function getAvailableDataCollections( | ||
requestOptions?: IGetAvailableDataCollectionsOptions | ||
): Promise<IGetAvailableDataCollectionsResponse> { | ||
let options: IGetAvailableDataCollectionsOptions = {}; | ||
let endpoint: string = `${ARCGIS_ONLINE_GEOENRICHMENT_URL}/dataCollections`; | ||
|
||
|
||
if (!requestOptions) { | ||
options.params = {}; | ||
} else { | ||
options = appendCustomParams<IGetAvailableDataCollectionsOptions>( | ||
requestOptions, | ||
[ | ||
"addDerivativeVariables", | ||
"suppressNullValues", | ||
], | ||
{ params: { ...requestOptions.params } } | ||
); | ||
|
||
if (options.params.addDerivativeVariables) { | ||
options.params.addDerivativeVariables = JSON.stringify(options.params.addDerivativeVariables); | ||
} | ||
|
||
if(requestOptions.countryCode) { | ||
endpoint = `${endpoint}/${requestOptions.countryCode}`; | ||
if(requestOptions.dataCollection) { | ||
endpoint = `${endpoint}/${requestOptions.dataCollection}`; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
// add spatialReference property to individual matches | ||
return request(`${cleanUrl(endpoint)}`, options).then( | ||
(response: any) => { | ||
return response; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* Copyright (c) 2020 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
export const ARCGIS_ONLINE_GEOENRICHMENT_URL = | ||
"https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver/Geoenrichment"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* Copyright (c) 2020 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
export * from "./getAvailableDataCollections"; |
Oops, something went wrong.