Tutorial: Get global data

Learn how to query global demographic information for locations around the world with the GeoEnrichment service.

Python mapping widget displaying results of global data enrichment.

The GeoEnrichment service provides global demographic data for 170 countries and regions. To get globally available information, you use the KeyGlobalFacts 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 the GeoEnrichment service and display global data for a point near London, England.

Prerequisites

The ArcGIS API for Python tutorials use Jupyter Notebooks to execute Python code. If you are new to this environment, please see the guide to install the API and use notebooks locally.

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 access) GIS resources such as content, users, and groups. Additionally, import the Geometry and Point classes from the arcgis.geometry module and the enrich method from the arcgis.geoenrichment module.

    Use dark colors for code blocks
    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
    
    from arcgis.gis import GIS
    from arcgis.geometry import Geometry, Point
    from arcgis.features import FeatureSet
    from arcgis.geoenrichment import enrich
    
    
    
  2. Log in to your portal. In hosted notebooks, You can use the "home" parameter to use the credentials of the currently logged in account.

    Use dark colors for code blocks
    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
    
    from arcgis.gis import GIS
    from arcgis.geometry import Geometry, Point
    from arcgis.features import FeatureSet
    from arcgis.geoenrichment import enrich
    
    
    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 coordinates and spatial reference representing a location in London, England.

    Use dark colors for code blocks
    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
    
    portal = GIS("home")
    print(f"Connected to {portal.properties.name} as {portal.properties.user.username}")
    
    study_area_pt = Point(
        {"x": 0.1278, "y": 51.5074, "spatialReference": {"wkid": 4326}}
    )  # London, England
    
    

Get demographic data

  1. Use the enrich function, passing in the study area point and the data collection text string of KeyGlobalFacts to get the demographic data. To learn more about data collections, go to Data enrichment.

    Use dark colors for code blocks
    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
    
    study_area_pt = Point(
        {"x": 0.1278, "y": 51.5074, "spatialReference": {"wkid": 4326}}
    )  # London, England
    
    enrichment_results = enrich(
        study_areas=[study_area_pt], data_collections=["KeyGlobalFacts"]
    )
    enrichment_results
    
    enriched_features = FeatureSet.from_dataframe(enrichment_results)
    enriched_features
    
    

Display the results

  1. Create a map and set its basemap to arcgis-navigation.

    Use dark colors for code blocks
    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
    
    enrichment_results = enrich(
        study_areas=[study_area_pt], data_collections=["KeyGlobalFacts"]
    )
    enrichment_results
    
    enriched_features = FeatureSet.from_dataframe(enrichment_results)
    enriched_features
    
    map = portal.map("London, England")
    map.basemap.basemap = "arcgis-navigation"
    map
    
    
  2. Use the enrichment results to construct a PopupInfo object.

    Use dark colors for code blocks
    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
    
    # set popup info
    from arcgis.map.popups import PopupInfo
    popup_fields = [
        "Population: {totpop}",
        "Males: {totmales}",
        "Females: {totfemales}",
        "Average household size: {avghhsz}",
    ]
    pi = PopupInfo(title="Data for a 1 mile search radius", description="<br>".join(popup_fields))
    
    
  3. Use the add method and pass in the enriched geomety and popup info to add the results to the maps content. Set the extent of the map to the result geometry's extent by calling the zoom_to_layer method.

    Use dark colors for code blocks
    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
    
    # set popup info
    from arcgis.map.popups import PopupInfo
    popup_fields = [
        "Population: {totpop}",
        "Males: {totmales}",
        "Females: {totfemales}",
        "Average household size: {avghhsz}",
    ]
    pi = PopupInfo(title="Data for a 1 mile search radius", description="<br>".join(popup_fields))
    
    map.content.add(enriched_features, popup_info=pi)
    map.zoom_to_layer(enriched_features)

You should now see a map centered around London, England with a polygon graphic representing a 1 mile radius around the study area point. Click on the graphic to display a popup to view global 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.