Learn how to find an address, business, or place with the geocoding service.
You can perform place geocoding with the geocoding service. Place geocoding is the process of searching for addresses for businesses, administrative locations, and geographic features. You can search for the name of a place and/or you can provide categories to filter the results.
In this tutorial, you use the geocode
function to find places around the Santa Monica mountains area.
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
arcgis.gis
module. This module is the entry point into the GIS and provides the functionality to manage GIS content, users, and groups. Additionally, import thegeocode
class from thearcgis.geocoding
module, which provides types and functions for geocoding, batch geocoding and reverse geocoding.Use dark colors for code blocks from arcgis.gis import GIS from arcgis.geocoding import geocode
-
Use the
GIS
class to log in anonymously to ArcGIS Online. Since the results are not stored, you do not need credentials to call the geocoding service.Use dark colors for code blocks from arcgis.gis import GIS from arcgis.geocoding import geocode gis = GIS()
Find coffee shops near a point
-
Pass the relevant parameters into the geocode function and get a
Feature
as the result. Use theSet location
,category
,out
, and_fields max
parameters to request the names, addresses, and locations of 25 coffee shops near a point in the Santa Monica Mountains. Set the_location as
parameter to_featureset true
to return the results as a feature set so that they can be easily added to a map.Use dark colors for code blocks from arcgis.gis import GIS from arcgis.geocoding import geocode gis = GIS() geocoded_features = geocode( address=None, location=[-118.71511, 34.09042], category="Coffee shop", out_fields="Place_addr, PlaceName", max_locations=25, as_featureset=True, )
Review the results
-
Use the
sdf
property of aFeature
to convert the feature set into a spatial data frame and render the first two locations.Set Use dark colors for code blocks from arcgis.gis import GIS from arcgis.geocoding import geocode gis = GIS() geocoded_features = geocode( address=None, location=[-118.71511, 34.09042], category="Coffee shop", out_fields="Place_addr, PlaceName", max_locations=25, as_featureset=True, ) geocoded_df = geocoded_features.sdf geocoded_df.head(2)
Map the results
-
Use the
map
method of theGIS
class to create a map widget.Use dark colors for code blocks geocoded_df = geocoded_features.sdf geocoded_df.head(2) map = gis.map() map
-
Once the map has loaded, use the
add
method to add the results to the map content and thezoom
method to update the maps extent to show the geocoded features._to _layer Use dark colors for code blocks map = gis.map() map from arcgis.map.popups import PopupInfo map.content.add(geocoded_features, popup_info=PopupInfo(title="{PlaceName}", description="Address: {Place_addr}")) map.zoom_to_layer(geocoded_features)
You should see the results displayed as graphic points on the map.
-
Optional: Use the
export
method to export the current state of the map widget to a static HTML file which can be viewed in any web browser._to _html Use dark colors for code blocks from os import path, getcwd export_dir = path.join(getcwd(), "home") if not path.isdir(export_dir): os.mkdir(export_dir) export_path = path.join(export_dir, "find-place-addresses.html") m.export_to_html(export_path, title="Find place addresses")
What's next?
Learn how to use additional functionality in these tutorials: