Skip to content

Instantly share code, notes, and snippets.

@pdbartsch
Last active January 14, 2024 12:43
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pdbartsch/5987932 to your computer and use it in GitHub Desktop.
Save pdbartsch/5987932 to your computer and use it in GitHub Desktop.
open-refine geocoding using OpenStreetMap's Nominatim service. (previously called google-refine)
Step One - Starting with a single address field
Edit Column > Add Column by Fetching URLs
Nominatim has a limit of 1 geocode per second so make sure to set the throttle delay to greater than 1000 milliseconds
Fetch URL based on column (quotes needed):
"http://nominatim.openstreetmap.org/search?format=json&email=[YOUR_EMAIL_HERE].com&app=google-refine&q=' + escape(value, 'url')"
------------------------------------------------------------------------------------
Step Two - Extract lat/lon from newly created JSON blobs
Edit Column > Add Column based on This Column
Parse Json and concatenate latitude, longitude:
with(value.parseJson()[0], pair, pair.lat + ',' + pair.lon)
------------------------------------------------------------------------------------
Sources:
https://github.com/OpenRefine/OpenRefine/wiki/Geocoding
http://wiki.openstreetmap.org/wiki/Nominatim
https://gist.github.com/mjrich/3118660
http://www.youtube.com/watch?v=5tsyz3ibYzk&feature=player_embedded
@ryancatalani
Copy link

The URL to fetch is a little off—I believe it should be "http://nominatim.openstreetmap.org/search?format=json&email=[YOUR_EMAIL_HERE]&app=google-refine&q=" + escape(value, 'url'). Or if you want to include the single quotes around the query value, then "http://nominatim.openstreetmap.org/search?format=json&email=[YOUR_EMAIL_HERE]&app=google-refine&q='" + escape(value, 'url') + "'".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment