rasterToLineSegments {roads} | R Documentation |
Convert raster to lines
Description
Converts rasters that represent lines into an sf object.
Usage
rasterToLineSegments(rast, method = "mst")
Arguments
rast |
|
method |
character. Method of building lines. Options are |
Details
For method = "nearest"
raster is first converted to points and then
lines are drawn between the nearest points. If there are two different ways
to connect the points that have the same distance both are kept which can
cause doubled lines. USE WITH CAUTION. method = "mst"
converts the
raster to points, reclassifies the raster so roads are 0 and other cells are
1 and then uses projectRoads
to connect all the points with a minimum
spanning tree. This will always connect all raster cells and is slower but
will not double lines as often. Neither method is likely to work for very
large rasters
Value
an sf simple feature collection
Examples
CLUSexample <- prepExData(CLUSexample)
# works well for very simple roads
roadLine1 <- rasterToLineSegments(CLUSexample$roads)
# longer running more realistic examples
demoScen <- prepExData(demoScen)
# mst method works well in this case
roadLine2 <- rasterToLineSegments(demoScen[[1]]$road.rast)
# nearest method has doubled line where the two roads meet
roadLine3 <- rasterToLineSegments(demoScen[[1]]$road.rast, method = "nearest")
# The mst method can also produce odd results in some cases
roadLine4 <- rasterToLineSegments(demoScen[[4]]$road.rast)