spdf: Convert a data.frame to SpatialPointsDataFrame

Description Usage Arguments Details Author(s)

View source: R/functions.R

Description

Convert a data.frame to SpatialPointsDataFrame by automatically identifying the columns that contain coordinate information (unless specified in a parameter), and assuming a lat-lon pseudoprojection unless otherwise indicated.

Usage

1
spdf(data, crs = NULL, llcols = NULL, na.action = na.omit)

Arguments

data

An object coercible into a data.frame

crs

The proj4string argument for SpatialPointsDataFrame function. Defaults to WGS-84 lat-lon

llcols

Names of the longitude and latitude (x and y coordinate) columns, in that order. If missing, looks first for column names starting with latitude and longitude, then for column names starting with lat and lon, then with x and y (case insensitive). If any of the lookups result in one hit or more than two hits, or all lookups result in no hits, the function will fail.

na.action

What to do with missing or invalid values in coordinate columns

Details

Default behavior built into the function means that nine times out of ten, you can create your spatial object with a simple spdf(obj) call, instead of the standard sp:SpatialPointsDataFrame function call which requires three parameters. The function is also easy to use in magrittr pipe workflows. However, one time out of ten things could go horribly wrong if you're not careful!

Author(s)

Lauri Myllyvirta lauri.myllyvirta@greenpeace.org


laurimyllyvirta/lauR documentation built on April 28, 2021, 6:26 p.m.