Learn how to find an address the geocoding service.
Geocoding is the process of converting address or place text into a location. The geocoding service provides address and place geocoding as well as reverse geocoding.
In this tutorial, you use the geocode
class to find an address in Los Angeles, CA.
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
andreverse
classes from the_geocode arcgis.geocoding
module. Additionally, import thePoint
class from thearcgis.geometry
module.
from arcgis.gis import GIS
from arcgis.geocoding import geocode, reverse_geocode
from arcgis.geometry import Point
-
Log into ArcGIS Online as an anonymous user. Simple geocoding and reverse geocoding do not require credits, hence you need not log in using your credentials.
Use dark colors for code blocks from arcgis.gis import GIS from arcgis.geocoding import geocode, reverse_geocode from arcgis.geometry import Point gis = GIS()
Find an address
-
Search for an address by passing in the string "Hollywood sign" as the address parameter of the geocode function. The
geocode()
function is versatile and accepts a number of relevant parameters. Refer to Finding points of interest to learn more.Use dark colors for code blocks gis = GIS() geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result
Create a map
-
Create an instance of the map widget, set the initial extent by passing in a place name string of
Los Angeles, CA
and setting thezoom
equal to eleven.Level Use dark colors for code blocks geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result m = gis.map("Los Angeles, CA", zoomlevel=11) m
Display the results.
-
Use the
draw
method to display the results on the map. Since you specified theas
optional parameter while geocoding, you received the result as a_featureset= True Feature
object instead of a dictionary.Set Feature
objects can be easily drawn on the map widget by passing them to theSet draw()
method.Use dark colors for code blocks geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result m = gis.map("Los Angeles, CA", zoomlevel=11) m m.draw(geocode_result)
-
Use the
clear
method to remove the previous result graphics._graphics() Use dark colors for code blocks m = gis.map("Los Angeles, CA", zoomlevel=11) m m.draw(geocode_result) m.clear_graphics()
Try geocoding using the following addresses.
- Single line address:
380 New York St, Redlands, CA
- Administrative place name:
New York City
- Zipcode: 9254
- Single line address:
Reverse geocode a coordinate
-
Construct a
Point
geometry object for the following latitude and longitude:34.13419,-118.29636
. The coordinates specified here are in latitude, longitude which correspond to the spatial referenceGCS
. For a complete list of supported IDs and their corresponding definition strings, see: spatial references._WGS _1984 Use dark colors for code blocks m.clear_graphics() location = {"Y": 34.13419, "X": -118.29636, "spatialReference": {"wkid": 4326}} unknown_pt = Point(location)
-
Use the
reverse
function to find the address from a point location._geocode Use dark colors for code blocks location = {"Y": 34.13419, "X": -118.29636, "spatialReference": {"wkid": 4326}} unknown_pt = Point(location) address = reverse_geocode(location=unknown_pt) address
Display the results
- Use the
draw
method to add the results of thereverse
to the map._geocode
location = {"Y": 34.13419, "X": -118.29636, "spatialReference": {"wkid": 4326}}
unknown_pt = Point(location)
address = reverse_geocode(location=unknown_pt)
address
m.draw(address)
You should see the results of the reverse geocode displayed as a point graphic on the map.
What's next?
Learn how to use additional functionality in these tutorials: