Skip to contents

Takes an origin (A) and destination (B), represented by the linestring l, and generates 3 extra geometries based on points p:

Usage

line_via(l, p)

Arguments

l

A spatial lines object

p

A spatial points object

Details

  1. From A to P1 (P1 being the nearest point to A)

  2. From P1 to P2 (P2 being the nearest point to B)

  3. From P2 to B

Examples

library(sf)
l <- flowlines_sf[2:4, ]
p <- destinations_sf
lv <- line_via(l, p)
lv
#> Simple feature collection with 3 features and 15 fields
#> Active geometry column: geometry
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -1.550807 ymin: 53.81756 xmax: -1.516734 ymax: 53.82887
#> Geodetic CRS:  WGS 84
#>        Area.of.residence Area.of.workplace All Work.mainly.at.or.from.home
#> 920575         E02002361         E02002363  38                           0
#> 920578         E02002361         E02002367  10                           0
#> 920582         E02002361         E02002371  44                           0
#>        Underground..metro..light.rail..tram Train Bus..minibus.or.coach Taxi
#> 920575                                    0     1                     4    1
#> 920578                                    0     0                     1    0
#> 920582                                    0     0                     2    2
#>        Motorcycle..scooter.or.moped Driving.a.car.or.van
#> 920575                            0                   24
#> 920578                            0                    8
#> 920582                            0                   28
#>        Passenger.in.a.car.or.van Bicycle On.foot Other.method.of.travel.to.work
#> 920575                         4       0       4                              0
#> 920578                         0       0       1                              0
#> 920582                         3       3       6                              0
#>                         id                       geometry
#> 920575 E02002361 E02002363 LINESTRING (-1.516734 53.82...
#> 920578 E02002361 E02002367 LINESTRING (-1.516734 53.82...
#> 920582 E02002361 E02002371 LINESTRING (-1.516734 53.82...
#>                              leg_orig                        leg_via
#> 920575 LINESTRING (-1.516734 53.82... LINESTRING (-1.517333 53.82...
#> 920578 LINESTRING (-1.516734 53.82... LINESTRING (-1.517333 53.82...
#> 920582 LINESTRING (-1.516734 53.82... LINESTRING (-1.517333 53.82...
#>                              leg_dest
#> 920575 LINESTRING (-1.53741 53.829...
#> 920578 LINESTRING (-1.555112 53.82...
#> 920582 LINESTRING (-1.534205 53.81...
# library(mapview)
# mapview(lv) +
#    mapview(lv$leg_orig, col = "red")
plot(lv[3], lwd = 9, reset = FALSE)
plot(lv$leg_orig, col = "red", lwd = 5, add = TRUE)
plot(lv$leg_via, col = "black", add = TRUE)
plot(lv$leg_dest, col = "green", lwd = 5, add = TRUE)