geomate is a automate geocoding tools using Google GeoCoding API.
Basically, you only need to do three things, and geomate will take care of everything else for you:
import geomate import pprint # put your google map API key here, what you see here is all fake api_keys = [ "GoogleGeoCodingApiKey01", # user1 "GoogleGeoCodingApiKey02", # user2 ... "GoogleGeoCodingApiKey99", # user991ihu8", ] # create a google geocode API client googlegeocoder = geomate.GoogleGeocoder(api_keys=api_keys) googlegeocoder.check_usable() # show you which keys are available # bind to a geocoder and database batch = geomate.BatchGeocoder(googlegeocoder, db_file="geocode.sqlite3") # construct your todo address list anyway you want list_of_address = [ "675 15th St NW Washington, DC 20005", "2317 Morgan Ln Dunn Loring, VA 22027", "1201 Rockville Pike Rockville, MD 20852", (39.085801, -77.084513), (38.872719, -77.306417), (38.902027, -77.053536), ] batch.process_this(list_of_address) # process everything # see what's we have done for address in list_of_address: pprint.pprint(batch.lookup(address))
Suppose you got 10000 address, but 5000 of them are invalid address, which is not able to geocoded. And invalid address happens to be at begin of the queue. You probably don’t want to waste API quota on that. geomate provide a keyword shuffle to randomlly perform the geocoding, so in average, you can get most of valid address geocoded in a short time:
Here’s something may helpful. Basically there are two steps in the processing:
So you can take advantage of this for more flexible batch geocoding process.
You can easily retrieve the geocoded data by:
for address in list_of_address: data = batch.lookup(address) pprint(data)
Of course you can also manually read it from sqlite database.
geomate is released on PyPI, so all you need is:
$ pip install geomate
To upgrade to latest version:
$ pip install --upgrade geomate
Prerequisit: geopy, to install:
$ pip install geopy