R/locs2vect.R
locs2vect.Rd
Convert matrix or data frame with point coordinates to a SpatVector object
locs2vect(locs, crs = 4326, lon.col = NULL, lat.col = NULL)
A matrix or data frame containing point coordinates data.
If a matrix, the first two columns will be assumed to contain longitude
and latitude coordinates, respectively.
If a data frame, the function will try to guess the columns containing the coordinates
based on column names, unless lon.col
and lat.col
are provided.
A number specifying the EPSG code (see https://spatialreference.org). Default is geographic (unprojected) coordinates, datum WGS84 (EPSG = 4326).
Character (optional). Name of the column containing longitude data.
Character (optional). Name of the column containing latitude data.
A terra::SpatVector()
object.
locs <- matrix(runif(20), ncol = 2)
locs2vect(locs)
#> As locs is a matrix, assuming first two columns are longitude and latitude, respectively.
#> class : SpatVector
#> geometry : points
#> dimensions : 10, 0 (geometries, attributes)
#> extent : 0.09602416, 0.9907123, 0.06521611, 0.7793086 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
locs <- data.frame(species = rep("Laurus nobilis", 10), x = runif(10), y = runif(10))
locs2vect(locs)
#> Assuming 'y' is latitude
#> Assuming 'x' is longitude
#> class : SpatVector
#> geometry : points
#> dimensions : 10, 1 (geometries, attributes)
#> extent : 0.191518, 0.9477639, 0.02006522, 0.8570836 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> names : species
#> type : <chr>
#> values : Laurus nobilis
#> Laurus nobilis
#> Laurus nobilis