How to geocode a single address (not table of addresses) in ModelBuilder and/or python Script? I want to enter the address and then geocode it. I am using arcgis 10.2.2


The geopy module is quick and easy for tasks such as this. Straight from the docs:

>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim()
>>> location = geolocator.geocode("175 5th Avenue NYC")
>>> print(location.address)
Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, ...
>>> print(location.latitude, location.longitude)
(40.7410861, -73.9896297241625)
>>> print(location.raw)
{u'place_id': u'9167009604', u'type': u'attraction', ...}

Note that it includes classes to use just about any geocoding service that is out there.


I wrote a quick little function to do this with the ESRI python libraries You can grab it at: https://community.esri.com/groups/arcgis-python-api/blog/2018/12/28/single-address-geocode-with-python or just check out the code below

import requests
geoCodeUrl = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"

def singleAdressGeocode(address, geoCodeUrl, outSR = "4326"):
  #clean up the address for url encoding
  address = address.replace(" ", "+")
  address = address.replace(",", "%3B")

  #send address to geocode service
  lookup = requests.get(geoCodeUrl + "?SingleLine=" + address + "&outSR=" + outSR + "&maxLocations=1&f=pjson")
  data = lookup.json()

  if data["candidates"]:
    #woo hoo results
    coords = data["candidates"][0]["location"]
    return coords
    #no results
    return "Address not geocoded: " + address

print singleAdressGeocode("1600 Pennsylvania Ave NW, Washington, DC 20500", geoCodeUrl)
  • 1
    Welcome to GIS SE. As a new user, please take the Tour/ Please Edit your answer to post the actual code, not just a link to it. Both questions and answers here are expected to be local to Stack Exchange, so that link failure does not destroy the content. – Vince Dec 28 '18 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.