Overview

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

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 DevLabs use Jupyter Notebooks to execute Python code. If you are new to Python, please see the ArcGIS API for Python guide to Using the Jupyter notebook environment.

Steps

Geocode place names and addresses

  1. Go to the Esri Jupyter Notebook 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.

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

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

    dev_gis = GIS()
    
  4. Search for the Hollywood sign.

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

    map1 = dev_gis.map("Los Angeles, CA", zoomlevel=11)
    map1
    
  6. Draw the geocode result on the map.

    map1.draw(geocode_result)
    
  7. 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
    map1.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,'X':-118.29636,
                'spatialReference':{
                'wkid':4326}
               }
    unknown_pt = Point(location)
    
  2. Reverse geocode the Point to get the address

    address = reverse_geocode(location=unknown_pt)
    address
    

Congratulations, you're done!

Your notebook should look something like this

Challenge

Reverse geocode a point in projected coordinate system

Reverse geocode the coordinates X: -8575656.166250402, Y: 4707061.441484527 to find its address. Use spatial references to lookup the wkid for WGS_1984_Web_Mercator_Auxiliary_Sphere which is the coordinate system for the above coordinates.