A coord_matrix is a matrix with two columns named "lon" and "lat" to represent spatial point data. They are used as an intermediary when converting some R objects to sf::sf() objects.

as_coord_matrix() can smartly convert a range of R objects to coord_matrix. If you are a package developer and want to add support for smartmap to your package without having to depend on the heavy sf package, it is enough to provide an as_coord_matrix() method.

as_coord_matrix(x, ...)

# S3 method for default
as_coord_matrix(x, ...)

# S3 method for numeric
as_coord_matrix(x, ...)

# S3 method for sf
as_coord_matrix(x, ...)

# S3 method for sfc_POINT
as_coord_matrix(x, ...)

# S3 method for matrix
as_coord_matrix(x, ..., loncol = guess_loncol(x), latcol = guess_latcol(x))

# S3 method for data.frame
as_coord_matrix(x, ..., loncol = guess_loncol(x), latcol = guess_latcol(x))

Arguments

x

any of the following:

  • a matrix: Either a matrix with named longitude and latitude columns or an unnamed two column matrix containing longitude and latitude (in that order)

  • a data.frame with named longitude and latitude columns

  • an sf::sfc_POINT object

  • a named or unnamed numeric vector of length 2 containing a single longitude-latitude coordinate pair

  • a character scalar path or URL to a shapefile or zipped shapefile

...

passed on to methods

loncol, latcol

character scalars. Names of the columns of x containing longitude and latitude. The default trying guessing the columns.

Value

as_coord_matrix() returns a coord_matrix object: A numeric matrix with the columns "lon"and "lat" (in that order)

See also