Skip to content
Prev 22467 / 29559 Next

inconsistent as.data.frame(SpatialPointsDF)

Hi

I can reproduce this using Edzer's example. See below for output from R. Also notice the naming of the coordinate columns to "x" and "y" in the S4 method of the raster package's function as.data.frame! Isn't that quite unusual? I have maintainer on CC.
Longitude Latitude z
1         1        2 3
2         2        1 4
[1] ".GlobalEnv"        "package:raster"    "package:sp"       
 [4] "ESSR"              "package:stats"     "package:graphics" 
 [7] "package:grDevices" "package:utils"     "package:datasets" 
[10] "package:methods"   "Autoloads"         "package:base"
x y z
1 1 2 3
2 2 1 4
Function: as.data.frame (package base)
x="ANY"
x="data.frame"
    (inherited from: x="ANY")
x="Raster"
x="SpatialLines"
x="SpatialPoints"
x="SpatialPointsDataFrame"
    (inherited from: x="SpatialPoints")
x="SpatialPolygons"
Method Definition:

function (x, row.names = NULL, optional = FALSE, ...) 
{
    .local <- function (x, row.names = NULL, optional = FALSE, 
        xy = TRUE, ...) 
    {
        if (!xy) {
            if (.hasSlot(x, "data")) {
                return(x at data)
            }
            else {
                return(NULL)
            }
        }
        nobj <- length(x)
        d <- coordinates(x)
        if (.hasSlot(x, "data")) {
            d <- cbind(d, x at data)
        }
        colnames(d)[1:2] <- c("x", "y")
        rownames(d) <- NULL
        as.data.frame(d, row.names = row.names, optional = optional, 
            ...)
    }
    .local(x, row.names, optional, ...)
}
<bytecode: 0x000000000d037260>
<environment: namespace:raster>

Signatures:
        x                       
target  "SpatialPointsDataFrame"
defined "SpatialPoints"
Yours sincerely / Med venlig hilsen


Frede Aakmann T?gersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.