Geocoding in R!

Folks,

In this blog we will explore the basics of Geocoding using R,  using Google Maps Geocoding API & R!

Geocoding: Process of transforming a description of a location (address, name of a place, or coordinates) to a location on the earth’s surface.

Forward Geocoding: Converting address/name of a place into geographic coordinates.

Reverse Geocoding: Converting geographic coordinates into readable address.

R Package required: 

install.packages(“RCurl ”): It allows us to compose general HTTP requests and provides convenient functions to fetch data.

install.packages(“rjson”): It allows us to converts JSON object into R objects and vice-versa.


Forward Geocoding using R

Google Maps Geocoding API:

11

Where output may be either of JSON/XML & parameters = address or components.

Example for JSON:

https://maps.googleapis.com/maps/api/geocode/json?address=India+Gate,+New+Delhi,+India&components=country:IN

Where address = “India Gate, New Delhi, India”, components = Country “IN” for India.

Component Country: country name or a two letter country code. For more components like locality & postal code etc. details read this link.

R Commands:

url<- “”

jdata<- getURL(url) # Fetching JSON data.

rdata<- fromJSON(jdata) # Convert a JSON object into an R object.

Output:

1

Geographic coordinates present in  rdata results.

2

Extracting geographic coordinates from the rdata.

3.png

PS: These are approx geographic coordinates, as it depends on the address provided in URL.


Reverse Geocoding using R

Google Maps Reverse Geocoding API:

12

Where output may be either of JSON/XML. Parameters:  ,

R Commands:

url<- “”

jdata<- getURL(url) # Fetching JSON data.

rdata<- fromJSON(jdata) # Convert a JSON object into an R object.

For Example taking latitude & longitude 28.632455, 77.217218 – Courtesy: Google Maps

4.png

Output:

7.png

5

For more details please read this google link.


Thanks!

Happy Learning!

Advertisements

3 thoughts on “Geocoding in R!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s