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 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. 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.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: 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.