Tutorial: Get local data

Learn how to access local data, such as spending trends, for the United States with the .

Python mapping widget displaying results of local data enrichment.

The GeoEnrichment service provides detailed local data for specific countries. Each individual data field is represented by an . Analysis variables are organized into data categories such as spending and market behaviors with names such as 2024 Educational Attainment or 2024 Seen Video Ad at Gas Station Last 30 Days. The data available varies by country and by data provider.

In this tutorial, you use the GeoEnrichment service to display spending trend information for a study area within the United States.

Steps

Import modules and log in

  1. Import the GIS class from the arcgis.gis module. The GIS class provides helper objects to manage (search, create, and manage) GIS resources such as content, users, and groups. Additionally, import the Geometry and Point classes from the arcgis.geometry module, the FeatureSet class from arcgis.features module and the Country method from the arcgis.geoenrichment module.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    
    from arcgis.gis import GIS
    from arcgis.features import FeatureSet
    from arcgis.geoenrichment import Country
    from arcgis.geometry import Geometry, Point
    
    
    
  2. Log in to your . In a hosted notebook, You can use the home parameter to use the credentials of the currently logged in account.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    
    from arcgis.gis import GIS
    from arcgis.features import FeatureSet
    from arcgis.geoenrichment import Country
    from arcgis.geometry import Geometry, Point
    
    
    portal = GIS("home")
    print(f"Connected to {portal.properties.name} as {portal.properties.user.username}")
    
    

Create study area point

  1. Use the Point class to construct a point geometry by passing in the and representing a location in Nashville, Tennessee.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    
    portal = GIS("home")
    print(f"Connected to {portal.properties.name} as {portal.properties.user.username}")
    
    study_area_pt = Point({"x": -86.7679, "y": 36.1745, "spatialReference": {"wkid": 4326}})
    
    

Get demographic data

  1. Use the Country class from the arcgis.geoenrichment module. This provides access to local variables for a specific country. Pass in the study area point and the following variable names :

    • PsychographicsShopping.MP28067A_B
    • transportation.X7027_I
    • entertainment.X9005_I
    • lifemodegroupsNEW.TLIFENAME

    To learn more about the data collections and variables, go to Data Collections and GeoEnrichment coverage.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    
    study_area_pt = Point({"x": -86.7679, "y": 36.1745, "spatialReference": {"wkid": 4326}})
    
    usa_data = Country("usa", portal)
    
    enrich_results = usa_data.enrich(
        study_areas=[study_area_pt],
        enrich_variables=[
            "PsychographicsShopping.MP28067A_B",
            "transportation.X7027_I",
            "entertainment.X9005_I",
            "lifemodegroupsNEW.TLIFENAME",
        ],
    )
    
    
  2. To view the values returned from the enrichment, use the dataframe object returned from the enrich method to display the results as a table. Pass in an array of field names to limit the results to a subset of columns.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    
    usa_data = Country("usa", portal)
    
    enrich_results = usa_data.enrich(
        study_areas=[study_area_pt],
        enrich_variables=[
            "PsychographicsShopping.MP28067A_B",
            "transportation.X7027_I",
            "entertainment.X9005_I",
            "lifemodegroupsNEW.TLIFENAME",
        ],
    )
    
    
    display_cols = [
        "aggregation_method",
        "population_to_polygon_size_rating",
        "apportionment_confidence",
        "tlifename",
        "x9005_i",
        "mp28067a_b",
        "x7027_i",
    ]
    enrich_results[display_cols]
    
    

Display the results on a map

  1. Use the map property from the GIS class to create a map. To set the initial extent of the map, pass in the string Nashville, TN This will set the map to an extent that is appropriate for the results. Set the basemap of the map to arcgis-navigation.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    
    
    display_cols = [
        "aggregation_method",
        "population_to_polygon_size_rating",
        "apportionment_confidence",
        "tlifename",
        "x9005_i",
        "mp28067a_b",
        "x7027_i",
    ]
    enrich_results[display_cols]
    
    map = portal.map("Nashville, TN")
    map.basemap.basemap = "arcgis-navigation"
    map
    
    
  2. Use the FeatureSet class to convert the returned Pandas DataFrame into a . Create a popup object that will display formatted attribute values when a feature is clicked in the map.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    
    map = portal.map("Nashville, TN")
    map.basemap.basemap = "arcgis-navigation"
    map
    
    enrich_features = FeatureSet.from_dataframe(enrich_results)
    enrich_features
    
    # set popup info
    from arcgis.map.popups import PopupInfo
    popup_fields = [
        "Buys natural products: {mp28067a_b}",
        "Membership fees for Social Clubs: {x9005_i}",
        "Auto/Truck rental on trips: {x7027_i}",
        "Tapestry group name: {tlifename}",
    ]
    pi = PopupInfo(
      title="Data for a 1 mile search radius",
      description="<br>".join(popup_fields)
    )
    
    
    
  3. Use the add method to pass in the enriched geometry and popup info to add the results to the map content.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    
    enrich_features = FeatureSet.from_dataframe(enrich_results)
    enrich_features
    
    # set popup info
    from arcgis.map.popups import PopupInfo
    popup_fields = [
        "Buys natural products: {mp28067a_b}",
        "Membership fees for Social Clubs: {x9005_i}",
        "Auto/Truck rental on trips: {x7027_i}",
        "Tapestry group name: {tlifename}",
    ]
    pi = PopupInfo(
      title="Data for a 1 mile search radius",
      description="<br>".join(popup_fields)
    )
    
    
    map.content.add(enrich_features, popup_info=pi)

You should see a map centered around Nashville, TN with a graphic representing a 1 mile radius around the study area point. Click on the graphic to display a popup containing local demographic values.

What's next?

Learn how to use additional functionality in these tutorials:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close