batch_geocoding

Batch geocoding

  1. Premium operation, requires credits
  2. MaxBatchSize property of the Geocoder
In [1]:
from arcgis.gis import GIS
from arcgis import geocoding
from getpass import getpass
In [6]:
password= getpass()
gis = GIS("https://pycontraptions.maps.arcgis.com", "atma_mani", password)

# use the first of GIS's configured geocoders
geocoder = geocoding.get_geocoders(gis)[0]
········
In [3]:
print("MaxBatchSize : " + str(geocoder.properties.locatorProperties.MaxBatchSize))
print("SuggestedBatchSize : " + str(geocoder.properties.locatorProperties.SuggestedBatchSize))
MaxBatchSize : 1000
SuggestedBatchSize : 150

Batch geocode access

An ArcGIS Online organizational account is required to use the batch geocoding functionality provided by the World Geocoding Service. Successfully geocoded addresses, which return a status of Matched or Tied, cause ArcGIS Online service credits to be consumed for batch geocoding operations.

Example: batch geocode using single line addresses

In [4]:
addresses = ["380 New York St, Redlands, CA", 
             "1 World Way, Los Angeles, CA",
             "1200 Getty Center Drive, Los Angeles, CA", 
             "5905 Wilshire Boulevard, Los Angeles, CA",
             "100 Universal City Plaza, Universal City, CA 91608",
             "4800 Oak Grove Dr, Pasadena, CA 91109"]
In [7]:
results = geocoding.batch_geocode(addresses)
In [8]:
len(results)
Out[8]:
6
In [9]:
results[0]
Out[9]:
{'address': '380 New York St, Redlands, California, 92373',
 'attributes': {'AddBldg': '',
  'AddNum': '380',
  'AddNumFrom': '',
  'AddNumTo': '',
  'Addr_type': 'PointAddress',
  'City': 'Redlands',
  'Country': 'USA',
  'DisplayX': -117.195311,
  'DisplayY': 34.05611,
  'Distance': 0,
  'LangCode': 'ENG',
  'Loc_name': 'USA.PointAddress',
  'Match_addr': '380 New York St, Redlands, California, 92373',
  'Nbrhd': '',
  'Phone': '',
  'PlaceName': '',
  'Place_addr': '',
  'Postal': '92373',
  'PostalExt': '',
  'Rank': '',
  'Region': 'California',
  'ResultID': 0,
  'Score': 100,
  'Side': 'R',
  'StAddr': '380 New York St',
  'StDir': '',
  'StName': 'New York',
  'StPreDir': '',
  'StPreType': '',
  'StType': 'St',
  'Status': 'M',
  'Subregion': 'San Bernardino',
  'Type': '',
  'URL': '',
  'X': -117.195667,
  'Xmax': -117.194667,
  'Xmin': -117.196667,
  'Y': 34.05649,
  'Ymax': 34.05749,
  'Ymin': 34.05549},
 'location': {'x': -117.1956663679997, 'y': 34.056490358000474},
 'score': 100}
In [10]:
map1 = gis.map("Los Angeles", 9)
map1
In [11]:
for address in results:
    map1.draw(address['location'])

Batch geocoding multifield addresses

In [12]:
addresses= [{
                "Address": "380 New York St.",
                "City": "Redlands",
                "Region": "CA",
                "Postal": "92373"
            },{
                "Address": "1 World Way",
                "City": "Los Angeles",
                "Region": "CA",
                "Postal": "90045"
            }]
In [13]:
results_multif = geocoding.batch_geocode(addresses)
In [ ]:
map2 = gis.map("Los Angeles", 9)
map2
In [ ]:
for address in results_multif:
    map2.draw(address['location'])

Example: Batch geocode airport codes with category

In [14]:
airports = geocoding.batch_geocode(["LAX", "SFO", "ONT", "FAT", "LGB"])
#airports = geocoding.batch_geocode(["LAX", "SFO", "ONT", "FAT", "LGB"], category="airport")
In [15]:
len(airports)
Out[15]:
5
In [18]:
airports[-1]
Out[18]:
{'address': '',
 'attributes': {'AddBldg': '',
  'AddNum': '',
  'AddNumFrom': '',
  'AddNumTo': '',
  'Addr_type': '',
  'City': '',
  'Country': '',
  'DisplayX': 0,
  'DisplayY': 0,
  'Distance': 0,
  'LangCode': '',
  'Loc_name': '',
  'Match_addr': '',
  'Nbrhd': '',
  'Phone': '',
  'PlaceName': '',
  'Place_addr': '',
  'Postal': '',
  'PostalExt': '',
  'Rank': '',
  'Region': '',
  'ResultID': 4,
  'Score': 0,
  'Side': '',
  'StAddr': '',
  'StDir': '',
  'StName': '',
  'StPreDir': '',
  'StPreType': '',
  'StType': '',
  'Status': 'U',
  'Subregion': '',
  'Type': '',
  'URL': '',
  'X': 0,
  'Xmax': 0,
  'Xmin': 0,
  'Y': 0,
  'Ymax': 0,
  'Ymin': 0},
 'score': 0}
In [ ]:
map3 = gis.map("CA", 6)
map3
In [ ]:
for airport in airports:
    popup = { 
    "title" : airport['attributes']['PlaceName'], 
    "content" : airport['address']
    }
    map3.draw(airport['location'], popup)

Exercise: batch geocode the NYC_addreses_batch_geocode_exercise.csv file

Steps:

  1. read the csv using pandas
  2. Read the address column from the pandas dataframe
  3. Make it a list and send it to the batch geocode function
  4. get the results and plot that on the map
In [ ]: