| sl2sg {SpatialGraph} | R Documentation |
Map a SpatialLinesDataFrame into a SpatialGraph
Description
This function is the major workhorse to map an input
SpatialLinesDataFrame, as defined in the package sp, into a
SpatialGraph by using the spatial connectivity. Input is first
exploded by using explodeSLDF, and then all vertices in the
SpatialGraph are automatically generated according to crossings
in the input polylines.
Usage
sl2sg(SL, clipd = NULL, getdist = TRUE, getpath = FALSE)
Arguments
SL |
|
clipd |
distance threshold for clipping features, If NULL, a value of 1.0E-04 of the domain side size is used |
getdist |
calculate the |
getpath |
calculate the |
Details
A SpatialGraph is generated
Value
A SpatialGraph
Author(s)
Javier Garcia-Pintado, e-mail: j.garcia-pintado@marum.de
Examples
# x y
# create list of Line objects
if (1 > 2) {
library(sp)
library(SpatialGraph)
zz <- list()
zz[[1]] <- Line(matrix(
c(661750, 4229150,
662650, 4229450,
663550, 4227650,
663550, 4226850), ncol=2, byrow=TRUE))
zz[[2]] <- Line(matrix(
c(660250, 4229650,
661050, 4226450,
662550, 4225350,
664850, 4225850,
664650, 4229150,
662350, 4228850), ncol=2, byrow=TRUE))
# upgrade Line as Lines
for (i in 1:length(zz)) {
zz[[i]] <- Lines(list(zz[[i]]), ID=i)
}
# as SpatialLines
SL <- sp::SpatialLines(zz)
# as SpatialGraph including path calculation
SG <- sl2sg(SL, getpath=TRUE)
plot(SL, axes=TRUE)
points(SG@v, cex=2)
lines(SG@e, lwd=2)
points(SG@v, cex=2, col='grey', pch=19)
text(SG@v, labels=SG@v$ID)
# label edges and directions
textSGe(SG)
# show a distance matrix between nodes
SG@dist
# show path from node 1 to 3
SG@path[1,3]
}
[Package SpatialGraph version 1.0-4 Index]