Thursday, December 11, 2014

R GeoNames API

R has a package (geonames) for connecting to the GeoNames API.  If you are not familiar with GeoNames be sure to check out this previous post with a few examples.  The documentation for the package can be found at: http://cran.r-project.org/web/packages/geonames/geonames.pdf

Step #1: Getting a Free Account
You will need to visit  http://www.geonames.org/login to create a free account.  Note: GeoNames has free and premium services.

Step #2: Activating the Account
After receiving a confirmation e-mail, log-in, and click the activate link.  Look midway or towards the bottom of the page.  It is easy to miss!  If you do not activate the account, you will receive an error message in R such as '401 Unauthorized'.

Step #3: Installing and Loading the Package in R
The simplest way to a install a package in R is to go the toolbar at the top, select "Install Packages", choose a download source or simply select "OK" and then scroll down until you find "geonames" in all lowercase letters.

  • After the package installs, you will also have to Load Package from the same toolbar.  
  • Loading the package from the toolbar will have to be done each session--unless you write a short bit of code to do the same automatically.
  • Also make sure you have admin privileges on the computer you are working on.


Step #4: Connecting to the API
In R, you will have two write two lines setting "options" to access the API.  Simply replace "your username" in red with your username!  You will also have to set the host--which is currently api.geonames.org.  Please note in some older documentation and websites this is listed incorrectly as an older address.  It is also possible, although not likely, it could change in the future but would be listed here.

options(geonamesUsername="your username")
options(geonamesHost="api.geonames.org")

Step #5: Test Your Connection
In R, simply type:

source(system.file("tests","testing.R",package="geonames"),echo=TRUE)

If everything is setup correctly, R will pause for a few seconds and return geographic data like in the screenshot below.

Running the code above, you can test your connection.

Step #6: GeoNames Structure
Remember geographic data can have different hierarchies (See Place Hierarchy Webservices) and be accessed in different ways. Be sure to read through the GeoNames and R package documentation to be certain you are getting your desired result.  There are a number of user-defined functions in the GeoNames package.

Examples of user-defined functions:

  • GNcities () - returns cities within a bounding box
  • GNearthqukes () - returns recent earthquakes
  • ...and many more!

Step #7: Getting Geographic Information from Wikipedia, Saving...
For example, one function in the package allows you search Wikipedia articles and retrieve geographic information (i.e. lat, long, elevation).  For example the following code looks for up to 10 articles with "oriole" and stores them in a R dataframe named results:

results<-GNwikipediaSearch("oriole", maxRows = 10)

Click the screenshot to open in a larger window
Example of results, with rank and geographic information, lat, long, and elevation.
You can also type "summarize(results)"--without the quotes -- remember 'results' is the name of the data set to view all of the variables.  The data can also be exported from R.  Keep in mind you can use R to perform exact or fuzzy merging with a data set of place names you have.

Tuesday, December 2, 2014

Review of the Spatial Computing Class on Coursera

From GPS and Google Maps to Spatial Computing was the first geospatial Coursera course that I took and my second Coursera class. Below, I describe the course, what you'll learn, and key takeaways.  Overall, the course is a unique offering that you should check out!

Overview

The eight-week course is taught by Shashi Shekar and Brent Hecht from the University of Minnesota's Department of Computer Science and Engineering.  The goal of the course is to:
"introduc[e] concepts, algorithms, programming, theory and design of spatial computing technologies such as global positioning systems (GPS), Google Maps, location-based services and geographic information systems."
The class has a workload of 4-10 hours per week depending on which of the three tracks you decide to complete (scroll to the bottom of this post to learn more about the different tracks). The majority of the weeks are close to the four hour end. Week 3's workload was heavy.  Be sure to set aside enough time to watch all of the video lectures each week.

Topics Covered

You will learn why SQL requires extensions for spatial queries as well as how to understand the results from basic spatial queries.  How spatial data are stored, accessed, and algorithms used to solve basic spatial problems (i.e. shortest-path, routing) will be discussed.

You'll also learn about volunteered geographic information, different types of positioning, and even how position can be tracked underground. There are interesting lectures about implicit and explicit spatialization--being able to visualize and analyze spatial information in different ways than you might normally think about. Lastly, you will briefly cover cartography (mainly for those new to GIS and/or computer science focused).

Course Schedule

Week 1: Introduction to Spatial Computing and Overview of Course
Week 2: Spatial Query Languages
Week 3: Spatial Networks (e.g. road networks)
Week 4: Spatial Data Mining
Week 5: Volunteered Geographic Information
Week 6: Positioning
Week 7: Cartography and Geographic Human-Computer Interaction
Week 8: Future Directions in Spatial Computing 

Platforms used: WikiBrain API and briefly TileMill


You will learn about WikiBrain - accessing data from Wikipedia and Atlasify (soon to be released).

Miscellaneous

In addition to lectures/videos and slides, you will see taped/videoconference interviews with leading geospatial professionals. In the first few weeks, I felt this worked well but got a little old as the course went on. Hopefully, future sessions will shorten the interview segments--which can be quite lengthy--and occasionally feel burdensome on top of the other coursework.  You will also have a few required readings that are directly related to the coursework and include interesting real world applications.

Tracks

  • Curiosity:  come as you want! no requirements
  • Concept:  Short quizzes and a Statement of Accomplishment
  • Technical: Harder quizzes and assignments for a Distinguished Statement of Accomplishment
    • For the Technical Track, you will need to complete quizzes for both the Concepts and Technical Track. Having programming experience is recommended for the Technical Track's programming homework.

Signature Track available: Yes.  To learn more about Coursera's signature track visit: https://www.coursera.org/signature/guidebook

You will want to sign-up now for e-mail reminders about future sessions, since Coursera offerings are typically spaced several months apart.  For other geospatial classes on Coursera, visit my earlier post: http://opensourcegisblog.blogspot.com/2014/08/free-online-mapping-classes-from-psu.html.  I will be updating this list in the months to come.  (Please note, like other Coursera classes, it will take several weeks for your Statement of Accomplishment to be posted.)