as.psp: Coercion between sp objects and spatstat psp objects

as.pspR Documentation

Coercion between sp objects and spatstat psp objects

Description

Functions to convert between spatstats planar segment pattern (psp) format and various sp line formats. S4-style as() coercion can be used as well.

Usage

as.psp.Line(from, ..., window=NULL, marks=NULL, fatal)
as.psp.Lines(from, ..., window=NULL, marks=NULL, fatal)
as.psp.SpatialLines(from, ..., window=NULL, marks=NULL, characterMarks
                 = FALSE, fatal)
as.psp.SpatialLinesDataFrame(from, ..., window=NULL, marks=NULL, fatal)
as.SpatialLines.psp(from)

Arguments

from

object to coerce from

...

ignored

window

window of class owin as defined in the spatstat package

marks

marks as defined in the spatstat package

characterMarks

default FALSE, if TRUE, do not convert NULL marks to factor from character

fatal

formal coercion argument; ignored

Methods

coerce

signature(from = "Line", to = "psp")

coerce

signature(from = "Lines", to = "psp")

coerce

signature(from = "SpatialLines", to = "psp")

coerce

signature(from = "SpatialLinesDataFrame", to = "psp")

coerce

signature(from = "psp", to = "SpatialLines")

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!

Author(s)

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

Examples

run <- FALSE
if (require("spatstat.geom", quietly=TRUE)) run <- TRUE
if (run) {
data(meuse.riv)
mr <- Line(meuse.riv)
mr_psp <- as(mr, "psp")
mr_psp
}
if (run) {
plot(mr_psp)
}
if (run) {
xx_back <- as(mr_psp, "SpatialLines")
plot(xx_back)
}
if (run) {
xx <- readShapeLines(system.file("shapes/fylk-val.shp", package="maptools")[1],
 proj4string=CRS("+proj=utm +zone=33 +ellps=WGS84"))
xx_psp <- as(xx["LENGTH"], "psp")
xx_psp
}
if (run) {
plot(xx_psp)
}
if (run) {
xx_back <- as(xx_psp, "SpatialLines")
plot(xx_back)
}
if (run) {
xx <- readShapeLines(system.file("shapes/fylk-val-ll.shp", package="maptools")[1], 
 proj4string=CRS("+proj=longlat +ellps=WGS84"))
try(xx_psp <- as(xx["LENGTH"], "psp"))
}

maptools documentation built on July 26, 2023, 5:38 p.m.