Learn how to query global demographic information for locations around the world with the GeoEnrichment service.
The GeoEnrichment service provides global demographic data for 170 countries and regions. To get globally available information, you use the Key
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
-
Import the
GIS
class from thearcgis.gis
module. TheGIS
class provides helper objects to manage (search, create, and access) GIS resources such as content, users, and groups. Additionally, import theGeometry
andPoint
classes from thearcgis.geometry
module and theenrich
method from thearcgis.geoenrichment
module.Use dark colors for code blocks from arcgis.gis import GIS from arcgis.geometry import Geometry, Point from arcgis.features import FeatureSet from arcgis.geoenrichment import enrich
-
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 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
-
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 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
-
Use the
enrich
function, passing in the study area point and the data collection text string ofKey
to get the demographic data. To learn more about data collections, go to Data enrichment.Global Facts Use dark colors for code blocks 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
-
Create a
map
and set itsbasemap
toarcgis-navigation
.Use dark colors for code blocks 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
-
Use the enrichment results to construct a
Popup
object.Info Use dark colors for code blocks # 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))
-
Use the
add
method and pass in the enriched geomety and popup info to add the results to the maps content. Set theextent
of the map to the result geometry's extent by calling thezoom
method._to _layer Use dark colors for code blocks # 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: