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
You need an ArcGIS Developer or ArcGIS Online account to access the developer dashboard and create an API key.
Steps
Create a new pen
- If you are using the CDN libraries, to get started.
Get an API Key
To access location services, you need an API key or OAuth 2.0 access token. To learn how to create and scope your key, visit the Create an API key tutorial.
- Go to your dashboard to get an API key. The API key must be scoped to access the services used in this tutorial.
- In CodePen, update
api
to use your key.Key
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
api
with the API key from your dashboard.Key -
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.0.0/dist/bundled/request.umd.js"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-demographics@4.0.0/dist/bundled/demographics.umd.js"></script>
<script>
/* when including ArcGIS REST JS all exports are available
from the same arcgisRest global */
const apiKey = "YOUR_API_KEY";
const authentication = arcgisRest.ApiKeyManager.fromKey(apiKey);
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: