Skip to contents

Constructs a query to the NaturalEarth server (see reference 1) to download coastline data (or lake data, river data, etc) in any of three resolutions.

Usage

dod.coastline(
  resolution,
  item = "coastline",
  destdir = ".",
  destfile,
  server = "naturalearth",
  debug = 0
)

Arguments

resolution

A character value specifying the desired resolution. The permitted choices are "10m" (for 1:10M resolution, the most detailed), "50m" (for 1:50M resolution) and "110m" (for 1:110M resolution). If resolution is not supplied, "50m" will be used.

item

A character value indicating the quantity to be downloaded. This is normally one of "coastline", "land", "ocean", "rivers_lakes_centerlines", or "lakes", but the NaturalEarth server has other types, and advanced users can discover their names by inspecting the URLs of links on the NaturalEarth site, and use them for item. If item is not supplied, it defaults to "coastline".

destdir

a character value indicating the directory in which to store downloaded files.

destfile

optional name of destination file. If not provided, this function creates a reasonable name.

server

A character value specifying the server that is to supply the data. At the moment, the only permitted value is "naturalearth", which is the default if server is not supplied.

debug

an integer value indicating the level of debugging. If this exceeds 0, then some debugging messages will be printed. This value is passed down to related functions, but with 1 subtracted for each pass.

Value

A character value indicating the (ziip) filename of the result, or an empty string, if there is a problem.

References

  1. The NaturalEarth website is at https://www.naturalearthdata.com but the files are available at e.g. https://naturalearth.s3.amazonaws.com/50m_physical/ne_50m_coastline.zip

See also

Other functions that download files: dod.amsr(), dod.buoy(), dod.ctd(), dod.ctd.bats(), dod.ctd.bbmp(), dod.ctd.gtspp(), dod.ctd.itp(), dod.met(), dod.tideGauge(), dod.topo()

Author

Dan Kelley

Examples


# Download, unzip, read file, and then erase (as per CRAN policies)
if (interactive()) { # this is a problem for pkgdown::build_site()
    library(dod)
    # NOTE: data file is removed at end, to pass CRAN checks
    destdir <- tempdir()
    zip <- dod.coastline(destdir = destdir, debug = 3)
    unzip(zip, exdir = destdir)
    list.files(destdir) # note the .shp file
    shpfile <- list.files(destdir, ".shp$", full.names = TRUE)
    if (requireNamespace("oce", quietly = TRUE)) {
        library(oce)
        cl <- read.coastline(shpfile, type = "shapefile")
        plot(cl)
    }
    unlink(destdir, recursive = TRUE, force = TRUE)
}