Skip to content
R tools for easy navigation and reading of locally stored data files from [Natural Earth](http://www.naturalearthdata.com/)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R
man
DESCRIPTION
NAMESPACE
README.md

README.md

nearth

R tools for easy navigation and reading of locally stored data files from Natural Earth

Requirements

For the vector dataset it is pretty easy to download the entire suite of data. Rasters, on the other hand, are quite big and I decided to download just a few.

Suggested R packages

Installation

It is easy to install with devtools

library(devtools)
install_github("btupper/nearth")

Configuration within R

The nearth package will find files for you by name. To simplify this process, you should do the following either upon startup of R or before you use nearth. Set the path values to what makes sense for your setup.

options(NEARTH_VECTOR_PATH = "/Users/Shared/data/natural_earth/vector",
        NEARTH_RASTER_PATH = "/Users/Shared/data/natural_earth/raster")

I find it easiest to add this to my ~/.Rprofile configuration file so these are defined when R starts. Here's more information on ~/.Rprofile from Quick-R.

Usage

library(nearth)

# find a vector file by name
vfile <- find_nearth_vectors(name = 'ne_50m_coastline')

#find a raster file by name
rfile <- find_nearth_rasters(name = 'NE1_50M_SR_W')

If the rgdal and raster packages are installed, you can read the Natural Earth products using read_nearth. NOTE: you can provide just the name of the shapefile as shown below rather than the full filepath specification.

library(nearth)
library(rgdal)
library(raster)

v <- read_nearth(name = 'ne_50m_coastline', what = 'vector')
# note that the function returns a list of Spatial* objects
sp::spplot(v[[1]])

# read and crop the vectors to a bounding box [left, right, bottom, top]
# cropping can make for faster graphics in some cases
v <- read_nearth(name = 'ne_50m_coastline', what = 'vector', bb = c(-73,-62,39,45))

# read and plot a raster
# note that since you can provide one or more names of datasets
#   the function returns a list of rasters
r <- read_nearth(name = 'NE1_50M_SR_W', what = 'raster', form = 'brick')
raster::plotRGB(r[[1]])
You can’t perform that action at this time.