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

as.psp

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

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.