Skip To Content ArcGIS for Developers Sign In Dashboard

Overview

You will learn: how to find an address or place using the ArcGIS World Geocoding Service.

The ArcGIS World Geocoding Service can find addresses and places, convert addresses to coordinates, and perform batch geocoding. The geocoding module contains the geocode() function for forward geocoding that can be used to search for single field addresses, multi-field addresses, points of interest etc. The reverse_geocode() function can be used to find addresses of coordinates.

Before you begin

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

Create a new notebook

  1. Go to Esri Juptyter Notebooks and click New > Python 3 to create a new notebook.

    In each step below, type (or copy and paste) the commands into a new notebook cell and run the code by clicking run cell or pressing shift + Enter.

  1. Add the following code in a cell to import the ArcGIS API for Python.

    from arcgis.gis import GIS
    from arcgis.geocoding import geocode, reverse_geocode
    from arcgis.geometry import Point
    
  2. Log into ArcGIS Online as an anonymous user.

    gis = GIS()
    

Geocode place names and addresses

  1. Geocode by query to locate the Hollywood sign.

    geocode_result = geocode(address="Hollywood sign", as_featureset=True)
    
    # A list of features
    geocode_result.features
    
  2. Display a map of Los Angeles to display the geocode result.

    m = gis.map("Los Angeles, CA", zoomlevel=11)
    m
    
  3. Draw the geocode result on the map.

    m.draw(geocode_result)
    
  4. Clear the map and try geocoding the following addresses.

    • Single line address: 380 New York St, Redlands, CA
    • Administrative place name: New York City
    • Zip code: 92354
    m.clear_graphics()
    

Reverse geocode a coordinate

  1. Construct a Point geometry object for the following latitude and longitude: 34.13419,-118.29636.

    location = {
         'Y': 34.13419,                 # `Y` is latitude
         'X': -118.29636,               # `X` is longitude
         'spatialReference': {
             'wkid':4326
         }
    }
    unknown_pt = Point(location)
    
  2. Reverse geocode the Point to get the address.

    address = reverse_geocode(location=unknown_pt)
    address
    
  3. And draw it on the map.

    m.draw(address)
    

Congratulations, you're done!

Your notebook should look something like this.

Challenges

Geocode Multiple Points of Interest

Find multiple points of interest using the geocode function. For example, suppose you want to search for Fish Tacos in Portland, Oregon.

First create a query as a dict.

fish_query_portland = {
  'Address': 'fish tacos',
  'City': 'Portland',
  'Region': 'OR'
}

Then create a map located in Portland, OR.

m = gis.map('Portland, Oregon', zoomlevel=11)
m

And then draw the geocoded locations.

fish_tacos_places = geocode(fish_query_portland)
for fish_taco_place in fish_taco_places:
    m.draw(fish_taco_place['location'])