[R-sig-Geo] SpatialMultiPoints suggestions

Kent Johnson kent3737 at gmail.com
Sat Dec 5 22:37:30 CET 2015


Hi,

I am starting to use SpatialMultiPointsDataFrame to hold lat/lon/altitude
data and metadata from airplane tracks. A couple of observations:

- The documentation for SpatialMultiPoints {sp} seem to be incorrect. It
say that the 'coords' argument is a "numeric matrix or data.frame with
coordinates (each row is a point)". In fact the argument seems to be a list
of such matrices, as shown in the example code.

- rbind() is not implemented for SpatialMultiPoints*; perhaps it is an
oversight, as the other Spatial* classes have implementations of rbind().
Here is my attempt:

rbind.SpatialMultiPoints <- function(...) {
dots = list(...)
names(dots) <- NULL
stopifnot(identicalCRS(dots))
SpatialMultiPoints(do.call(c, lapply(dots, slot, name="coords")),
CRS(proj4string(dots[[1]])))
}

rbind.SpatialMultiPointsDataFrame <- function(...) {
dots = list(...)
names(dots) <- NULL
sp = do.call(rbind, lapply(dots, function(x) as(x, "SpatialMultiPoints")))
df = do.call(rbind, lapply(dots, function(x) x at data))
SpatialMultiPointsDataFrame(sp, df)
}


HTH,
Kent

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list