Geocoding and reverse geocoding are the process of turning the address or place name into geographic coordinates, vice versa.
More detailed definition: wikipedia
Address --> Latitude,Longitude: Geocoding
Latitude,Longitude --> Address: Reverse geocoding
The implementation is done by various providers, here is a list:
So with these services, next step is to use script to access the service’s API.
Basically in R, two packages are implemented:
ggmap provides Google Maps API:
# invoke the geocode function
The output level can be chosen by invoking the parameter:
output = c("latlon", "latlona", "more", "all").
And the free tier query rate can be check via
geocodeQueryCheck(userType = "free").
For the newly developed package
geocodeHERE, please consult the github page.
I have created a R function that uses Bing Geocoding service. The function import two packages:
httr provides the
cURL interface to do the
RJSONIO is used to parse the returned json content. The function takes the
address string and the authentication
key as parameter input, then returns in data frame.
You can get your key from here.
In python, you have more choices other than create your own function to
GET and parse the API.
Here are some wrapped packages:
- geocoder: wraps all services
- geopy: wraps all services
- pygeocoder: only google
- python-geocoder: only google
The last two packages seem to be abandoned, at least not as powerful as first two packages.
geocoder is more simple and provides more useful returned values. The only problem is that
geocoder seems to be python 2.x only.
geopy is python 2 & 3 ready and implements with object-oriented programming. And you can have more thorough controls.
Here is my sample code to read from
csv file a column with header ‘location’ and return required value.