The GeoEnrichment service provides global demographic data for 170 countries and regions. To get globally available information, you use the Key
data collection, which returns information for the total population, total households, average household size, and total population for males and females for a study area.
In this tutorial, you use ArcGIS REST JS to access the GeoEnrichment service and display global data for Eastern Europe.
Prerequisites
This tutorial requires an ArcGIS Location Platform or ArcGIS Online account.
Steps
Create a new pen
- If you are using the CDN libraries, to get started.
Get an access token
You need an access token with the correct privileges to access the resources used in this tutorial.
-
Go to the Create an API key tutorial and create an API key with the following privilege(s):
- Privileges:
- Location services > Data enrichment
- Privileges:
-
Copy the API key access token to your clipboard when prompted.
-
In CodePen, update the
access
variable to use your access token.Token Use dark colors for code blocks Copy const accessToken = "YOUR_ACCESS_TOKEN"; const authentication = arcgisRest.ApiKeyManager.fromKey(accessToken);
To learn about the other types of authentication available, go to Types of authentication.
Make the request
You can copy and paste the code below, following the steps to make a request to the GeoEnrichment service.
-
Reference the ArcGIS REST JS libraries either through CDN, ES Modules, or Node JS.
-
- Set the
access
with an API key access token from API key credentials.Token
- Set the
-
Define the parameters needed for the request. To return global data, set the
data
parameter toCollections ["
.Key Global Facts"] -
Call the Geoenrichment service and handle the results.
<!-- require ArcGIS REST JS libraries from https://unpkg.com -->
<script src="https://unpkg.com/@esri/arcgis-rest-request@4/dist/bundled/request.umd.js"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-demographics@4/dist/bundled/demographics.umd.js"></script>
<script>
/* when including ArcGIS REST JS all exports are available
from the same arcgisRest global */
const accessToken = "YOUR_ACCESS_TOKEN";
const authentication = arcgisRest.ApiKeyManager.fromKey(accessToken);
arcgisRest
.queryDemographicData({
studyAreas: [{ geometry: { x: 0.1278, y: 51.5074 } }], // London
dataCollections: ["KeyGlobalFacts"],
authentication: authentication
})
.then((response) => {
console.log("Demographics:", response);
document.getElementById("result").textContent = JSON.stringify(response, null, 2);
});
</script>
Result
Below is the response from the service:
{
"results": [
{
"paramName": "GeoEnrichmentResult",
"dataType": "GeoEnrichmentResult",
"value": {
"version": "2.0",
"FeatureSet": [
{
"displayFieldName": "",
"fieldAliases": {
"ID": "Id",
"OBJECTID": "Object ID",
"sourceCountry": "Country code",
"areaType": "Area type",
"bufferUnits": "Buffer units",
"bufferUnitsAlias": "Buffer units alias",
"bufferRadii": "Buffer radii",
"aggregationMethod": "Aggregation method",
"populationToPolygonSizeRating": "Population to polygon size rating for the country",
"apportionmentConfidence": "Apportionment confidence for the country",
"HasData": "Has data",
"MP28067a_B": "2022 Buy Natural Prods for Env Concerns: 4-Agr Cmpl",
"X7027_I": "2022 Index: Auto/Truck Rental on Trips",
"X9005_I": "2022 Index: Membership Fees-Social/Rec/Health Clubs",
"TLIFENAME": "2022 Dominant LifeMode Grp Name"
},
"spatialReference": {
"wkid": 4326,
"latestWkid": 4326
What's next?
Learn how to use additional ArcGIS location services in these tutorials: