get_osm_data {greenR}R Documentation

Download OSM Data (Interactive Use Only)

Description

Downloads OpenStreetMap (OSM) data for a specified location or bounding box. Includes highways, green areas, and trees for the specified location.

Usage

get_osm_data(
  bbox,
  server_url = "https://nominatim.openstreetmap.org/search",
  username = NULL,
  password = NULL
)

Arguments

bbox

Either a string representing the location (e.g., "Lausanne, Switzerland") or a numeric vector of length 4 representing the bounding box coordinates in the order: c(left, bottom, right, top).

server_url

Optional string representing an alternative Nominatim server URL.

username

Optional string for username if authentication is required for the server.

password

Optional string for password if authentication is required for the server.

Details

Note: This function requires an internet connection and must be run interactively. It performs HTTP requests to external APIs (Nominatim and Overpass via osmdata). On CRAN and in non-interactive sessions, this function will error.

Value

A list containing:

highways

An sf object with the OSM data about highways in the specified location.

green_areas

A list with an sf object of green area polygons.

trees

An sf object with the OSM data about trees in the specified location.

Examples

## Not run: 
  # Using a location name
  osm_data <- get_osm_data("Lausanne, Switzerland")

  # Using coordinates for a bounding box
  bbox_coords <- c(6.6, 46.5, 6.7, 46.6)  # Example coordinates near Lausanne
  osm_data <- get_osm_data(bbox_coords)

## End(Not run)

[Package greenR version 0.0.1.3 Index]