English

Error: ArcGIS API for Python GeoEnrichment Error: Country aggregation mode supports only global data collections

Error Message

The ArcGIS Python function enrich_layer (arcgis.features.enrich_data module) is used to enrich multiple point locations with demographic information using the following code snippet:

from arcgis.gis import GIS
from arcgis.features.enrich_data import enrich_layer
# Connect to GIS
gis = GIS("Pro")

# Use analysis variables available for the the countries of interest
analysis_variables = [
    "KeyFacts.TOTPOP_CY",
    "HouseholdTotals.AVGHHSZ_CY",
    "KeyFacts.PP_CY",
    "Spending.CS01_CY"
]

points = [
    {"country": "Australia", "coords": (-33.918199,151.202186)},
    {"country": "Belgium", "coords": (51.051012,4.335651)},
    {"country": "Netherlands", "coords": (51.848607,4.669177)}
]

for point in points:
    country = point['country']
    coords = point['coords']

        pt_enrich = enrich_layer(
            coords,
            analysis_variables=analysis_variables,
            distance=30,
            units='Kilometers',
            buffer_type='StraightLine',
            return_boundaries=True,
        )
        print(pt_enrich.layer.featureSet.features[0].attributes)

This is working well for certain countries, but is failing for others with the error message:

{"messageCode": "AO_100000", "message": "Country aggregation mode supports only global data collections. Following data collections couldn't be processed: 'KeyFacts', 'HouseholdTotals', 'Spending'."}

According to the Data Browser at the following URL, https://la.arcgis.com/databrowser/index.html, all of the countries in the test (Australia, Belgium, and The Netherlands) should support these analysis variables.

Cause

The error message "Country aggregation mode supports only global data collections" indicates that the buffer distance from the input coordinates results in a polygon input feature for enrichment that intersects more than one country, which is only supported with global data collections and not with any analysis variables.

Depending on where the point coordinate is located, a 30-kilometer buffer from the input coordinates can intersect multiple countries, which is why the error is only encountered in some cases.

Solution or Workaround

There are two potential workarounds to this error:

Set the optional parameter called country in the enrich_layer method to limit the enrichment to a single country for each input point that gets buffered

from arcgis.gis import GIS
from arcgis.features.enrich_data import enrich_layer

# Connect to GIS
gis = GIS("Pro")

# Testing using analysis variables from a variety of collections
analysis_variables = [
    "KeyFacts.TOTPOP_CY",
    "HouseholdTotals.AVGHHSZ_CY",
    "KeyFacts.PP_CY",
    "Spending.CS01_CY"
]

points = [
    {"country": "Australia", "code": "AU", "coords": (-33.918199,151.202186)},
    {"country": "Belgium", "code": "BE", "coords": (51.051012,4.335651)},
    {"country": "Netherlands", "code": "NL", "coords": (51.848607,4.669177)}
]

for point in points:
    country = point['country']
    coords = point['coords']
    code = point['code']

        pt_enrich = enrich_layer(
            coords,
            analysis_variables=analysis_variables,
            country= code,
            distance=30,
            units='Kilometers',
            buffer_type='StraightLine',
            return_boundaries=True,
        )
        print(pt_enrich.layer.featureSet.features[0].attributes)

Use the arcgis.geoenrichment module all the KeyGlobalFacts can be aggregated for all countries

from arcgis.gis import GIS
from arcgis.geoenrichment import enrich, BufferStudyArea
from arcgis.geometry import Point

gis = GIS("Pro")

points = []

points.append(Point({"x" : 4.335651, "y" : 51.051012, "spatialReference" : {"wkid" : 4326}}))
points.append(Point({"x" : 151.202186, "y" : -33.918199, "spatialReference" : {"wkid" : 4326}}))
points.append(Point({"x" : 4.669177, "y" : 51.848607, "spatialReference" : {"wkid" : 4326}}))
points.append(Point({"x" : 114.125105, "y" : 22.343511, "spatialReference" : {"wkid" : 4326}}))

for pt in points:
    buffered = BufferStudyArea(area= pt, radii=[30], units='Kilometers', overlap=False)
    enriched = enrich(
        study_areas=[buffered],
        data_collections=['KeyGlobalFacts'],
        )
    print(enriched)

Related Information

Last Published: 7/22/2021

Article ID: 000025443

Software: ArcGIS API for Python 1.8.5, 1.8.4, 1.8.3, 1.8.2, 1.8.1, 1.8.0, 1.7.1, 1.7.0, 1.6.1, 1.6