get_location_data: Get data for a location

View source: R/get_location_data.R

get_location_dataR Documentation

Get data for a location

Description

Returns data for a selected location or a list of locations (for map_location_data). If data is a character string, the parameter is passed to read_sf_url, read_sf_path, or read_sf_pkg. This function uses location_filter() to filter (using sf::st_intersects), crop, or trim data to the provided location. location can also be an an address, county GeoID, state name, abbreviation, or GeoID.

Usage

get_location_data(
  location = NULL,
  dist = getOption("overedge.dist"),
  diag_ratio = getOption("overedge.diag_ratio"),
  unit = getOption("overedge.unit", default = "meter"),
  asp = getOption("overedge.asp"),
  data = NULL,
  package = getOption("overedge.data_package"),
  filetype = getOption("overedge.data_filetype", default = "gpkg"),
  fn = NULL,
  crop = TRUE,
  trim = FALSE,
  from_crs = getOption("overedge.from_crs"),
  crs = getOption("overedge.crs"),
  class = "sf",
  label = NULL,
  index = NULL,
  col = NULL,
  ...
)

map_location_data(
  location = NULL,
  dist = NULL,
  diag_ratio = NULL,
  unit = NULL,
  asp = NULL,
  data = NULL,
  package = NULL,
  filetype = "gpkg",
  fn = NULL,
  crop = TRUE,
  trim = FALSE,
  from_crs = NULL,
  crs = NULL,
  class = "list",
  label = NULL,
  load = FALSE,
  index = NULL,
  ...
)

Arguments

location

sf object. If multiple areas are provided, they are unioned into a single sf object using sf::st_union

dist

buffer distance in units. Optional.

diag_ratio

ratio of diagonal distance of area's bounding box used as buffer distance. e.g. if the diagonal distance is 3000 meters and the "diag_ratio = 0.1" a 300 meter will be used. Ignored when dist is provided.

unit

Units for buffer. Supported options include "meter", "foot", "kilometer", and "mile", "nautical mile" Common abbreviations (e.g. "km" instead of "kilometer") are also supported. Distance in units is converted to units matching GDAL units for x; defaults to "meter"

asp

Aspect ratio of width to height as a numeric value (e.g. 0.33) or character (e.g. "1:3"). If numeric, get_asp() returns the same value without modification.

data

Character string (e.g. url, file path, or name of data from package), a sf, sfc, or bbox object including data in area.

package

Name of the package to search for data.

filetype

File type to use if passing parameters to read_sf_download or read_sf_pkg (required for extdata and cached data).

fn

Function to apply to data after filtering by location but before returning from function.

crop

If TRUE, data is cropped to location or bounding box sf::st_crop adjusted by the dist, diag_ratio, and asp parameters provided. Default TRUE.

trim

If TRUE, data is trimmed to area with sf::st_intersection. This option ignores any dist, diag_ratio, or asp parameters. Default FALSE.

from_crs

Coordinate reference system used to match the location CRS to the source data.

crs

Coordinate reference system to return.

class

Class of object to return.

label

label is optionally used by map_location_data to name the data objects in the list returned by the function.

index

A list of possible location, data, and (optionally) package values. List must be named and include a value named package and package must be NULL, to set package based on index. If list is not NULL and location and/or data as character or numeric values, the location and data are assumed to be index values for the index list. The index parameter supports nested lists created by make_location_data_list (using only the default key names of "location" and "data"). This feature has not be fully tested and may result in errors or unexpected results.

...

additional parameters passed to read_sf_path, read_sf_url, or read_sf_pkg and location_filter

load

If TRUE and class is "list", load data to local environment; defaults FALSE.

Details

Working with sf lists for data and locations:

map_location_data makes it easier to work with sf lists. It supports data as a character vector, data as an sf list when location is a single object, location as a character vector or sf list (including lists of bbox or sfc objects), or when both data and location are lists (such as a list created by make_location_data_list).

Examples

map_location_data(
  data = c("streets", "mta_bus_lines"),
  package = "mapbaltimore",
  location = get_location(
    type = "council_districts",
    id = 1,
    package = "mapbaltimore"),
  load = TRUE
)

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