### Get OSM Data with oe_get Source: https://docs.ropensci.org/osmextract/reference/oe_get.html Demonstrates how to use oe_get to retrieve OSM data for a specified place. It includes steps to copy a local example file to a temporary directory to avoid internet dependency for the example. ```r # Copy ITS file to tempdir so that the examples do not require internet # connection. You can skip the next 4 lines when running the examples # locally. its_pbf = file.path(tempdir(), "test_its-example.osm.pbf") file.copy( from = system.file("its-example.osm.pbf", package = "osmextract"), to = its_pbf, overwrite = TRUE ) #> [1] TRUE # Match, download (not really) and convert OSM extracts associated to a simple test. its = oe_get("ITS Leeds", download_directory = tempdir()) #> The input place was matched with: ITS Leeds #> The chosen file was already detected in the download directory. Skip downloading. #> Starting with the vectortranslate operations on the input file! #> 0...10...20...30...40...50...60...70...80...90...100 - done. #> Finished the vectortranslate operations on the input file! #> Reading layer `lines' from data source `/tmp/Rtmp7JYF3j/test_its-example.gpkg' using driver `GPKG' #> Simple feature collection with 189 features and 10 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -1.562458 ymin: 53.80471 xmax: -1.548076 ymax: 53.81105 #> Geodetic CRS: WGS 84 class(its) #> [1] "sf" "data.frame" unique(sf::st_geometry_type(its)) #> [1] LINESTRING #> 18 Levels: GEOMETRY POINT LINESTRING POLYGON MULTIPOINT ... TRIANGLE ``` -------------------------------- ### Match Input Zone and Download OSM Data Source: https://docs.ropensci.org/osmextract/reference/oe_vectortranslate.html This snippet shows how to match an input zone to an OSM PBF file and then download it. It includes copying a local example file to a temporary directory to avoid requiring an internet connection for the example. ```R its_match = oe_match("ITS Leeds") #> The input place was matched with: ITS Leeds #> $url #> [1] "https://github.com/ropensci/osmextract/raw/master/inst/its-example.osm.pbf" #> #> $file_size #> [1] 40792 #> file.copy( from = system.file("its-example.osm.pbf", package = "osmextract"), to = file.path(tempdir(), "test_its-example.osm.pbf"), overwrite = TRUE ) #> [1] TRUE its_pbf = oe_download( file_url = its_match$url, file_size = its_match$file_size, download_directory = tempdir(), provider = "test" ) #> The chosen file was already detected in the download directory. Skip downloading. list.files(tempdir(), pattern = "pbf|gpkg") #> [1] "test_its-example.osm.pbf" ``` -------------------------------- ### Example: Update OSM Data and Manage Files Source: https://docs.ropensci.org/osmextract/reference/oe_update.html This example demonstrates how to set up a temporary directory, populate it with OSM data, check its contents, and then use oe_update to update the .pbf files while cleaning up .gpkg files. It's wrapped in a dontrun block for safety. ```R if (FALSE) { # \dontrun{ # Set up a fake directory with .pbf and .gpkg files fake_dir = tempdir() # Fill the directory oe_get("Andorra", download_directory = fake_dir, download_only = TRUE) # Check the directory list.files(fake_dir, pattern = "gpkg|pbf") # Update all .pbf files and delete all .gpkg files oe_update(fake_dir, quiet = TRUE) list.files(fake_dir, pattern = "gpkg|pbf")} # } ``` -------------------------------- ### Install osmextract Package Source: https://docs.ropensci.org/osmextract/index.html Install the osmextract package from GitHub using the remotes package. This is the initial step before loading the package. ```r remotes::install_github("ropensci/osmextract") ``` -------------------------------- ### Import OSM Data for Various Locations Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Demonstrates importing OSM data for different places using oe_get(). Includes examples for downloading only, getting specific keys, and importing with extra tags or different string handling. ```r oe_get("Andorra") oe_get("Leeds") oe_get("Goa") # A state in India oe_get("Malta", layer = "points", quiet = FALSE) oe_match("RU", match_by = "iso3166_1_alpha2", quiet = FALSE) oe_get("Andorra", download_only = TRUE) oe_get_keys("Andorra") oe_get_keys("Andorra", values = TRUE) oe_get_keys("Andorra", values = TRUE, which_keys = c("oneway", "surface", "maxspeed")) oe_get("Andorra", extra_tags = c("maxspeed", "oneway", "ref", "junction"), quiet = FALSE) oe_get("Andora", stringsAsFactors = FALSE, quiet = TRUE, as_tibble = TRUE) # like read_sf ``` -------------------------------- ### Install osmextract from CRAN Source: https://docs.ropensci.org/osmextract/index.html Standard installation of the osmextract package from the CRAN repository. ```r install.packages("osmextract") ``` -------------------------------- ### Get Walking Network Data Source: https://docs.ropensci.org/osmextract/reference/oe_get_network.html This example demonstrates how to retrieve network data specifically for walking mode of transport for Leeds. The downloaded data is then plotted. ```r # walking mode of transport its_walking = oe_get_network( "ITS Leeds", mode = "walking", download_directory = tempdir(), quiet = TRUE ) plot(its_walking["highway"], lwd = 2, key.pos = 4, key.width = lcm(2.75)) ``` -------------------------------- ### Get OSM Data for Different Locations Source: https://docs.ropensci.org/osmextract/index.html Examples of using oe_get() for different locations and with additional parameters like 'extra_tags' for custom attributes or 'query' for SQL subsetting. ```r malta = oe_get("Malta", quiet = TRUE) andorra = oe_get("Andorra", extra_tags = "ref") leeds = oe_get("Leeds") goa = oe_get("Goa", query = "SELECT highway, geometry FROM 'lines'") ``` -------------------------------- ### Find .gpkg and .osm.pbf files for 'ITS Leeds' Source: https://docs.ropensci.org/osmextract/reference/oe_find.html This example demonstrates how to find both .gpkg and .osm.pbf files for a specific place. It requires the 'ITS Leeds' file to be present or downloaded. ```r res = file.copy( from = system.file("its-example.osm.pbf", package = "osmextract"), to = file.path(tempdir(), "test_its-example.osm.pbf"), overwrite = TRUE ) res = oe_get("ITS Leeds", quiet = TRUE, download_directory = tempdir()) oe_find("ITS Leeds", provider = "test", download_directory = tempdir()) ``` -------------------------------- ### Edit Renviron for Download Directory Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Provides an example of how to set the OSMEXT_DOWNLOAD_DIRECTORY environment variable using the usethis package to specify a custom download location. ```R usethis::edit_r_environ() ``` -------------------------------- ### Example Warning Message Source: https://docs.ropensci.org/osmextract/index.html This is an example of a warning message that may appear if using older versions of GDAL or PROJ. The functions should still work correctly. ```r st_crs<- : replacing crs does not reproject data; use st_transform for that ``` -------------------------------- ### Attempt to Get Keys from a Non-existent Layer Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html This example shows a case where `oe_get_keys` might fail if the specified layer does not exist in the GeoPackage file. It is wrapped in `if (FALSE)` to prevent execution. ```r if (FALSE) { # \dontrun{ oe_get_keys(its_path, layer = "points")} ``` -------------------------------- ### Download and Plot ITS Network Data Source: https://docs.ropensci.org/osmextract/reference/oe_get_network.html This snippet shows how to download default ITS network data for Leeds and plot it. It first copies an example PBF file to a temporary directory to ensure the example runs without an internet connection. ```r its_pbf = file.path(tempdir(), "test_its-example.osm.pbf") file.copy( from = system.file("its-example.osm.pbf", package = "osmextract"), to = its_pbf, overwrite = TRUE ) #> [1] TRUE # default value returned by OSM its = oe_get( "ITS Leeds", quiet = TRUE, download_directory = tempdir() ) plot(its["highway"], lwd = 2, key.pos = 4, key.width = lcm(2.75)) ``` -------------------------------- ### Clean up temporary directory Source: https://docs.ropensci.org/osmextract/reference/oe_find.html This command removes .pbf and .gpkg files from the specified temporary directory after running examples. ```r oe_clean(tempdir()) ``` -------------------------------- ### Find files for 'Isle of Wight' and 'Malta' with download option Source: https://docs.ropensci.org/osmextract/reference/oe_find.html This example demonstrates finding files for 'Isle of Wight' and attempting to download 'Malta' if it's missing. It uses a temporary directory for the downloads. ```r oe_find("Isle of Wight", download_directory = tempdir()) oe_find("Malta", download_if_missing = TRUE, download_directory = tempdir()) ``` -------------------------------- ### Create new provider zone file using usethis Source: https://docs.ropensci.org/osmextract/articles/providers.html Demonstrates how to create a new R script for defining provider zones, using 'bbbike' as an example, and suggests using the 'usethis::use_data_raw()' function for better practice. ```r file.edit("data-raw/bbbike_zones.R") # or, even better, use usethis::use_data_raw("bbbike_zones") ``` -------------------------------- ### Download OSM Extract Example Source: https://docs.ropensci.org/osmextract/reference/oe_download.html Demonstrates how to use oe_download to download OSM extract files. It shows how to obtain file URLs and sizes using oe_match and then download the files to a temporary directory, specifying the provider and file size. ```R (its_match = oe_match("ITS Leeds", quiet = TRUE)) #> $url #> [1] "https://github.com/ropensci/osmextract/raw/master/inst/its-example.osm.pbf" #> #> $file_size #> [1] 40792 #> if (FALSE) { # \dontrun{ oe_download( file_url = its_match$url, file_size = its_match$file_size, provider = "test", download_directory = tempdir() ) iow_url = oe_match("Isle of Wight") oe_download( file_url = iow_url$url, file_size = iow_url$file_size, download_directory = tempdir() ) Sucre_url = oe_match("Sucre", provider = "bbbike") oe_download( file_url = Sucre_url$url, file_size = Sucre_url$file_size, download_directory = tempdir() )} # } ``` -------------------------------- ### Edit geofabrik_zones.R file Source: https://docs.ropensci.org/osmextract/articles/providers.html Opens the 'geofabrik_zones.R' file in RStudio, which serves as an example for creating new provider zone objects. ```r file.edit("data-raw/geofabrik_zones.R") ``` -------------------------------- ### get_default_osmconf_ini Source: https://docs.ropensci.org/osmextract/reference/index.html Get the default osmconf.ini configuration file. ```APIDOC ## get_default_osmconf_ini() ### Description Get default osmconf.ini ### Returns Path to the default osmconf.ini file. ``` -------------------------------- ### Download OSM Data with SQL Query Source: https://docs.ropensci.org/osmextract/reference/oe_get.html Use the 'query' argument to filter OpenStreetMap data during download. This example retrieves only 'oneway' streets from a specified location. ```r q = "SELECT * FROM 'lines' WHERE oneway == 'yes'" its_oneway = oe_get("ITS Leeds", query = q, download_directory = tempdir()) ``` -------------------------------- ### Find only .gpkg files for 'Leeds' using 'bbbike' provider Source: https://docs.ropensci.org/osmextract/reference/oe_find.html This example shows how to find only the .gpkg file for 'Leeds' using the 'bbbike' provider, with the option to download if missing. It also specifies a temporary directory for downloads. ```r oe_find( "Leeds", provider = "bbbike", download_if_missing = TRUE, download_directory = tempdir(), return_pbf = FALSE ) ``` -------------------------------- ### Get Download Directory with Environment Variable Source: https://docs.ropensci.org/osmextract/reference/oe_download_directory.html Demonstrates how to temporarily set the `OSMEXT_DOWNLOAD_DIRECTORY` environment variable to a temporary directory and then retrieve the download directory path. This is useful for testing or ensuring downloads go to a specific location. ```r if (requireNamespace("withr", quietly = TRUE)) { withr::with_envvar( c("OSMEXT_DOWNLOAD_DIRECTORY" = tempdir()), oe_download_directory() ) } ``` -------------------------------- ### Find only .osm.pbf files for 'ITS Leeds' Source: https://docs.ropensci.org/osmextract/reference/oe_find.html This example shows how to retrieve only the path to the .osm.pbf file for a given place, excluding the .gpkg file. It assumes the necessary files are available in the specified directory. ```r oe_find( "ITS Leeds", provider = "test", download_directory = tempdir(), return_gpkg = FALSE ) ``` -------------------------------- ### Combine Pattern Matching and Direct Matching Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Illustrates a workflow where `oe_match_pattern` is used to identify potential matches, and then `oe_match` is used with a specific provider to get the download URL for a chosen match. ```r oe_match_pattern("Valencia") #> $geofabrik #> [1] "Valencia" #> #> $openstreetmap_fr #> [1] "Comunitat Valenciana" "Valencia" oe_match("Comunitat Valenciana", provider = "openstreetmap_fr") #> The input place was matched with: Comunitat Valenciana #> $url #> [1] "http://download.openstreetmap.fr/extracts/europe/spain/comunitat_valenciana-latest.osm.pbf" #> #> $file_size #> [1] 152737006 ``` -------------------------------- ### Access test_zones Object Source: https://docs.ropensci.org/osmextract/reference/test_zones.html This snippet shows how to access the test_zones object, which is an sf object representing a minimal provider's database for examples and tests. ```R test_zones ``` -------------------------------- ### License Notice for Interactive Programs Source: https://docs.ropensci.org/osmextract/LICENSE.html This snippet displays the standard copyright and licensing notice for interactive programs. It should be shown when the program starts in interactive mode. ```text osmextract Copyright (C) 2019 Robin Lovelace This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details. ``` -------------------------------- ### Download Data and Get Keys Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html This snippet shows how to download a specific dataset ('ITS Leeds' points layer) using `oe_get` and then retrieve all available attribute keys for that layer using `oe_get_keys`. It also includes cleanup of downloaded files. ```R its_path = oe_get( "ITS Leeds", layer = "points", download_only = TRUE, download_directory = tempdir(), quiet = TRUE ) oe_get_keys(its_path, layer = "points") #> [1] "amenity" "addr:postcode" #> [3] "addr:street" "addr:city" #> [5] "fhrs:id" "capacity" #> [7] "covered" "addr:housenumber" #> [9] "operator" "bicycle_parking" #> [11] "addr:suburb" "natural" #> [13] "shop" "crossing" #> [15] "naptan:AtcoCode" "naptan:Bearing" #> [17] "naptan:CommonName" "naptan:PlusbusZoneRef" #> [19] "naptan:ShortCommonName" "naptan:Street" #> [21] "naptan:verified" "addr:housename" #> [23] "bus" "collection_times" #> [25] "local_ref" "naptan:Crossing" #> [27] "naptan:Indicator" "naptan:Landmark" #> [29] "public_transport" "condition" #> [31] "entrance" "ref:UK:leedscc:bin" #> [33] "shelter" "waste_basket:model" #> [35] "crossing_ref" "wheelchair" #> [37] "brand" "brand:wikidata" #> [39] "brand:wikipedia" "noexit" #> [41] "booth" "old_name" #> [43] "opening_hours" "advertising" #> [45] "foot" "kerb" #> [47] "post_box:type" "tactile_paving" #> [49] "takeaway" "toilets:wheelchair" #> [51] "addr:unit" "cuisine" #> [53] "level" "naptan:Notes" #> [55] "royal_cypher" "source:addr" #> [57] "timetable" "tourism" #> [59] "website" "access" #> [61] "addr:source" "artist_name" #> [63] "artwork_type" "atm" #> [65] "bicycle" "building" #> [67] "contact:website" "direction" #> [69] "fee" "healthcare" #> [71] "historic" "horse" #> [73] "live_display" "loc_name" #> [75] "material" "motor_vehicle" #> [77] "naptan:BusStopType" "not:addr:postcode" #> [79] "phone" "post_box:design" #> [81] "recycling:glass_bottles" "recycling:paper" #> [83] "traffic_signals" "url" #> [85] "wikidata" # Remove .pbf and .gpkg files in tempdir rm(its_pbf, res, its_path, its, its_extra) oe_clean(tempdir()) ``` -------------------------------- ### Get the download directory Source: https://docs.ropensci.org/osmextract/reference/oe_download_directory.html This function returns the download directory used by the package. By default, it is equal to the output of `tools::R_user_dir("osmextract", "data")`. Such value can be overwritten by setting the `OSMEXT_DOWNLOAD_DIRECTORY` environment variable. If the directory does not exist, it will be created. ```APIDOC ## Function: oe_download_directory ### Description Returns the download directory used by the package. ### Usage ```R oe_download_directory() ``` ### Value A character vector representing the path for the download directory used by the package. ### Examples ```R # Get the default download directory oe_download_directory() # Example with environment variable override if (requireNamespace("withr", quietly = TRUE)) { withr::with_envvar( c("OSMEXT_DOWNLOAD_DIRECTORY" = tempdir()), oe_download_directory() ) } ``` ``` -------------------------------- ### Match Place with Different Providers Source: https://docs.ropensci.org/osmextract/articles/osmextract.html When an exact match is not found with the default provider, `oe_match` checks other supported providers. This example shows fallback to 'bbbike' and 'openstreetmap_fr'. ```r oe_match("Leeds") #> No exact match found for place = Leeds and provider = geofabrik. Best match is Laos. #> Checking the other providers... #> An exact string match was found using provider = bbbike. #> $url #> [1] "https://download.bbbike.org/osm/bbbike/Leeds/Leeds.osm.pbf" #> #> $file_size #> [1] 38177699 oe_match("London") #> No exact match found for place = London and provider = geofabrik. Best match is Jordan. #> Checking the other providers... #> An exact string match was found using provider = bbbike. #> $url #> [1] "https://download.bbbike.org/osm/bbbike/London/London.osm.pbf" #> #> $file_size #> [1] 189372355 oe_match("Vatican City") #> No exact match found for place = Vatican City and provider = geofabrik. Best match is Tianjin. #> Checking the other providers... #> An exact string match was found using provider = openstreetmap_fr. #> $url #> [1] "http://download.openstreetmap.fr/extracts/europe/vatican_city-latest.osm.pbf" #> #> $file_size #> [1] 771128 ``` -------------------------------- ### Import OSM Data Using Coordinates Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Import OSM data by providing geographical coordinates. Examples show geocoding a capital city and then importing data for those coordinates, including specifying different providers. ```r # Geocode the capital of Goa, India (geocode_panaji = tmaptools::geocode_OSM("Panaji, India")) oe_get(geocode_panaji$coords, quiet = FALSE) # Large file oe_get(geocode_panaji$coords, provider = "bbbike", quiet = FALSE) oe_get(geocode_panaji$coords, provider = "openstreetmap_fr", quiet = FALSE) # Spatial match starting from the coordinates of Arequipa, Peru geocode_arequipa = c(-71.537005, -16.398874) oe_get(geocode_arequipa, quiet = FALSE) oe_get(geocode_arequipa, provider = "bbbike", quiet = FALSE) # Error oe_get(geocode_arequipa, provider = "openstreetmap_fr", quiet = FALSE) # No country-specific extract ``` -------------------------------- ### Get Keys from a File Path Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html Retrieve keys from a file path directly, which can be faster than loading the entire `sf` object first. This method is efficient when you only need to analyze the keys without processing the full spatial data. ```r its_path = oe_get( "ITS Leeds", download_only = TRUE, download_directory = tempdir(), quiet = TRUE ) oe_get_keys(its_path, values = TRUE) ``` -------------------------------- ### Get OSM Data with oe_get() Source: https://docs.ropensci.org/osmextract/articles/osmextract.html A convenient wrapper function to perform multiple steps of OSM data import in one go: matching the place, downloading, translating to GPKG, and reading the data. It simplifies the import process. ```r its_lines = oe_get("ITS Leeds") #> The input place was matched with: ITS Leeds #> The chosen file was already detected in the download directory. Skip downloading. #> The corresponding gpkg file was already detected. Skip vectortranslate operations. #> Reading layer `lines' from data source `/tmp/Rtmp2tl7Wt/test_its-example.gpkg' using driver `GPKG' #> Simple feature collection with 189 features and 12 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -1.562458 ymin: 53.80471 xmax: -1.548076 ymax: 53.81105 #> Geodetic CRS: WGS 84 ``` -------------------------------- ### Get Default Download Directory Source: https://docs.ropensci.org/osmextract/reference/oe_download_directory.html Retrieves the default directory path used by the osmextract package for downloading data. This path is typically determined by `tools::R_user_dir` but can be influenced by environment variables. ```r oe_download_directory() ``` -------------------------------- ### Get Keys from a File Path Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html Retrieves unique keys and their values from an OSM data file (e.g., .gpkg) by providing its file path. This can be faster than reading the entire file into an sf object first. ```APIDOC ## oe_get_keys(its_path, values = TRUE) ### Description Retrieves unique keys and their associated values from an OSM data file specified by its path. ### Parameters #### Path Parameters - **its_path** (character) - The file path to the OSM data file (e.g., a .gpkg file). - **values** (logical) - If TRUE, returns the unique values for each key. Defaults to FALSE. ### Request Example ```R its_path <- oe_get("ITS Leeds", download_only = TRUE, download_directory = tempdir(), quiet = TRUE) oe_get_keys(its_path, values = TRUE) ``` ### Response #### Success Response (Output) Returns a list where each element is a key from the OSM data, followed by its unique values and their counts. The output is sorted by the percentage of NA values for each key. #### Response Example ``` Found 38 unique keys, printed in ascending order of % NA values. The first 10 keys are: surface (91% NAs) = {#asphalt = 12; #paved = 3; #cobblestone = 1; #paving_sto...} lanes (91% NAs) = {#2 = 9; #1 = 7} ... ``` ``` -------------------------------- ### oe_get_boundary Source: https://docs.ropensci.org/osmextract/reference/index.html Get the administrative boundary for a given place. ```APIDOC ## oe_get_boundary() ### Description Get the administrative boundary for a given place ### Usage `oe_get_boundary(place, download_dir = oe_download_directory(), quiet = FALSE)` ### Parameters - **place** (character or sf object) - The place to get the boundary for. - **download_dir** (character, optional) - Directory to save downloaded boundary data. - **quiet** (logical, optional) - If TRUE, suppress messages. ``` -------------------------------- ### oe_find Source: https://docs.ropensci.org/osmextract/reference/index.html Get the path of .pbf and .gpkg files associated with an input OSM extract. ```APIDOC ## oe_find() ### Description Get the path of .pbf and .gpkg files associated with an input OSM extract ### Usage `oe_find(place, download_dir = oe_download_directory(), quiet = FALSE)` ### Parameters - **place** (character or sf object) - The place or area to search for extracts. - **download_dir** (character, optional) - The directory to search within. Defaults to the package's download directory. - **quiet** (logical, optional) - If TRUE, suppress messages. ``` -------------------------------- ### List Downloaded Files Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Lists files in the download directory, useful for verifying downloaded `.pbf` or converted `.gpkg` files. ```r list.files(oe_download_directory(), pattern = "pbf|gpkg") ``` -------------------------------- ### Configure Download Directory Source: https://docs.ropensci.org/osmextract/index.html Set a custom directory for saving OSM data by adding OSMEXT_DOWNLOAD_DIRECTORY to your .Renviron file using usethis::edit_r_environ(). ```r usethis::edit_r_environ() # Add a line containing: OSMEXT_DOWNLOAD_DIRECTORY=/path/where/to/save/files ``` -------------------------------- ### Plot OSM Data Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Visualize the imported OSM data, for example, plotting highway features with specified line width and no legend. ```r par(mar = rep(0.1, 4)) plot(its_lines["highway"], lwd = 2, key.pos = NULL) ``` -------------------------------- ### Get Default OSM Configuration INI Path Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Retrieves the default path to the GDAL osmconf.ini configuration file used by osmextract. ```r (default_config <- get_default_osmconf_ini()) #> [1] "/usr/share/gdal/osmconf.ini" ``` -------------------------------- ### Using a Custom osmconf.ini File Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Demonstrates how to use a custom osmconf.ini file to modify extraction behavior, such as reporting all nodes and ways. This can lead to more detailed output compared to default settings. ```R oe_get("ITS Leeds", provider = "test", osmconf_ini = temp_ini, quiet = FALSE) ``` -------------------------------- ### Read OpenStreetMap Data as Tibble Source: https://docs.ropensci.org/osmextract/reference/oe_get.html An example mimicking the behavior of `read_sf` by retrieving OpenStreetMap data for 'Andora' and returning it as a tibble with quiet processing. ```r oe_get("Andora", stringsAsFactors = FALSE, quiet = TRUE, as_tibble = TRUE) ``` -------------------------------- ### Download Only .osm.pbf File (Skip Vector Translation) Source: https://docs.ropensci.org/osmextract/reference/oe_get.html Use oe_get with download_only = TRUE and skip_vectortranslate = TRUE to download the raw .osm.pbf file, skipping the vector translation step. This is the fastest download option if you need the raw data. ```r oe_get( "ITS Leeds", download_only = TRUE, skip_vectortranslate = TRUE, quiet = TRUE, download_directory = tempdir() ) ``` -------------------------------- ### Fallback to Other Providers with oe_match Source: https://docs.ropensci.org/osmextract/reference/oe_match.html If an exact match is not found with the default provider (geofabrik), oe_match will test other providers. This example shows a fallback to bbbike. ```R oe_match("Leeds") ``` -------------------------------- ### Get OSM Keys from GeoPackage Layer Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Retrieves all unique OSM keys stored in the 'other_tags' field for a specified layer in a GeoPackage file. ```r oe_get_keys(its_gpkg, layer = "lines") #> [1] "surface" "lanes" "bicycle" "lit" #> [5] "access" "oneway" "maxspeed" "ref" #> [9] "foot" "natural" "lanes:backward" "lanes:forward" #> [13] "source:name" "step_count" "lanes:psv:backward" "alt_name" #> [17] "layer" "motor_vehicle" "tunnel" "bridge" #> [21] "covered" "incline" "lanes:psv" "service" #> [25] "turn:lanes" "turn:lanes:forward" "frequency" "indoor" #> [29] "lcn" "level" "maxheight" "operator" #> [33] "power" "source:geometry" "substation" "turn:lanes:backward" #> [37] "voltage" "website" ``` -------------------------------- ### Import cycling network Source: https://docs.ropensci.org/osmextract/reference/oe_get_network.html Imports the default cycling network for a specified place. Additional arguments like boundary or force_download can be passed. ```r cycling_network <- oe_get_network(place = "Germany", mode = "cycling") ``` -------------------------------- ### Get Specific OSM Keys (Values Ignored) Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html Retrieves only specified keys from the 'other_tags' column, ignoring their values. The 'values' argument is FALSE by default. ```R oe_get_keys(zone = "/path/to/your/file.osm.pbf", layer = "lines", which_keys = c("highway", "name")) ``` -------------------------------- ### Load osmextract and sf packages Source: https://docs.ropensci.org/osmextract/articles/providers_comparisons.html Loads the necessary libraries for using osmextract and spatial data handling. ```r library(osmextract) #> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright. #> Check the package website, https://docs.ropensci.org/osmextract/, for more details. library(sf) #> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE ``` -------------------------------- ### Clone osmextract repository and open project Source: https://docs.ropensci.org/osmextract/articles/providers.html Clones the osmextract GitHub repository and opens the RStudio project file, providing access to the package's source code for reference. ```bash git clone git@github.com:ropensci/osmextract rstudio osmextract/osmextract.Rproj ``` -------------------------------- ### Get OSM Keys and Values Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html Retrieves both the keys and their corresponding values from the 'other_tags' column for the 'lines' layer. The 'values' argument must be set to TRUE. ```R oe_get_keys(zone = "/path/to/your/file.osm.pbf", layer = "lines", values = TRUE) ``` -------------------------------- ### Get Driving Network Data Source: https://docs.ropensci.org/osmextract/reference/oe_get_network.html This snippet shows how to retrieve network data for driving mode of transport for Leeds. The resulting network data is then plotted. ```r # driving mode of transport its_driving = oe_get_network( "ITS Leeds", mode = "driving", download_directory = tempdir(), quiet = TRUE ) plot(its_driving["highway"], lwd = 2, key.pos = 4, key.width = lcm(2.75)) ``` -------------------------------- ### Load osmextract Package Source: https://docs.ropensci.org/osmextract/articles/tips-and-tricks.html Load the osmextract package to begin using its functionalities. This is a standard first step for any R session utilizing the package. ```r library(osmextract) #> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright. #> Check the package website, https://docs.ropensci.org/osmextract/, for more details. ``` -------------------------------- ### Transforming CRS with vectortranslate_options Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Demonstrates using 'vectortranslate_options' to modify the Coordinate Reference System (CRS) of the output GeoPackage. This example transforms data from EPSG:4326 to EPSG:27700. ```R oe_get("ITS Leeds", vectortranslate_options = c("-t_srs", "EPSG:27700"), quiet = FALSE) ``` -------------------------------- ### Plot OSM Data Source: https://docs.ropensci.org/osmextract/index.html Visualize the downloaded OSM data using base R plotting functions. This example plots lines and points for the Isle of Wight. ```r par(mar = rep(0, 4)) plot(st_geometry(osm_lines), xlim = c(-1.59, -1.1), ylim = c(50.5, 50.8)) plot(st_geometry(osm_points), xlim = c(-1.59, -1.1), ylim = c(50.5, 50.8)) ``` -------------------------------- ### Retrieve OpenStreetMap Data from Alternative Providers Source: https://docs.ropensci.org/osmextract/reference/oe_get.html Demonstrates fetching OpenStreetMap data for a place, specifying alternative providers if needed. ```r baku = oe_get(place = "Baku") ``` -------------------------------- ### Get OSM Keys from Lines Layer Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html Retrieves all unique keys present in the 'other_tags' column for the 'lines' layer of a specified zone. The keys are sorted by frequency. ```R oe_get_keys(zone = "/path/to/your/file.osm.pbf", layer = "lines") ``` -------------------------------- ### Spatial Clipping with Boundary as First Argument Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Starting from version 0.6, the boundary object can be passed as the first argument to `oe_get` for automatic spatial clipping during download. ```R its_small = oe_get(its_bbox, provider = "test") #> The input place was matched with ITS Leeds. #> Setting 'boundary = place' to geographically subset the output. Use boundary = NA to import full extract. #> The chosen file was already detected in the download directory. Skip downloading. #> Starting with the vectortranslate operations on the input file! #> 0...10...20...30...40...50...60...70...80...90...100 - done. #> Finished the vectortranslate operations on the input file! #> Reading layer `lines' from data source `/tmp/Rtmp2tl7Wt/test_its-example.gpkg' using driver `GPKG' #> Simple feature collection with 5 features and 10 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -1.559731 ymin: 53.80676 xmax: -1.556762 ymax: 53.80945 #> Geodetic CRS: WGS 84 ``` -------------------------------- ### Download Cycleways in England with osmextract Source: https://docs.ropensci.org/osmextract/index.html Shows how to download and process large OSM datasets efficiently using osmextract, converting data to the .gpkg format. ```r library(osmextract) cycleways_england = oe_get( "England", quiet = FALSE, query = "SELECT * FROM 'lines' WHERE highway = 'cycleway'" ) par(mar = rep(0.1, 4)) plot(sf::st_geometry(cycleways_england)) ``` -------------------------------- ### Match OSM Extract with Place Name Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Matches a small OSM extract using a place name string. This example uses a specific extract for 'ITS Leeds'. ```R # ITS stands for Institute for Transport Studies: https://environment.leeds.ac.uk/transport (its_details = oe_match("ITS Leeds")) ``` -------------------------------- ### Get Specific OSM Keys and Values Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html Retrieves only specified keys and their corresponding values from the 'other_tags' column. The 'which_keys' argument takes a character vector of desired keys. ```R oe_get_keys(zone = "/path/to/your/file.osm.pbf", layer = "lines", values = TRUE, which_keys = c("highway", "name")) ``` -------------------------------- ### Add a Key to an Existing .gpkg File Source: https://docs.ropensci.org/osmextract/reference/oe_get_keys.html Demonstrates how to add a new key (column) to an existing GeoPackage file using `oe_read` with a SQL query. This allows for targeted data extraction and modification without re-processing the entire dataset. ```r its = oe_get("ITS Leeds", download_directory = tempdir()) its_extra = oe_read( its_path, query = "SELECT *, hstore_get_value(other_tags, 'oneway') AS oneway FROM lines", quiet = TRUE ) colnames(its_extra) ``` -------------------------------- ### Get Default osmconf.ini Path Source: https://docs.ropensci.org/osmextract/reference/get_default_osmconf_ini.html Call this function to obtain the file path to the configuration file used by the package for converting OSM PBF files to GeoPackage format. ```r get_default_osmconf_ini() ``` ```r get_default_osmconf_ini() #> [1] "/usr/share/gdal/osmconf.ini" ``` -------------------------------- ### Spatial Filtering with Boundary Argument Source: https://docs.ropensci.org/osmextract/articles/osmextract.html Use the `boundary` argument in `oe_get` to perform spatial filtering during the vectortranslate process. This example filters data within a specified bounding box. ```R its_bbox = st_bbox( c(xmin = -1.559184 , ymin = 53.807739 , xmax = -1.557375 , ymax = 53.808094), crs = 4326 ) |> st_as_sfc() its_small = oe_get("ITS Leeds", boundary = its_bbox) #> The input place was matched with: ITS Leeds #> The chosen file was already detected in the download directory. Skip downloading. #> Starting with the vectortranslate operations on the input file! #> 0...10...20...30...40...50...60...70...80...90...100 - done. #> Finished the vectortranslate operations on the input file! #> Reading layer `lines' from data source `/tmp/Rtmp2tl7Wt/test_its-example.gpkg' using driver `GPKG' #> Simple feature collection with 5 features and 10 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -1.559731 ymin: 53.80676 xmax: -1.556762 ymax: 53.80945 #> Geodetic CRS: WGS 84 ``` -------------------------------- ### Update .osm.pbf Files in a Directory Source: https://docs.ropensci.org/osmextract/reference/oe_update.html Use this function to re-download all .osm.pbf files in a directory that were previously downloaded with oe_get(). It can optionally delete old .gpkg files to prevent synchronization issues. Set quiet = TRUE to suppress informative messages. ```R oe_update( download_directory = oe_download_directory(), quiet = FALSE, delete_gpkg = TRUE, max_file_size = 5e+08, ... ) ```