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_
function can be used to find addresses of coordinates.
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
Geocode place names and addresses
-
Add the following code in a cell to import the ArcGIS API for Python.
Use dark colors for code blocks 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()
-
Geocode by query to locate the Hollywood sign. 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 from arcgis.gis import GIS from arcgis.geocoding import geocode, reverse_geocode from arcgis.geometry import Point gis = GIS() geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result.features
-
Display a map of Los Angeles to display the geocode result.
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() geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result.features m = gis.map("Los Angeles, CA", zoomlevel=11) m
-
Draw the geocode result on the map. Since you specified the
a
optional parameter while geocoding, you received the result as as_ 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 from arcgis.gis import GIS from arcgis.geocoding import geocode, reverse_geocode from arcgis.geometry import Point gis = GIS() geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result.features m = gis.map("Los Angeles, CA", zoomlevel=11) m m.draw(geocode_result)
-
Clear the map.
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() geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result.features 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 from arcgis.gis import GIS from arcgis.geocoding import geocode, reverse_geocode from arcgis.geometry import Point gis = GIS() geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result.features m = gis.map("Los Angeles, CA", zoomlevel=11) m m.draw(geocode_result) m.clear_graphics() location = { 'Y': 34.13419, 'X': -118.29636, 'spatialReference':{ 'wkid': 4326 } } unknown_pt = Point(location)
-
Reverse geocode the
Point
to get the address.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() geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result.features m = gis.map("Los Angeles, CA", zoomlevel=11) m m.draw(geocode_result) m.clear_graphics() location = { 'Y': 34.13419, 'X': -118.29636, 'spatialReference':{ 'wkid': 4326 } } unknown_pt = Point(location) address = reverse_geocode(location=unknown_pt) address
-
Draw the address on the map.
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() geocode_result = geocode(address="Hollywood sign", as_featureset=True) geocode_result.features m = gis.map("Los Angeles, CA", zoomlevel=11) m m.draw(geocode_result) m.clear_graphics() location = { 'Y': 34.13419, 'X': -118.29636, 'spatialReference':{ 'wkid': 4326 } } unknown_pt = Point(location) address = reverse_geocode(location=unknown_pt) address m.draw(address)