Programmatic batch geocoding using Python and ArcGIS Organization account

3713
1
02-12-2013 06:51 AM
Jay_Gregory
Occasional Contributor III
I would like some assistance on best practices for programmatic (python) geocoding. 
I have some python scripts that parse various text files (csv, tsv, etc) and/or web pages, and create point feature classes from address information contained therein (currently using Google's geocoding).  What would be the best method to problematically using Esri's world geocoder (preferably through creating a Python function) if I have an ArcGIS for Org portal account.  All the examples I've seen refer to web applications

Here are my thoughts/options:

1. Call http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer for each record I want to geocode.  Will I bump up against a rate limit if I try to say, geocode, 1000 records in a script that runs over 30 seconds or so?

2. Generate a token and use that to batch geocode (although I'll still be calling the geocode service once per geocode).  How would I do this step?  Would I first get the token from this:

https://www.arcgis.com/sharing/generateToken?username=yourUserName&password=yourPassword&referer=htt... or do I have to get a token from my portal URL?

and then use the token to call this - through a python POST request:

http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=searchAddress&f=pjson&t...

3.  Would it be better to scratch single geocodes, and just format my addresses into a json string and use esri's batch geocoding functionality?  Would that be the same general process as outlined in step 2 except just using "SingleLine" input field?

Thanks for your input!

Jay
Tags (2)
0 Kudos
1 Reply
MichaelGayheart1
New Contributor III
Your post is almost a year old so I imagine you figured something out on your own, but I found this thread when I was searching for best practices myself and I came up with something that works for batch geocoding using python. In case someone else runs into this thread in the future, this is a solution that worked for me.

In our case, we have an employee table managed by another part of the company that contains addresses from all over the world. I can't write to their system, so a GIS representation of employee locations is kept in a different SQL Server Geodatabase. I don't want to batch geocode all 10,000 records each time, so I compare the address fields and if any records have been added/changed I write the rows to a temporary database.

I then use the GeocodeAddresses_geocoding python method described here: http://resources.arcgis.com/en/help/main/10.2/index.html#//002600000006000000. Note that you will need to add a GIS Server connection inside ArcCatalog to https://geocode.arcgis.com:443/arcgis/services/ (see attachment) using your AGOL organization user name and password. I found it useful to copy this connection from C:\Users\<USER>\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog to a fileshare so that the process can still get to the AGS connection even if it is run under a different user account.

Batch Geocoding seems to work fine using this method. I then go back to the resulting feature class and copy the shape, lat, lon, and some of the geocoding quality fields (e.g. score, rank, etc.) to my Geodatabase copy of the Employee feature class. Does that make sense? If you found another way, I would be curious to hear your approach too!
0 Kudos