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

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)

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")

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

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

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
}
#> planar line segment pattern: 175 line segments
#> window: rectangle = [178304, 182331.5] x [325698.5, 337684.8] units
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
}
#> Warning: shapelib support is provided by GDAL through the sf and terra packages among others
#> marked planar line segment pattern: 1094 line segments
#> marks are numeric, of type ‘double’
#> window: rectangle = [-4867.8, 1084721.9] x [6456207, 7841997] units
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"))
}
#> Warning: shapelib support is provided by GDAL through the sf and terra packages among others
#> Error in as.psp.SpatialLinesDataFrame(from) : 
#>   Only projected coordinates may be converted to spatstat class objects