sf
object with OSM dataenrich.Rd
Perform enriched query on OSM and add as new column.
enrich_osm( dataset, name = NULL, key = NULL, value = NULL, type = "points", measure = "spherical", r = NULL, kernel = "uniform", reduce_fun = sum, control = list(), .verbose = TRUE, ... ) data_enrichment(ref_data, query, colname, .verbose = TRUE) measure_matrix(measure_name, measure_fun, ref_geometry, ftr_geometry) control_enrich(timeout = 300, memsize = 1073741824)
dataset | target |
---|---|
name | the column name of the feature to be added |
key | target OSM feature key to add, see |
value | target value for OSM feature key to add, see
|
type |
|
measure |
|
r | The search radius used by the |
kernel |
|
reduce_fun | The aggregation function used by the |
control | The list with configuration variables for the OSRM server.
It contains |
.verbose |
|
... | Additional parameters to be passed into the OSM query, such as a user-defined kernel. |
Type
represents the feature type to be considered. Usually this
would be points, but polygons and multipolygons are also possible. This
argument can also be a vector of multiple types. Non-point types will be
converted to points using the st_centroid
function from the sf
package
(NB this does not necessarily work well for all features!).
Available options are:
points
lines
polygons
multilines
multipolygons
Measure
represents the metric used to compute the distances or durations
between the rows in the dataset and the OSM features. The following metrics
are available in this package, assuming that the OSRM server is setup as
suggested in our guide at:
https://github.com/sodascience/osmenrich_docker:
spherical
distance_by_foot
duration_by_foot
distance_by_car
duration_by_car
distance_by_bike
duration_by_bike
Kernel
indicates the kernel function from the osmenrich
package to be
used to weight the objects retrieved by their distances (or durations) from
the reference objects and then convert these vectors into single numbers.
The simplest kernel allows the user to count the number of occurrences
of reference objects within a radius r
and is called kernel_uniform
.
For more details see the introductory vignette of osmenrich
:
vignette("introduction", package = "osmenrich")
If you want to get a large number of objects make sure to set the
.timeout
(time before request times out) and .memsize
(maxmimum
size of the request) arguments for the Overpass server and set
the "max-table-size" argument correctly when starting the
OSRM server(s).
if (FALSE) { # Load libraries library(tidyverse) library(sf) # Create example dataset sf_example <- tribble( ~person, ~lat, ~lon, "Alice", 52.12, 5.09, "Bob", 52.13, 5.08, ) %>% sf::st_as_sf( coords = c("lon", "lat"), crs = 4326 ) # Enrich data creating new column `waste_baskets` sf_enriched <- sf_example %>% enrich_osm( name = "n_waste_baskets", key = "amenity", value = "waste_basket", reduce_fun = sum ) }