Examples for 'sp::SpatialPoints'


create objects of class SpatialPoints or SpatialPointsDataFrame

Aliases: SpatialPoints SpatialPointsDataFrame

Keywords: manip

### ** Examples

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
Warning in SpatialPointsDataFrame(pts, df): forming a SpatialPointsDataFrame
based on maching IDs, not on record order. Use match.ID = FALSE to match on
record order
  coordinates a
a      (1, 1) 5
b      (2, 2) 4
c      (3, 3) 3
d      (4, 4) 2
e      (5, 5) 1
SpatialPointsDataFrame(pts, df, match.ID = TRUE) # don't warn
  coordinates a
a      (1, 1) 5
b      (2, 2) 4
c      (3, 3) 3
d      (4, 4) 2
e      (5, 5) 1
SpatialPointsDataFrame(pts, df, match.ID = FALSE) # don't warn
  coordinates a
e      (1, 1) 1
d      (2, 2) 2
c      (3, 3) 3
b      (4, 4) 4
a      (5, 5) 5
df$m = letters[5:1]
SpatialPointsDataFrame(pts, df, match.ID = "m") # don't warn
  coordinates a m
a      (1, 1) 5 a
b      (2, 2) 4 b
c      (3, 3) 3 c
d      (4, 4) 2 d
e      (5, 5) 1 e
dimnames(pts)[[1]] = letters[5:1]
SpatialPointsDataFrame(pts, df) # don't warn: ID matching doesn't reorder
  coordinates a m
e      (1, 1) 1 e
d      (2, 2) 2 d
c      (3, 3) 3 c
b      (4, 4) 4 b
a      (5, 5) 5 a

[Package sp version 1.5-0 Index]