|
| 1 | +--- |
| 2 | +title: "Tips and tricks for using the package" |
| 3 | +output: rmarkdown::html_vignette |
| 4 | +vignette: > |
| 5 | + %\VignetteIndexEntry{tips-and-tricks} |
| 6 | + %\VignetteEngine{knitr::rmarkdown} |
| 7 | + %\VignetteEncoding{UTF-8} |
| 8 | +--- |
| 9 | + |
| 10 | +```{r, include = FALSE} |
| 11 | +knitr::opts_chunk$set( |
| 12 | + collapse = TRUE, |
| 13 | + comment = "#>", |
| 14 | + fig.align = "center" |
| 15 | +) |
| 16 | +
|
| 17 | +# save user's options and pars |
| 18 | +user_options = options() |
| 19 | +user_par = par(no.readonly = TRUE) |
| 20 | +
|
| 21 | +# save files in the tempdir |
| 22 | +old_dd = Sys.getenv("OSMEXT_DOWNLOAD_DIRECTORY", tempdir()) |
| 23 | +Sys.setenv(OSMEXT_DOWNLOAD_DIRECTORY = tempdir()) |
| 24 | +
|
| 25 | +its_pbf = file.path( |
| 26 | + osmextract::oe_download_directory(), |
| 27 | + "test_its-example.osm.pbf" |
| 28 | +) |
| 29 | +file.copy( |
| 30 | + from = system.file("its-example.osm.pbf", package = "osmextract"), |
| 31 | + to = its_pbf, |
| 32 | + overwrite = TRUE |
| 33 | +) |
| 34 | +
|
| 35 | +# set new options |
| 36 | +options(width = 100) |
| 37 | +``` |
| 38 | + |
| 39 | +This vignette presents a collection of useful tips and tricks we've gathered over the years for effectively using this package to read, download, and filter OpenStreetMap (OSM) extracts. First of all, let's load the relevant packages: |
| 40 | + |
| 41 | +```{r setup} |
| 42 | +library(osmextract) |
| 43 | +``` |
| 44 | + |
| 45 | +## How can I get OSM objects by node/way id number? |
| 46 | + |
| 47 | +The example below demonstrates how to select a set of ways from an OSM extract, assuming you already know their OSM IDs: |
| 48 | + |
| 49 | +```{r} |
| 50 | +osm_id <- c("4419868", "6966733", "7989989", "15333726", "31705837") |
| 51 | +
|
| 52 | +out <- oe_get( |
| 53 | + place = "ITS Leeds", |
| 54 | + query = paste0( |
| 55 | + "SELECT * FROM lines WHERE osm_id IN (", paste0(osm_id, collapse = ","), ")" |
| 56 | + ), |
| 57 | + quiet = TRUE |
| 58 | +) |
| 59 | +print(out, n = 0L) |
| 60 | +``` |
| 61 | + |
| 62 | +```{r, include=FALSE} |
| 63 | +# reset par, options, and download directory |
| 64 | +options(user_options) |
| 65 | +par(user_par) |
| 66 | +Sys.setenv(OSMEXT_DOWNLOAD_DIRECTORY = old_dd) |
| 67 | +``` |
0 commit comments