get_location: Get location of a specified type based on name, id, or...

View source: R/get_location.R

get_locationR Documentation

Get location of a specified type based on name, id, or location

Description

Filter by name or id or use a spatial filter based on an sf object or geocoded street address. Optionally you can use an index list to match the type to a named list of URLs or sf objects.

Usage

get_location(
  type,
  name = NULL,
  name_col = "name",
  id = NULL,
  id_col = "id",
  location = NULL,
  index = NULL,
  union = FALSE,
  crs = getOption("overedge.crs"),
  label = NULL,
  class = "sf",
  ...
)

Arguments

type

Type of location to return. Type can be an sf object, e.g. a data frame with multiple neighborhoods or a character string that can be passed to get_location_data. If index is provided, character can also be a character string to match the name of a list.

name

Location name to return.

name_col

Column name in type with name values, Default: 'name' Required if name provided.

id

Location id to return. id is coerced to character or numeric to match the class of the id_col for type.

id_col

Column name in type with id values, Default: 'id'. Required if id is provided.

location

An address, bounding box (bbox), or simple feature (sf) object passed to sf::st_filter. Any valid address or addresses are geocoded with tidygeocoder::geo, converted to a simple feature object, and then used as a spatial filter. bbox objects are converted using sf_bbox_to_sf(). Multiple addresses are supported.

index

Optional list used to match type to data, Default: NULL

union

If TRUE, the location geometry is unioned with sf::st_union and the names are combined into a single value. Default: FALSE.

crs

Coordinate reference system to return; defaults to NULL which returns data using the same coordinate reference system as the provided type of location.

label

Label optionally added to "label" column; must be a length 1 or match the number of rows returned based on the other parameters. If union = TRUE, using label is recommended. Default: NULL

class

Class of object to return; defaults to "sf".

...

Additional parameters passed to get_location_data if type is character and index is NULL.

Value

A simple feature object from data provided to type.

Examples

nc <- read_sf_path(system.file("shape/nc.shp", package = "sf"))

# get_location works with a type sf object and name and id values
get_location(type = nc, name = "Warren", name_col = "NAME")
get_location(type = nc, id = 37185, id_col = "FIPSNO")

# type can also be a file path
get_location(
  type = system.file("shape/nc.shp", package = "sf"),
  name = "Hertford",
  name_col = "NAME"
)

# type can also be an index name (if a named list of data sets, url values, or
# path values is passed to index)
get_location(
  type = "smaller",
  name = "Hertford",
  name_col = "NAME",
  index = list(
    "smaller" = dplyr::filter(nc, AREA <= 0.10),
    "larger" = dplyr::filter(nc, AREA > 0.15)
  )
)

elipousson/overedge documentation built on Aug. 13, 2022, 7:41 p.m.