The GeoEnrichment service provides detailed local data for specific countries. Each individual data field is represented by an analysis variable that are organized into data categories such as spending and market behaviors such as 2022 Educational Attainment
or 2022 Seen Video Ad at Gas Station Last 30 Days
. The data available vary by country and by data provider.
In this tutorial, you use ArcGIS REST JS to access the GeoEnrichment service and display spending trend information for a study area within the United States.
Prerequisites
You need 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. For local data set the
analysis
parameter.Variables -
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: 36.1745, y: -86.7679 } }], // Nashville, TN
analysisVariables: [
"PsychographicsShopping.MP28067A_B",
"transportation.X7027_I",
"entertainment.X9005_I",
"lifemodegroupsNEW.TLIFENAME"
],
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:
Get global data
Query demographic information for locations around the world with the GeoEnrichment service.
Edit feature data
Add, update, and delete data in a hosted feature layer.
Find place addresses
Find coffee shops, gas stations, restaurants and other nearby places by accessing the Geocoding service.