Learn R Programming

osrm (version 4.1.1)

osrmNearest: Get the Nearest Point on the Street Network

Description

This function interfaces with the nearest OSRM service.

Usage

osrmNearest(
  loc,
  exclude,
  osrm.server = getOption("osrm.server"),
  osrm.profile = getOption("osrm.profile")
)

Value

The output of this function is an sf POINT of the point on the street network.

It contains 2 fields:

  • id, the point identifierv

  • distance, the distance in meters to the supplied input point.

Arguments

loc

a point to snap to the street network. loc can be:

  • a vector of coordinates (longitude and latitude, WGS 84),

  • a data.frame of longitudes and latitudes (WGS 84),

  • a matrix of longitudes and latitudes (WGS 84),

  • an sfc object of type POINT,

  • an sf object of type POINT.

If src is a data.frame, a matrix, an sfc object or an sf object then only the first row or element is considered.

exclude

pass an optional "exclude" request option to the OSRM API.

osrm.server

the base URL of the routing server.

osrm.profile

the routing profile to use, e.g. "car", "bike" or "foot".

Examples

Run this code
if (FALSE) {
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "osrm"),
  quiet = TRUE
)
pt <- osrmNearest(apotheke.sf[56, ])
pt$distance
}

Run the code above in your browser using DataLab