Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as.ppp

Coercion between sp objects and spatstat ppp objects


Description

Functions to convert between spatstats planar point pattern (ppp) format and sps SpatialPoints and SpatialPointsDataFrame as well as one-way conversion from SpatialGridDataFrame to ppp. S4-style as() coercion can be used as well.

Usage

as.ppp.SpatialPoints(X)
as.ppp.SpatialPointsDataFrame(X)
as.SpatialPoints.ppp(from)
as.SpatialPointsDataFrame.ppp(from)
as.SpatialGridDataFrame.ppp(from)

Arguments

from, X

object to coerce from

Details

The main conversion is between sps SpatialPoints/SpatialPointsDataFrame and spatstats ppp. Conversion between SpatialGridDataFrame and ppp should rarely be used; using as.owin.SpatialGridDataFrame is more transparent.

Methods

coerce

signature(from = "SpatialPoints", to = "ppp")

coerce

signature(from = "SpatialPointsDataFrame", to = "ppp")

coerce

signature(from = "ppp", to = "SpatialGridDataFrame")

coerce

signature(from = "ppp", to = "SpatialPointsDataFrame")

coerce

signature(from = "ppp", to = "SpatialPoints")

Warning

In spatstat all spatial objects are assumed to be planar. This means that spatstat is not designed to work directly with geographic (longitude and latitude) coordinates. If a sp object is declared to have geographic (unprojected) coordinates maptools refuses to convert directly to spatstat format. Rather, these should be projected first using e.g. spTransform. If you know what you are doing, and really want to force coercion, you can overwrite the proj4string of the sp object with NA, proj4string(x) <- CRS(NA), which will fool the system to think that the data is in local planar coordinates. This is probably not a good idea!

Note

The ppp format requires an observation window which is the sampling region. The sp formats contain no such information and by default the bounding box of the points is simply used. This is almost never the correct thing to do! Rather, information about the sampling region should be converted into spatstats owin format and assigned as the observation window. Usually conversion from ppp to sp format simply discards the owin. However, as.SpatialGridDataFrame.ppp actually first discards the points(!), second checks that the corresponding owin is in a grid format (matrix of TRUE/FALSE for inside/outside sampling region), and finally converts the TRUE/FALSE grid to a SpatialGridDataFrame.

Author(s)

Edzer Pebesma edzer.pebesma@uni-muenster.de, Roger Bivand

Examples

run <- FALSE
if (require("spatstat.geom", quietly=TRUE)) run <- TRUE
if (run) {
## Convert SpatialPointsDataFrame into a marked ppp
data(meuse)
coordinates(meuse) = ~x+y
meuse_ppp <- as(meuse, "ppp")
meuse_ppp # Window is the bounding rectangle
}
if (run) {
plot(meuse_ppp, which.marks = "zinc")
}
if (run) {
## Convert SpatialPoints into an unmarked ppp
meuse2 <- as(meuse, "SpatialPoints")
as(meuse2, "ppp")
}
if (run) {
## Get sampling region in grid format and assign it as observation window
data(meuse.grid)
gridded(meuse.grid) <- ~x+y
mg_owin <- as(meuse.grid, "owin")
Window(meuse_ppp) <- mg_owin
meuse_ppp # Window is now a binary image mask (TRUE/FALSE grid)
}
if (run) {
plot(meuse_ppp, which.marks = "zinc")
}
if (run) {
## Convert marked ppp back to SpatialPointsDataFrame
rev_ppp_SPDF <- as.SpatialPointsDataFrame.ppp(meuse_ppp)
summary(rev_ppp_SPDF)
}
if (run) {
## Convert marked ppp back to SpatialPoints (discarding marks)
rev_ppp_SP <- as.SpatialPoints.ppp(meuse_ppp)
summary(rev_ppp_SP)
}
if (run) {
## Convert marked ppp back to SpatialGridDataFrame (extracting the window grid)
rev_ppp_SGDF <- as.SpatialGridDataFrame.ppp(meuse_ppp)
summary(rev_ppp_SGDF)
}

maptools

Tools for Handling Spatial Objects

v1.1-1
GPL (>= 2)
Authors
Roger Bivand [cre, aut] (<https://orcid.org/0000-0003-2392-6140>), Nicholas Lewin-Koh [aut], Edzer Pebesma [ctb], Eric Archer [ctb], Adrian Baddeley [ctb], Nick Bearman [ctb], Hans-Jörg Bibiko [ctb], Steven Brey [ctb], Jonathan Callahan [ctb], German Carrillo [ctb], Stéphane Dray [ctb], David Forrest [ctb], Michael Friendly [ctb], Patrick Giraudoux [ctb], Duncan Golicher [ctb], Virgilio Gómez Rubio [ctb], Patrick Hausmann [ctb], Karl Ove Hufthammer [ctb], Thomas Jagger [ctb], Kent Johnson [ctb], Matthew Lewis [ctb] (<https://orcid.org/0000-0003-2244-4078>), Sebastian Luque [ctb], Don MacQueen [ctb], Andrew Niccolai [ctb], Edzer Pebesma [ctb], Oscar Perpiñán Lamigueiro [ctb], Ethan Plunkett [ctb], Ege Rubak [ctb] (<https://orcid.org/0000-0002-6675-533X>), Tom Short [ctb], Greg Snow [ctb], Ben Stabler [ctb], Murray Stokely [ctb], Rolf Turner [ctb]
Initial release
2021-03-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.