# An R function for finding coordinates of NZ localities

June 10, 2012
By

(This article was first published on The Praise of Insects, and kindly contributed to R-bloggers)

Over the course of my PhD, I will be doing a fair amount of georeferencing. This involves obtaining geographic coordinates for localities where weevil specimens have been collected. When I'm the one who has collected them, this is fairly straightforward—Google Maps has made obtaining coordinates a breeze. When it's a museum specimen, however, things get a little tricky. Maps and atlases are extremely useful, but hard to search through. The university has access to MapToaster which contains the topographic maps of New Zealand, and which allows one to search for place names. However, it's only available from university computers, and the search feature requires a degree of mouse work to drive it. LINZ has made the New Zealand Geographic Place Names Database freely available online, which is also fairly fiddly to use in a high throughput situation. However, it is based on a fairly well-structured database, which allowed me to write an R function to search and retrieve information (including coordinates) for place names of interest.

The result is gazNZ(). This function allows a name to be searched for from the R console, making the process of finding coordinates a lot quicker, and means that I only need to use my keyboard when searching for things—a much more satisfying state of affairs.

> gazNZ("Cook Strait")
\$Cook Strait
[1] -41.2493 174.4736

To leave a comment for the author, please follow the link and comment on his blog: The Praise of Insects.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...