| cpp_extract | R Documentation |
Single entry point to build a makegraph-ready graph from a geographic linestring source. The
source is dispatched on automatically from x's type (file extension, or object class). Exactly
five forms of x are recognized – see the x parameter below for the precise contract of
each, since passing the wrong shape of object for a given source (e.g. only part of an osmdata
result) fails loudly rather than silently producing a wrong graph.
cpp_extract(
x,
output = c("graph", "data.frame", "csv"),
out_prefix = NULL,
coords = TRUE,
epsg = NULL,
keep_length = FALSE,
snap_digits = NULL,
osm_params = list(),
geom_params = list()
)
x |
One of:
GeoPackage is not supported and has no plans to be: convert it to a shapefile first (e.g. via
|
output |
One of |
out_prefix |
Path prefix used when |
coords |
logical. If |
epsg |
Optional. A projected EPSG code (or anything |
keep_length |
logical. If |
snap_digits |
integer. Shapefile/sf sources: decimal places used to round coordinates before
deduplicating line endpoints into nodes. |
osm_params |
A list of options for OSM sources (
|
geom_params |
A list of options for shapefile/
|
Arguments are grouped by which family of source they apply to: arguments that work the same way
regardless of source stay as their own top-level parameter; source-specific ones are grouped into the
osm_params or geom_params list (see those two parameters below for the full list of what
each one accepts) – so a shapefile/sf call never needs to mention profile/
use_maxspeed, and a .pbf/osmdata/osmextract call never needs to mention
cost_field/direction_field.
Shapefile/sf sources are assumed to already be topologically clean, i.e. lines only meet at
their endpoints. OSM sources
(.pbf or osmdata) instead detect junctions in the middle of a way from OSM's own node ids
(a node referenced by 2 or more kept ways, or a way's own endpoint); for .pbf, a way referencing a
node outside the file (a regional extract cut through it) is dropped entirely, and for osmdata, a
way with a vertex that can't be matched against $osm_points is dropped, with a warning. A plain
sf object that looks OSM-derived (it has an osm_id column) but isn't the full
osmdata result is refused with an explanatory error, rather than silently treated as
topologically clean like a plain sf source and producing a wrong graph.
Depending on output: a cppRouting_graph, a named list of two data.frames
(data, coords), or (invisibly) the paths of the written CSV files. For
output = "data.frame", from/to/node_id are character regardless of
source: a node id is a label, not a quantity, matching what makegraph() itself already guarantees
for dict$ref. For output = "graph", that same real id is carried through dict$ref;
data$from/data$to stay makegraph()'s own compact integer index (its adjacency list is
always built on that, not on the original id).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.