Learn R Programming

gbm.auto (version 1.4.0)

gbm.basemap: Creates Basemaps for Gbm.auto mapping from your data range

Description

Downloads unzips crops & saves NOAAs global coastline shapefiles to user-set box. Use for 'shape' in gbm.map. If downloading in RStudio uncheck "Use secure download method for HTTP" in Tools > Global Options > Packages. Simon Dedman, 2015/6 simondedman@gmail.com GitHub.com/SimonDedman/gbm.auto

Usage

gbm.basemap(
  bounds = NULL,
  grids = NULL,
  gridslat = NULL,
  gridslon = NULL,
  getzip = TRUE,
  zipvers = "2.3.7",
  savedir = tempdir(),
  savename = "Crop_Map",
  res = c("CALC", 1, 2, 3, 4, 5),
  extrabounds = FALSE
)

Arguments

bounds

Region to crop to: c(xmin,xmax,ymin,ymax).

grids

If bounds unspecified, name your grids database here.

gridslat

If bounds unspecified, specify which column in grids is latitude.

gridslon

If bounds unspecified, specify which column in grids is longitude.

getzip

Download & unpack GSHHS data to WD? "TRUE" else absolute/relative reference to GSHHS_shp folder, including that folder.

zipvers

GSHHS version, in case it updates. Please email developer (SD) if this is incorrect.

savedir

Save outputs to a temporary directory (default) else change to current directory e.g. "/home/me/folder". Do not use getwd() here.

savename

Shapefile save-name, no shp extension, default is "Crop_Map"

res

Resolution, 1:5 (low:high) OR c,l,i,h,f (coarse, low, intermediate, high, full) or "CALC" to calculate based on bounds. Choose one.

extrabounds

Grow bounds 16pct each direction to expand rectangular datasets basemaps over the entire square area created by basemap in mapplots.

Value

basemap coastline file for gbm.map in gbm.auto. "cropshp" SpatialPolygonsDataFramein in local environment & user-named files in "CroppedMap" folder. Load later with maptools function: MyMap <- readShapePoly("./CroppedMap/Crop_Map")

Details

errors and their origins: 1. Error in setwd(getzip) : cannot change working directory If you've specified the location of the local GSHHS_shp folder, ensure you're in the correct directory relative to it. This error means it looked for the folder and couldn't find it.

2. Error in writeSpatialShape(cropshp, savename) x is a NULL object, not a compatible Spatial*DataFrame. Ensure that your lats and longs are the the right way around

3. If rgdal install fails in Linux try: sudo apt-get install libgdal-dev && sudo apt-get install libproj-dev"

4. Error in as.environment(pos):no item called "package:shapefiles" on the search list: strange error occurring despite shapefiles being coded like all other packages. Correct output produced regardless.

Examples

Run this code
# NOT RUN {
# Not run: downloads and saves external data.
data(samples)
mybounds <- c(range(samples[,3]),range(samples[,2]))
gbm.basemap(bounds = mybounds, getzip = "./GSHHS_shp/",
savename = "My_Crop_Map", res = "f")
# In this example GSHHS folder already downloaded to the working directory
# hence I pointed getzip at that rather than having it download the zip again
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab