Skip to content

Why as.ppp.sf attach only the first column as mark?  #2450

@agila5

Description

@agila5

Dear all, I was wondering why the following code

sf/R/spatstat.R

Lines 141 to 154 in 6f247a5

as.ppp.sf = function(X, ...) {
check_spatstat("spatstat.geom", X)
pp = spatstat.geom::as.ppp(st_geometry(X), ...)
if (st_dimension(X[1,]) == 2)
X = X[-1,]
st_geometry(X) = NULL # remove geometry column
if (ncol(X) > 1)
warning("only first attribute column is used for marks")
if (ncol(X) == 0)
pp
else
spatstat.geom::setmarks(pp, X[1])
}

forces the conversion sf -> ppp to keep only the first column of mark. What are the downside of keeping all the columns (if any) of X? AFAICT, the argument value in spatstat.geom::setmarks accepts a vector but also a data.frame object. For example:

library(sf)
library(spatstat)

X <- st_read(system.file("csv/pt.csv", package="sf"))
pp <- spatstat.geom::as.ppp(st_geometry(X)) 
st_geometry(X) = NULL
spatstat.geom::setmarks(pp, X) 
#> Marked planar point pattern: 3 points
#> Mark variables: Id, Int64, Int32, WKT 
#> window: rectangle = [0, 44] x [0, 55] units

Created on 2024-10-03 with reprex v2.0.2

EDIT: Maybe this wasn't always the case, but I cannot find any proper reference in the NEWS file of spatstat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions