Debian Codegraph @

man/SpatialPoints.Rd

raw
1 \name{SpatialPoints}
2 \alias{SpatialPoints}
3 \alias{SpatialPointsDataFrame}
4 \title{ create objects of class SpatialPoints or SpatialPointsDataFrame}
5 \description{ create objects of class \link{SpatialPoints-class} or
6 \link{SpatialPointsDataFrame-class} from
7 coordinates, and from coordinates and \code{data.frame}s}
8 \usage{
9 SpatialPoints(coords, proj4string=CRS(as.character(NA)), bbox = NULL)
10 SpatialPointsDataFrame(coords, data, coords.nrs = numeric(0),
11 proj4string = CRS(as.character(NA)), match.ID, bbox = NULL)
12 }
13 \arguments{
14 \item{coords}{numeric matrix or data.frame with coordinates
15 (each row is a point); in case of SpatialPointsDataFrame an object
16 of class \link{SpatialPoints-class} is also allowed}
17 \item{proj4string}{ projection string of class \link{CRS-class}}
18 \item{bbox}{bounding box matrix, usually NULL and constructed from the data, but may be passed through for coercion purposes if clearly needed}
19 \item{data}{ object of class \code{data.frame}; the number of rows in \code{data}
20 should equal the number of points in the \code{coords} object}
21 \item{coords.nrs}{numeric; if present, records the column positions where
22 in \code{data} the coordinates were taken from (used by \link{coordinates<-})}
23 \item{match.ID}{ logical or character; if missing, and \code{coords} and \code{data} both have
24 row names, and their order does not correspond, matching is done by these
25 row names and a warning is issued; this warning can be suppressed by setting
26 \code{match.ID} to TRUE.
27 If TRUE AND coords has non-automatic
28 rownames (i.e., coerced to a matrix by \code{as.matrix},
29 \code{dimnames(coords)[[1]]} is not \code{NULL}), AND \code{data} has
30 row.names (i.e. is a data.frame), then the \code{SpatialPointsDataFrame}
31 object is formed by matching the row names of both components, leaving
32 the order of the coordinates in tact. Checks are done to see whether
33 both row names are sufficiently unique, and all data are matched.
34 If FALSE, coordinates and data are simply "glued" together, ignoring row names. If
35 character: indicates the column in \code{data} with coordinates IDs
36 to use for matching records. See examples below. }
37 }
38 \value{
39 \code{SpatialPoints} returns an object of class \code{SpatialPoints};
40 \code{SpatialPointsDataFrame} returns an object of class \code{SpatialPointsDataFrame};
41 }
42 \seealso{ \link{coordinates}, \link{SpatialPoints-class},
43 \link{SpatialPointsDataFrame-class} }
44 \examples{
45 set.seed(1331)
46 pts = cbind(1:5, 1:5)
47 dimnames(pts)[[1]] = letters[1:5]
48 df = data.frame(a = 1:5)
49 row.names(df) = letters[5:1]
50
51 library(sp)
52 options(warn=1) # show warnings where they occur
53 SpatialPointsDataFrame(pts, df) # warn
54 SpatialPointsDataFrame(pts, df, match.ID = TRUE) # don't warn
55 SpatialPointsDataFrame(pts, df, match.ID = FALSE) # don't warn
56 df$m = letters[5:1]
57 SpatialPointsDataFrame(pts, df, match.ID = "m") # don't warn
58
59 dimnames(pts)[[1]] = letters[5:1]
60 SpatialPointsDataFrame(pts, df) # don't warn: ID matching doesn't reorder
61 }
62 \keyword{manip}