### Install Development Version of osmextract Source: https://github.com/ropensci/osmextract/blob/master/README.md Installs the latest development version of the 'osmextract' package from GitHub. Requires the 'remotes' package. ```r # install.packages("remotes") remotes::install_github("ropensci/osmextract") ``` -------------------------------- ### Download England Cycleways with osmextract (efficiently) Source: https://github.com/ropensci/osmextract/blob/master/README.md This example shows how to download cycleways in England using the osmextract package. It is designed for large datasets and converts data to the efficient 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)) ``` -------------------------------- ### Program Copyright and License Notice Source: https://github.com/ropensci/osmextract/blob/master/LICENSE.md Include this notice at the start of each source file to state the copyright and license terms. It specifies redistribution rights under the GNU GPL version 3 or later. ```text Copyright (C) 2019 Robin Lovelace This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` -------------------------------- ### Install Released Version of osmextract Source: https://github.com/ropensci/osmextract/blob/master/README.md Installs the stable version of the 'osmextract' package from CRAN. ```r install.packages("osmextract") ``` -------------------------------- ### Interactive Mode Notice for Programs Source: https://github.com/ropensci/osmextract/blob/master/LICENSE.md Display this notice when a program starts in interactive mode to inform users about its free software status, warranty, and redistribution conditions. ```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 England Cycleways with osmdata (fails for large data) Source: https://github.com/ropensci/osmextract/blob/master/README.md This example demonstrates downloading cycleways in England using the osmdata package. It highlights a common issue where Overpass API queries for large datasets can time out. ```r library(osmdata) cycleways_england = opq("England") %>% add_osm_feature(key = "highway", value = "cycleway") %>% osmdata_sf() # Error in check_for_error(doc) : General overpass server error; returned: # The data included in this document is from www.openstreetmap.org. The data is available under ODbL. runtime error: Query timed out in "query" at line 4 after 26 seconds. ``` -------------------------------- ### Download OSM Data with Extra Tags for Andorra Source: https://github.com/ropensci/osmextract/blob/master/README.md Example of downloading OSM data for Andorra, requesting 'ref' as an extra tag. ```r andorra = oe_get("Andorra", extra_tags = "ref") ``` -------------------------------- ### Download OSM Data for Leeds Source: https://github.com/ropensci/osmextract/blob/master/README.md Example of downloading OSM data for Leeds. ```r leeds = oe_get("Leeds") ``` -------------------------------- ### Download OSM Data for Malta Source: https://github.com/ropensci/osmextract/blob/master/README.md Example of downloading OSM data for Malta using oe_get(). Uses quiet=TRUE to suppress messages. ```r malta = oe_get("Malta", quiet = TRUE) ``` -------------------------------- ### Geocode and Download OSM Data for Milan Source: https://github.com/ropensci/osmextract/blob/master/README.md Example of using oe_get() for a place name ('Milan') that may not have an exact match in providers, triggering geocoding via Nominatim API and downloading the smallest intersecting OSM extract. This may result in a large download. ```r oe_get("Milan") # Warning: It will download more than 400MB of data #> No exact match found for place = Milan and provider = geofabrik. Best match is Iran. #> Checking the other providers. #> No exact match found in any OSM provider data. Searching for the location online. #> ... (extra messages here) ``` -------------------------------- ### Check default download directory Source: https://github.com/ropensci/osmextract/blob/master/README.md Call this function to verify the current default download directory used by the osmextract package. ```r oe_download_directory() ``` -------------------------------- ### Load osmextract Package Source: https://github.com/ropensci/osmextract/blob/master/README.md Loads the 'osmextract' package into the R session. Includes a note about data licensing and package website. ```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. ``` -------------------------------- ### Load sf Package Source: https://github.com/ropensci/osmextract/blob/master/README.md Loads the 'sf' package, recommended for use with 'osmextract' for spatial data handling. Includes linking information for GEOS, GDAL, and PROJ. ```r library(sf) #> Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE ``` -------------------------------- ### Download and Import OSM Points Data Source: https://github.com/ropensci/osmextract/blob/master/README.md Downloads and imports 'points' layer data for 'Isle of Wight' as an sf object. Uses quiet=TRUE to suppress messages and stringsAsFactors=FALSE. ```r osm_points = oe_get("Isle of Wight", layer = "points", stringsAsFactors = FALSE, quiet = TRUE) ``` -------------------------------- ### Set Test Environment Variables with withr Source: https://github.com/ropensci/osmextract/blob/master/tests/testthat/README.md Use withr::local_envvar to temporarily set environment variables for testing. This ensures that the OSMEXT_DOWNLOAD_DIRECTORY is set to a temporary location and TESTTHAT is set to 'true' to prevent interactive prompts from oe_clean(). ```r withr::local_envvar( .new = list( "OSMEXT_DOWNLOAD_DIRECTORY" = tempdir(), "TESTTHAT" = "true" ) ) ``` -------------------------------- ### Download and Import OSM Lines Data Source: https://github.com/ropensci/osmextract/blob/master/README.md Downloads and imports 'lines' layer data for 'Isle of Wight' as an sf object. Uses quiet=TRUE to suppress messages and stringsAsFactors=FALSE. ```r osm_lines = oe_get("Isle of Wight", stringsAsFactors = FALSE, quiet = TRUE) ``` -------------------------------- ### Edit .Renviron file Source: https://github.com/ropensci/osmextract/blob/master/README.md Use this function to open your .Renviron file and add a line to specify a custom download directory for OSM extracts. ```r usethis::edit_r_environ() # Add a line containing: OSMEXT_DOWNLOAD_DIRECTORY=/path/where/to/save/files ``` -------------------------------- ### Download OSM Lines with Custom SQL Query Source: https://github.com/ropensci/osmextract/blob/master/README.md Downloads OSM 'lines' data for Goa, filtering for 'highway' and 'geometry' columns using a custom SQL query. ```r goa = oe_get("Goa", query = "SELECT highway, geometry FROM 'lines'") ``` -------------------------------- ### Plot OSM Lines and Points Geometries Source: https://github.com/ropensci/osmextract/blob/master/README.md Plots the geometries of the downloaded 'lines' and 'points' data for 'Isle of Wight'. Sets margins to zero for a clean plot. ```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)) ``` -------------------------------- ### Inspect Column Names of OSM Lines Data Source: https://github.com/ropensci/osmextract/blob/master/README.md Displays the names of the columns in the 'osm_lines' sf object, showing the default variable names extracted from OSM data. ```r names(osm_lines) # default variable names #> [1] "osm_id" "name" "highway" "waterway" "aerialway" #> [6] "barrier" "man_made" "railway" "z_order" "other_tags" #> [11] "geometry" ``` -------------------------------- ### Plot Major, Secondary, and Tertiary Roads Source: https://github.com/ropensci/osmextract/blob/master/README.md Filters the 'osm_lines' data to include only major, secondary, and tertiary roads, then plots these roads, highlighting the 'highway' type. ```r ht = c("primary", "secondary", "tertiary", "unclassified") # highway types of interest osm_major_roads = osm_lines[osm_lines$highway %in% ht, ] plot(osm_major_roads["highway"], key.pos = 1) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.