ohsome_parse {ohsome}R Documentation

Parse content from an ohsome API response

Description

Extracts and parses the content from an ohsome API response

Usage

ohsome_parse(
  response,
  returnclass = c("default", "sf", "data.frame", "list", "character"),
  omit_empty = TRUE
)

ohsome_sf(response, omit_empty = TRUE)

ohsome_df(response, omit_empty = TRUE)

Arguments

response

An ohsome_response object

returnclass

character; one of the following:

  • "default" returns sf if the ohsome_response contains GeoJSON, or else a data.frame.

  • "sf" returns sf if the ohsome_response contains GeoJSON, else issues a warning and returns a data.frame.

  • "data.frame" returns a data.frame.

  • "list" returns a list.

  • "character" returns the ohsome API response body as text (JSON or semicolon-separated values)

omit_empty

logical; omit features with empty geometries (only if returnclass = "sf")

Details

ohsome_parse() parses an ohsome_response object into an object of the specified class. By default, this is an sf object if the ohsome API response contains GeoJSON data or a data.frame if it does not. ohsome_sf() and ohsome_df() wrapper functions for specific return classes.

Value

An sf object, a data.frame, a list or a character

Examples

## Not run: 
# Create and send a query to ohsome API
r <- ohsome_query("elements/centroid", filter = "amenity=*") |>
    set_boundary(osmdata::getbb("Heidelberg")) |>
    set_time("2021") |>
    set_properties("metadata") |>
    ohsome_post(parse = FALSE)

# Parse response to object of default class (here: sf)
ohsome_parse(r)

# Parse response to data.frame
ohsome_df(r)

# Parse response to sf
ohsome_sf(r)

## End(Not run)


[Package ohsome version 0.2.2 Index]