as.ppp {maptools}R Documentation

coercion between sp objects and spatstat objects

Description

S4-style as() coercion works from objects of S4 sp classes to spatstat S3 classes, but not the reverse. Coercion to sp classes uses direct function calls.

Usage

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

Arguments

from spatstat object of class ppp or im

Methods

coerce
signature(from = "SpatialPoints", to = "ppp")
coerce
signature(from = "SpatialPointsDataFrame", to = "ppp")
coerce
signature(from = "SpatialGridDataFrame", to = "ppp")
coerce
signature(from = "SpatialPolygons", to = "owin")
coerce
signature(from = "SpatialPixelsDataFrame", to = "owin")
coerce
signature(from = "SpatialGridDataFrame", to = "owin")
coerce
signature(from = "SpatialGridDataFrame", to = "im")
coerce
signature(from = "im", to = "SpatialGridDataFrame")
coerce
signature(from = "ppp", to = "SpatialGridDataFrame")
coerce
signature(from = "ppp", to = "SpatialPointsDataFrame")
coerce
signature(from = "ppp", to = "SpatialPoints")

Note

When coercing a SpatialPolygons object to an owin object, full topology checking is enabled by default. To avoid checking, set .spatstat_check to FALSE in the global environment. This work-around may not be required from spatstat version 2, and is used at the risk of garbled topology breaking other functions in spatstat.

Author(s)

Edzer Pebesma e.pebesma@geo.uu.nl, Roger Bivand

Examples

library(spatstat)
data(meuse)
coordinates(meuse) = ~x+y
zn1 <- as(meuse["zinc"], "ppp")
zn1
plot(zn1)
as(as(meuse, "SpatialPoints"), "ppp")
data(meuse.grid)
gridded(meuse.grid) = ~x+y
mg_owin <- as(meuse.grid, "owin")
zn1a <- ppp(x=zn1$x, y=zn1$y, marks=zn1$marks, window=mg_owin)
zn1a
plot(zn1a)
rev_ppp_SP <- as.SpatialPoints.ppp(zn1a)
summary(rev_ppp_SP)
rev_ppp_SPDF <- as.SpatialPointsDataFrame.ppp(zn1a)
summary(rev_ppp_SPDF)
rev_ppp_SGDF <- as.SpatialGridDataFrame.ppp(zn1a)
summary(rev_ppp_SGDF)
# as.owin(meuse.grid)
# --- will only work if as.owin is method...
mg_owin <- as(as(meuse.grid["ffreq"], "SpatialPixelsDataFrame"), "owin")
mg_owin
ho_sp <- SpatialPolygons(list(Polygons(list(Polygon(cbind(c(0,1,1,0,0),
  c(0,0,1,1,0))), Polygon(cbind(c(0.6,0.4,0.4,0.6,0.6), 
  c(0.2,0.2,0.4,0.4,0.2)), hole=TRUE)), ID="ho")))
plot(ho_sp, col="red", pbg="pink")
ho <- as(ho_sp, "owin")
plot(ho)
pp <- runifpoint(500, win=ho)
plot(pp)
ho_orig <- owin(poly=list(list(x=c(0,1,1,0), y=c(0,0,1,1)),
  list(x=c(0.6,0.4,0.4,0.6), y=c(0.2,0.2,0.4,0.4))))
identical(ho, ho_orig)
mg_dist <- meuse.grid["dist"]
fullgrid(mg_dist) <- TRUE
image(mg_dist, axes=TRUE)
mg_im <- as(mg_dist, "im")
plot(mg_im)
mg2 <- as.SpatialGridDataFrame.im(mg_im)
image(mg2, axes=TRUE)

[Package maptools version 0.7-12 Index]