Select to view content in your preferred language

Geocoding using python, need help~

3294
5
Jump to solution
01-06-2013 03:42 PM
chrislim1
Emerging Contributor
Hi, i am trying to currently working on a assignment that would require me to perform geocoding against a JSON object containing a array of addresses. im looking at using python to achieve this functionality. Initial research on arcgis api has yielded little results so i was wondering is there anyone on the forum can point me in the correct direction? is it do-able?
ps. im a complete newbie to python, just picked up the language a few days ago so go easy on me guys~
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
BruceHarold
Esri Regular Contributor
Hi

ArcPy recordsets (and featuresets) can be converted to and from JSON using the .JSON and .AsShape methods, so that part is easy, within a script or model embedding a script.  You can geocode a recordset (treat it like a table in other words) or load it into an in_memory table to geocode it.

If you are using ArcGIS Online there is a REST endpoint for batch geocoding, but don't go down that track unless you need to.

http://resources.arcgis.com/en/help/arcgis-online-geocoding-rest-api/

Regards

View solution in original post

0 Kudos
5 Replies
DavidEmmith
New Contributor
Hi, i am trying to currently working on a assignment that would require me to perform geocoding against a JSON object containing a array of addresses. im looking at using python to achieve this functionality. Initial research on arcgis api has yielded little results so i was wondering is there anyone on the forum can point me in the correct direction? is it do-able?
ps. im a complete newbie to python, just picked up the language a few days ago so go easy on me guys~


You're going to want to tackle this problem using regular expressions. There may already be modules out there written to parse JSON objects. You'll need to hunt around a bit.
http://docs.python.org/2/library/re.html
0 Kudos
BruceHarold
Esri Regular Contributor
Hi

Regexes are a wormhole you might not want to dive into.

The canonical approach to geocoding an array of addresses would be to write them into a table (a text file is OK, provided it has recognised delimiters and header) and geocode the table.

Regards
0 Kudos
chrislim1
Emerging Contributor
You're going to want to tackle this problem using regular expressions. There may already be modules out there written to parse JSON objects. You'll need to hunt around a bit.
http://docs.python.org/2/library/re.html


Thanks for the suggestion 😃 i presume the regex expression is used in the extraction of the values in the JSON object? For that aspect, i am currently using the json library for the extraction. i find it simpler and easier(both code-wise and on the eyes) compared to regex coz i REALLLLYYYY hate regex expressions LOL. too confusing to deal with @.@ thanks again for the help!

Hi

Regexes are a wormhole you might not want to dive into.

The canonical approach to geocoding an array of addresses would be to write them into a table (a text file is OK, provided it has recognised delimiters and header) and geocode the table.

Regards


Hi!
i am (or my boss to be exact) actually planning to, eventually, publish this as a REST service. Therefore, i would have json objects coming in, which values will be extracted into addresses and passed into geocode engine for batch processing so is it possible to actually stream the addresses into the geocode engine using python instead of outputing the addresses to a database table file(excel,dbf,csv etc.)?
Currently, i have a completed but not working model built using the modelbuilder which actually takes in a recordset and pass it to the geoprocessor which would process the addresses and batch geocode them with a composite address locator.
Is that the correct way to do it if the expected input is a json object?
if yes then would i nid to extract them into strings and pass it in or i can just pass them in as a whole json object?
i checked the arcpy api and the input for recordset is a table(?) which i really do not know whats its refering to.. 😧

EDIT: Assuming that the recordset method is the way to go, i tried to input sample data into the recordset's table in the modelbuilder for geocoding. After finalizing my sample data input with the apply and ok buttons, when i reopen the recordset's properties interface, all the sample data in the recordset's table disappears. Am i doing something wrong?
ps. the table for the recordset is pointing to a pathname called "in_memory/{insert random number here}" and i am unable to change it. Is that the reason why my data keeps disappearing?

oh and i am currently using arcgis for desktop 10.1
0 Kudos
BruceHarold
Esri Regular Contributor
Hi

ArcPy recordsets (and featuresets) can be converted to and from JSON using the .JSON and .AsShape methods, so that part is easy, within a script or model embedding a script.  You can geocode a recordset (treat it like a table in other words) or load it into an in_memory table to geocode it.

If you are using ArcGIS Online there is a REST endpoint for batch geocoding, but don't go down that track unless you need to.

http://resources.arcgis.com/en/help/arcgis-online-geocoding-rest-api/

Regards
0 Kudos
chrislim1
Emerging Contributor
Hi

ArcPy recordsets (and featuresets) can be converted to and from JSON using the .JSON and .AsShape methods, so that part is easy, within a script or model embedding a script.  You can geocode a recordset (treat it like a table in other words) or load it into an in_memory table to geocode it.

If you are using ArcGIS Online there is a REST endpoint for batch geocoding, but don't go down that track unless you need to.

http://resources.arcgis.com/en/help/arcgis-online-geocoding-rest-api/

Regards


Oh thats was what i am desperately looking for! cant believe i didn see that in the api. Ah i see, thanks for the help! really saved my arse from the fire @.@
0 Kudos