json2sf_cs: Convert output from CycleStreets.net into sf object

Description Usage Arguments Examples

View source: R/journey.R

Description

Convert output from CycleStreets.net into sf object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
json2sf_cs(
  obj,
  cols = NULL,
  cols_extra = c("elevation_start", "elevation_end", "gradient_segment",
    "elevation_change", "provisionName"),
  smooth_gradient = FALSE,
  distance_cutoff = 50,
  gradient_cutoff = 0.1,
  n = 3
)

Arguments

obj

Object from CycleStreets.net read-in with

cols

Columns to be included in the result, a character vector or NULL for all available columns (see details for default)

cols_extra

Additional columns to be added providing summaries of gradient and other variables

smooth_gradient

Identify and fix anomalous gradients? TRUE by default. See https://github.com/Robinlovelace/cyclestreets/issues/14

distance_cutoff

Distance (m) used to identify anomalous gradients

gradient_cutoff

Gradient (%, e.g. 0.1 being 10%) used to identify anomalous gradients

n

The number of segments to use to smooth anomalous gradents. The default is 3, meaning segments directly before, after and including the offending segment.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from = "Leeds Rail Station"
to = "University of Leeds"
# from_point = tmaptools::geocode_OSM(from)
# to_point = tmaptools::geocode_OSM(to)
from_point = c(-1.54408, 53.79360)
to_point =   c(-1.54802, 53.79618)
# save result from the API call to journey.json
# res_json = journey(from_point, to_point, silent = FALSE, save_raw = TRUE)
# jsonlite::write_json(res_json, "inst/extdata/journey.json")
f = system.file(package = "cyclestreets", "extdata/journey.json")
obj = jsonlite::read_json(f, simplifyVector = TRUE)
rsf = json2sf_cs(obj, cols = c("distances"))
names(rsf)
rsf
rsf2 = json2sf_cs(obj, cols = NULL, cols_extra = NULL)
names(rsf2)
# stplanr::line2points(rsf) extract start and end points
sf:::plot.sf(rsf)
json2sf_cs(obj, cols = c("time", "busynance", "elevations"))
json2sf_cs(obj, cols = c("distances"), smooth_gradient = TRUE,
  gradient_cutoff = 0.05, distance_cutoff = 50)

Robinlovelace/cyclestreets documentation built on June 26, 2021, 11:22 p.m.