coordinates() of SpatialLines DF
On Wed, 27 Jan 2010, Agustin Lobo wrote:
HI, I'm confused by the following:
xter <-
readOGR(dsn="/media/Transcend/PROVI/MARICEL2/x_terRiverBasin",layer="x_ter")
class(xter)
[1] "SpatialLinesDataFrame" attr(,"package") [1] "sp"
delme <- coordinates(xter) class(delme)
[1] "list" The manual page of coordinates states: Value usually an object of class SpatialPointsDataFrame; if the coordinates set cover the full set of variables in object, an object of class SpatialPoints is returned why don't I get a SpatialPointsDataFrame?
Because "usually" you do get a SpatialPointsDataFrame from coordinates<-
(set) on a data.frame. coordinates (get) is a matrix for SpatialPoints*
and the classes that inherit (SpatialPixels*, SpatialGrids* - cell
centres), and for SpatialPolygons* - label points.
See for the extraction method:
getMethod("coordinates", "Line")
getMethod("coordinates", "Lines")
getMethod("coordinates", "SpatialLines")
to see what is happening in this case - you get a list of lists of
coordinate matrices. Using the Norwegian coastline from maptools:
library(maptools)
library(maps)
nor_coast_lines <- map("world", interior=FALSE, plot=FALSE, xlim=c(4,32),
ylim=c(58,72))
nor_coast_lines <- pruneMap(nor_coast_lines, xlim=c(4,32), ylim=c(58,72))
nor_coast_lines_sp <- map2SpatialLines(nor_coast_lines,
proj4string=CRS("+proj=longlat +datum=wgs84"))
plot(nor_coast_lines_sp, axes=TRUE)
crdl0 <- coordinates(nor_coast_lines_sp)
crdl1 <- sapply(crdl0, function(x) do.call("rbind", x))
crdl2 <- do.call("rbind", crdl1)
lines(crdl2[chull(crdl2),], type="l", col="red")
using do.call() of "rbind" to stack the coordinate matrices.
Roger
Anyway, is there any way to get object "delme" to become a 2 col. data frame or matrix? What I want is the cloud of points to calculate the convex hull and get an estimate of the polygon of the basin. Thanks Agus [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no