sp (version 1.1-0)

SpatialPoints: create objects of class SpatialPoints or SpatialPointsDataFrame

Description

create objects of class SpatialPoints-class or SpatialPointsDataFrame-class from coordinates, and from coordinates and data.frames

Usage

SpatialPoints(coords, proj4string=CRS(as.character(NA)), bbox = NULL)
SpatialPointsDataFrame(coords, data, coords.nrs = numeric(0), 
      proj4string = CRS(as.character(NA)), match.ID, bbox = NULL)

Arguments

coords
numeric matrix or data.frame with coordinates (each row is a point); in case of SpatialPointsDataFrame an object of class SpatialPoints-class is also allowed
proj4string
projection string of class CRS-class
bbox
bounding box matrix, usually NULL and constructed from the data, but may be passed through for coercion purposes if clearly needed
data
object of class data.frame; the number of rows in data should equal the number of points in the coords object
coords.nrs
numeric; if present, records the column positions where in data the coordinates were taken from (used by coordinates<-)
match.ID
logical or character; if missing, and coords and data both have row names, and their order does not correspond, matching is done by these row names and a warning is issued; this warning can be suppressed by setting match.ID

Value

  • SpatialPoints returns an object of class SpatialPoints; SpatialPointsDataFrame returns an object of class SpatialPointsDataFrame;

See Also

coordinates, SpatialPoints-class, SpatialPointsDataFrame-class

Examples

Run this code
set.seed(1331)
pts = cbind(1:5, 1:5)
dimnames(pts)[[1]] = letters[1:5]
df = data.frame(a = 1:5)
row.names(df) = letters[5:1]

library(sp)
options(warn=1) # show warnings where they occur
SpatialPointsDataFrame(pts, df) # warn
SpatialPointsDataFrame(pts, df, match.ID = TRUE) # don't warn
SpatialPointsDataFrame(pts, df, match.ID = FALSE) # don't warn
df$m = letters[5:1]
SpatialPointsDataFrame(pts, df, match.ID = "m") # don't warn

dimnames(pts)[[1]] = letters[5:1]
SpatialPointsDataFrame(pts, df) # don't warn: ID matching doesn't reorder

Run the code above in your browser using DataCamp Workspace