Title: | Get Easy Access to Tabular and Spatial Data |
---|---|
Description: | Download and format spatial and non-spatial data with simple filtering by location. |
Authors: | Eli Pousson [aut, cre, cph] |
Maintainer: | Eli Pousson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1.9000 |
Built: | 2024-10-29 02:22:26 UTC |
Source: | https://github.com/elipousson/getdata |
Use lubridate::as_date()
to convert an object to a length 2 list with a
minimum and maximum date. By default the dates in the list will be named
named "start" and "end". date_range_query()
is a variation that returns a
query string that can be passed to the "where" parameter of
get_esri_data()
. between_date_range()
works the same way identical but
uses the BETWEEN DATE syntax. check_date_range()
validates whether a date
or date range falls within supplied limits.
as_date_range( x = NULL, year = NULL, days = 90, ..., start_date = NULL, end_date = NULL, limits = NULL, nm = c("start", "end"), call = caller_env() ) date_range_query(x = NULL, .col = "date", ..., nm = c("start", "end")) between_date_range(x = NULL, .col = "date", ..., nm = c("start", "end")) check_date_range( x = NULL, ..., limits = NULL, nm = c("start", "end"), call = caller_env() )
as_date_range( x = NULL, year = NULL, days = 90, ..., start_date = NULL, end_date = NULL, limits = NULL, nm = c("start", "end"), call = caller_env() ) date_range_query(x = NULL, .col = "date", ..., nm = c("start", "end")) between_date_range(x = NULL, .col = "date", ..., nm = c("start", "end")) check_date_range( x = NULL, ..., limits = NULL, nm = c("start", "end"), call = caller_env() )
x |
Date range as character vector in format of |
year |
If date_range is |
days |
Default range duration in days to use if date_range is length 1. |
... |
Arguments passed on to |
start_date , end_date
|
Start and end date used if year and date_range are
both |
limits |
Optional range of allowed dates. If dates supplied to
|
nm |
Names to use for returned date range list. Defaults to |
call |
The execution environment of a currently
running function, e.g. |
.col |
Name of date column to use for query. Defaults to "date". |
A length 2 list with min and max Date values.
as_date_range("2022-01-01", days = 10) as_date_range(c("2022-01-01", "2022-01-31")) as_date_range(year = 2022) date_range_query(c("2022-01-01", "2022-01-31")) # check_date_range("2022-09-01", limits = c("2022-07-01", "2022-09-30"))
as_date_range("2022-01-01", days = 10) as_date_range(c("2022-01-01", "2022-01-31")) as_date_range(year = 2022) date_range_query(c("2022-01-01", "2022-01-31")) # check_date_range("2022-09-01", limits = c("2022-07-01", "2022-09-30"))
sf::write_sf()
or readr::write_rds()
cache_location_data()
is a variant on get_location_data()
that saves the
returned data to a cache directory using sf::write_sf()
(if data is a sf
object) or readr::write_rds()
(if data is another class). Additional
parameters are ignored if location is NULL
.
cache_location_data( data = NULL, ..., location = NULL, name = NULL, label = NULL, fileext = "gpkg", filename = NULL, path = NULL, prefix = NULL, postfix = NULL, cache = TRUE, pkg = "getdata", create = TRUE, overwrite = FALSE, compress = c("none", "gz", "bz2", "xz"), version = 3, call = caller_env() )
cache_location_data( data = NULL, ..., location = NULL, name = NULL, label = NULL, fileext = "gpkg", filename = NULL, path = NULL, prefix = NULL, postfix = NULL, cache = TRUE, pkg = "getdata", create = TRUE, overwrite = FALSE, compress = c("none", "gz", "bz2", "xz"), version = 3, call = caller_env() )
data |
Character string (e.g. url, file path, or name of data from
package) for a spatial data or a |
... |
Arguments passed on to
|
location |
sf object. If multiple areas are provided, they are unioned
into a single sf object using |
name |
Name to make file name converted to snake case with
|
label |
Label to combine with name converted to snake case with
|
fileext |
File type or extension. Optional if filename or path include a file extension. |
filename |
File name; if filename is |
path |
Path to file or data directory. Optional. If path includes a file
extension and filename and fileext are both |
prefix |
File name prefix. "date" adds a date prefix, "time" adds a
date/time prefix; defaults to |
postfix |
File name postfix; defaults to |
cache |
If |
pkg |
Package name passed to appname parameter of
|
create |
If |
overwrite |
If |
compress |
Compression method to use: "none", "gz" ,"bz", or "xz". |
version |
Serialization format version to be used. The default value is 2
as it's compatible for R versions prior to 3.5.0. See |
call |
The execution environment of a currently
running function, e.g. |
Save data to file and invisibly return file path.
getdata has two helpers for working with address data:
bind_address_col()
bind a provided value for city, county, and state to a
data frame (to supplement address data with consistent values for these
variables). This function is useful for converting partial street addresses
with a consistent values for state, county, or city into full addresses
bind_block_col()
requires a data frame with columns named "bldg_num",
"street_dir_prefix", "street_name", and "street_type" and binds derived
values for whether a building is on the even or odd side of a block and
create a block segment and a block face (including the even/odd identifier).
bind_block_col( x, bldg_num = "bldg_num", street_dir_prefix = "street_dir_prefix", street_name = "street_name", street_suffix = "street_type", replace_suffix = FALSE, street_col = NULL, block_col = NULL, .after = street_suffix, case = NULL ) bind_address_col(x, ..., case = NULL, .cols = NULL, .after = NULL) bind_location_text_col( x, text_col = "text", address_pattern = c("Ave.", "Avenue", "St.", "Street", "Rd.", "Road"), block_face_pattern = c("sides\\)", "side\\)", "[:space:]block", "-block", "blocks"), street_corridor_pattern = c("between(?=.+and)", "from(?=.+to)"), .cols = NULL )
bind_block_col( x, bldg_num = "bldg_num", street_dir_prefix = "street_dir_prefix", street_name = "street_name", street_suffix = "street_type", replace_suffix = FALSE, street_col = NULL, block_col = NULL, .after = street_suffix, case = NULL ) bind_address_col(x, ..., case = NULL, .cols = NULL, .after = NULL) bind_location_text_col( x, text_col = "text", address_pattern = c("Ave.", "Avenue", "St.", "Street", "Rd.", "Road"), block_face_pattern = c("sides\\)", "side\\)", "[:space:]block", "-block", "blocks"), street_corridor_pattern = c("between(?=.+and)", "from(?=.+to)"), .cols = NULL )
x |
A data.frame with a column name matching col and no column names matching the list passed to .cols (or the default values listed below). |
bldg_num , street_dir_prefix , street_name , street_suffix
|
Column names to use for address information required to generate a block name and number. |
replace_suffix |
If |
street_col |
String to use for street address column added based on component column values. |
block_col |
String to use as prefix for block identifier columns and
separator between block number and street. Set to "block" when |
.after |
passed to |
case |
Case to use for text in new columns or in modified values.
Options include "lower", "upper", "title", or "sentence". Defaults to
|
... |
Additional parameters passed to |
.cols |
Column names to add. Defaults to is_address, is_block_face, is_street_corridor, and block_side. x must not have any column names matching the names found in .cols. |
text_col |
Column name containing the information to check for location details, Default: 'text' |
address_pattern |
A character vector of regex patterns to return |
block_face_pattern |
A character vector of regex patterns to return
|
street_corridor_pattern |
A character vector of regex patterns to return
|
A data.frame with new indicator columns for address and block_face and a column indicating whether the text references a particular cardinal direction in describing a block.
address_df <- data.frame( "bldg_num" = c("100", "1415", "600"), "street_dir_prefix" = c(NA, NA, "N"), "street_name" = c("Holiday", "Key", "Charles"), "street_type" = c("Street", "Highway", "St") ) address_df <- bind_block_col( x = address_df, street_col = "street_address" ) address_df[1,] address_df <- bind_address_col( address_df, city = "Baltimore", state = "MD" ) address_df[2,] location_df <- data.frame( "text" = c( "100 Holiday St.", "1400 block Key Highway (north side)", "Charles St. from E. Centre St. to E. Madison St." ) ) location_df <- bind_location_text_col(location_df) location_df
address_df <- data.frame( "bldg_num" = c("100", "1415", "600"), "street_dir_prefix" = c(NA, NA, "N"), "street_name" = c("Holiday", "Key", "Charles"), "street_type" = c("Street", "Highway", "St") ) address_df <- bind_block_col( x = address_df, street_col = "street_address" ) address_df[1,] address_df <- bind_address_col( address_df, city = "Baltimore", state = "MD" ) address_df[2,] location_df <- data.frame( "text" = c( "100 Holiday St.", "1400 block Key Highway (north side)", "Charles St. from E. Centre St. to E. Madison St." ) ) location_df <- bind_location_text_col(location_df) location_df
This function can apply the following common data cleaning tasks:
Applies stringr::str_squish and stringr::str_trim to all character columns
Optionally replaces all character values of "" with NA
values
Optionally corrects UNIX formatted dates with 1970-01-01 origins
Optionally renames variables by passing a named list of variables
The address functions previously included with format_data()
are now
documented at format_address_data()
.
format_data( x, var_names = NULL, xwalk = NULL, clean_names = TRUE, .name_repair = "check_unique", replace_na_with = NULL, replace_with_na = NULL, replace_empty_char_with_na = FALSE, fix_date = FALSE, label = FALSE, remove_empty = NULL, remove_constant = FALSE, format_sf = FALSE, ..., call = caller_env() ) rename_with_xwalk( x, xwalk = NULL, cols = c("label", "name"), label = FALSE, .strict = TRUE, keep_all = TRUE, arg = caller_arg(x), call = caller_env() ) label_with_xwalk(x, xwalk = NULL, label = "var", ...) make_variable_dictionary( x, .labels = NULL, .definitions = NULL, details = c("basic", "none", "full") ) fix_epoch_date(x, .cols = dplyr::contains("date"), tz = "")
format_data( x, var_names = NULL, xwalk = NULL, clean_names = TRUE, .name_repair = "check_unique", replace_na_with = NULL, replace_with_na = NULL, replace_empty_char_with_na = FALSE, fix_date = FALSE, label = FALSE, remove_empty = NULL, remove_constant = FALSE, format_sf = FALSE, ..., call = caller_env() ) rename_with_xwalk( x, xwalk = NULL, cols = c("label", "name"), label = FALSE, .strict = TRUE, keep_all = TRUE, arg = caller_arg(x), call = caller_env() ) label_with_xwalk(x, xwalk = NULL, label = "var", ...) make_variable_dictionary( x, .labels = NULL, .definitions = NULL, details = c("basic", "none", "full") ) fix_epoch_date(x, .cols = dplyr::contains("date"), tz = "")
x |
A tibble or data frame object |
var_names |
A named list following the format, |
xwalk |
A data frame with two columns using the first column as name and the second column as value; or a named list. The existing names of x must be the values and the new names must be the names. |
clean_names |
If |
.name_repair |
Defaults to "check_unique" |
replace_na_with |
A named list to pass to |
replace_with_na |
A named list to pass to |
replace_empty_char_with_na |
If |
fix_date |
If |
label |
For |
remove_empty |
If not |
remove_constant |
If |
format_sf |
If |
... |
Additional parameters passed to |
cols |
Column names to use for crosswalk. |
.strict |
If |
keep_all |
If |
arg , call
|
Additional parameters used internally with |
.labels |
Replaces labels column created by
|
.definitions |
Character vector of definitions appended to dictionary data frame. Must be in the same order as the variables in the provided data frame x. |
details |
add details about each variable (full details could be time
consuming for big data frames, |
.cols |
tidyselect for columns to apply epoch date fixing function to.
Defaults to |
tz |
Time zone passed to |
The input data frame or simple feature object with formatting functions applied.
nc <- get_location_data(data = system.file("shape/nc.shp", package = "sf")) format_data(nc)
nc <- get_location_data(data = system.file("shape/nc.shp", package = "sf")) format_data(nc)
The main format_sf_data function is a wrapper for the following common
steps in transforming an sf
object and preparing for mapping or analysis:
format_sf_data( x, crs = getOption("getdata.crs", default = 3857), erase_data = NULL, dTolerance = NULL, smooth = FALSE, sf_col = NULL, sf_req = TRUE, ... ) erase_data(x, erase_data = NULL)
format_sf_data( x, crs = getOption("getdata.crs", default = 3857), erase_data = NULL, dTolerance = NULL, smooth = FALSE, sf_col = NULL, sf_req = TRUE, ... ) erase_data(x, erase_data = NULL)
x |
A |
crs |
Coordinate reference system for returned data, Default: getOption("getdata.crs", default = 3857) |
erase_data |
A |
dTolerance |
numeric; tolerance parameter, specified for all or for each
feature geometry. If you run |
smooth |
If |
sf_col |
Name to use for output |
sf_req |
If |
... |
Additional parameters passed to |
Convert data to an sf
object with sfext::as_sf if sf_req
is FALSE
Make data valid with sf::st_make_valid if needed
Format data with format_data using the ... parameters
Erase any data overlapping with erase_data
(suggested for use with water or open space)
Simplify geometry with sf::st_simplify if dTolerance
is provided
Smooth geometry with smoothr::smooth if smooth
is TRUE
Rename the sf column to match sf_col
(defaults to "geometry")
The helper functions for format_sf_data and additional formatting functions
for sf
data are described in the details.
Helper functions for format_sf_data:
erase_data: erase intersection of x and erase_data (validity of erase_data checked before sfext::st_erase and for x after completing the operation.
rename_sf_col: Rename sf
column.
relocate_sf_col: Relocate sf
column after selected columns (defaults to
dplyr::everything()
).
A sf
object with columns and geometry modified based parameters.
library(sf) nc <- read_sf(system.file("shape/nc.shp", package = "sf")) nc_county <- nc[2,] # Transform coordinate reference system st_crs(nc)$epsg st_crs(format_sf_data(nc, crs = 3857))$epsg # Simplify and smooth geometry plot(nc_county, max.plot = 1) nc_county_simple <- format_sf_data(nc_county, dTolerance = 5000, smooth = TRUE) plot(nc_county_simple, max.plot = 1) # Erase data nc_co_water <- get_tigris_data(type = "area water", state = "NC", county = nc_county$NAME) nc_county_erased <- format_sf_data(nc_county, erase_data = nc_co_water) plot(nc_county_erased, max.plot = 1) # If sf_req is set to FALSE, use any object that can be converted with sfext::as_sf nc_bbox <- st_bbox(nc) plot(format_sf_data(nc_bbox, erase_data = nc_county_simple, sf_req = FALSE))
library(sf) nc <- read_sf(system.file("shape/nc.shp", package = "sf")) nc_county <- nc[2,] # Transform coordinate reference system st_crs(nc)$epsg st_crs(format_sf_data(nc, crs = 3857))$epsg # Simplify and smooth geometry plot(nc_county, max.plot = 1) nc_county_simple <- format_sf_data(nc_county, dTolerance = 5000, smooth = TRUE) plot(nc_county_simple, max.plot = 1) # Erase data nc_co_water <- get_tigris_data(type = "area water", state = "NC", county = nc_county$NAME) nc_county_erased <- format_sf_data(nc_county, erase_data = nc_co_water) plot(nc_county_erased, max.plot = 1) # If sf_req is set to FALSE, use any object that can be converted with sfext::as_sf nc_bbox <- st_bbox(nc) plot(format_sf_data(nc_bbox, erase_data = nc_county_simple, sf_req = FALSE))
Get data from an Airtable base using the Airtable API, a development version
of the rairtable package,
and the httr2 package. If the base includes coordinate fields/columns,
optionally convert the data to a simple feature object using
sfext::df_to_sf()
if geometry = TRUE
.
get_airtable_data( base, table = NULL, view = NULL, record = deprecated(), fields = NULL, filter = NULL, sort = NULL, direction = "asc", desc = deprecated(), max_records = 100, per_page = NULL, cell_format = "json", tz = NULL, locale = NULL, fields_by_id = FALSE, offset = NULL, geometry = FALSE, location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", "meter"), asp = getOption("getdata.asp"), crs = getOption("getdata.crs", 3857), coords = getOption("getdata.coords", c("lon", "lat")), from_crs = getOption("getdata.from_crs", 4326), remove_coords = TRUE, address = getOption("getdata.address", "address"), geo = FALSE, name_repair = janitor::make_clean_names, token = NULL, type = "AIRTABLE_TOKEN", resp_type = deprecated(), ... ) get_airtable_metadata( base, table = NULL, token = NULL, type = "AIRTABLE_TOKEN", resp_type = "tables", fields = FALSE )
get_airtable_data( base, table = NULL, view = NULL, record = deprecated(), fields = NULL, filter = NULL, sort = NULL, direction = "asc", desc = deprecated(), max_records = 100, per_page = NULL, cell_format = "json", tz = NULL, locale = NULL, fields_by_id = FALSE, offset = NULL, geometry = FALSE, location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", "meter"), asp = getOption("getdata.asp"), crs = getOption("getdata.crs", 3857), coords = getOption("getdata.coords", c("lon", "lat")), from_crs = getOption("getdata.from_crs", 4326), remove_coords = TRUE, address = getOption("getdata.address", "address"), geo = FALSE, name_repair = janitor::make_clean_names, token = NULL, type = "AIRTABLE_TOKEN", resp_type = deprecated(), ... ) get_airtable_metadata( base, table = NULL, token = NULL, type = "AIRTABLE_TOKEN", resp_type = "tables", fields = FALSE )
base |
Airtable base id starting with with "app". Optional if url or airtable are supplied. If base is an Airtable url, the table and view are replaced based on the values parsed from the url. Required. |
table |
Airtable table id or name. If table is a table ID it is a string starting with "viw". Optional only if base is a url. |
view |
Airtable view ID. View ID values starts with "viw". Optional if
require_view is |
record |
Airtable record identifier, Default: |
fields |
For |
filter |
Placeholder for filterByFormula API parameter allowing use of SQL style queries to filter data. Not yet implemented. |
sort |
Field names to sort by. Defaults to |
direction |
A string ("asc" for ascending (default) or "desc" for
descending) or character vector matching length of sort parameter. Ignored
if sort is |
desc |
Deprecated. Sort results in descending order. Replaced by direction parameter. |
max_records |
Maximum number of records to return. Must be 100 or less. |
per_page |
Passed to page_size parameter of
|
cell_format |
Cell format for "Link to another record" fields. Defaults to "json" which returns a unique record ID. A "string" cell_format returns the displayed character string. |
tz , locale
|
Time zone and locale, Defaults to |
fields_by_id |
If |
offset |
Offset parameter, Default: |
geometry |
If |
location |
sf object. If multiple areas are provided, they are unioned
into a single sf object using |
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 |
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, |
crs |
Cordinate reference system to return, Default: 4326 for
|
coords |
Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat"). |
from_crs |
For |
remove_coords |
For |
address |
Address column name passed to |
geo |
If |
name_repair |
One of "unique" (default), "universal", "check_unique",
"unique_quiet", or "universal_quiet" passed to |
token , type
|
API token and type, token defaults to |
resp_type |
Response type to return, Reprecated. Previously, set resp_type to "resp" to return the API response without any additional formatting or conversion. |
... |
Arguments passed on to
|
This function an Airtable personal access token which you can create at
https://airtable.com/create/tokens and save to your local environment with
set_access_token(token = <YOUR_PERSONAL_ACCESS_TOKEN>, type = "AIRTABLE_TOKEN")
. The function previously required an Airtable API key
which you can set using set_access_token(token = <YOUR_API_KEY>, type = "AIRTABLE_API_KEY")
. However, Airtable is in the process of deprecating user
API keys.
get_airtable_data()
requires a scope that includes data.records:read
and
get_airtable_metadata()
a scope including schema.bases:read
.
As of May 2023, this function depends on the dev branch of my fork of the rairtable package. I expect this dependency to switch back to the rairtable package when the fork is merged.
Learn more about the Airtable API https://airtable.com/developers/web/api/introduction
elevatr::get_elev_point
to get the elevation along a profile
get_elev_profile()
is a wrapper for elevatr::get_elev_point()
that takes
a LINESTRING or POINT input for profile and returns a data frame of
elevation. Optionally, create a series of points along a line with
sf::st_line_sample()
and/or include a column with the distance between each
successive POINT in the data frame.
get_elev_profile( profile, units = NULL, dist = FALSE, n = NULL, density = NULL, type = "regular", sample = NULL, ..., drop_units = FALSE, cumulative = FALSE )
get_elev_profile( profile, units = NULL, dist = FALSE, n = NULL, density = NULL, type = "regular", sample = NULL, ..., drop_units = FALSE, cumulative = FALSE )
profile |
A |
units |
If |
dist |
If |
n |
integer; number of points to choose per geometry; if missing, n will be computed as |
density |
numeric; density (points per distance unit) of the sampling, possibly a vector of length equal to the number of features (otherwise recycled); |
type |
character; indicate the sampling type, either "regular" or "random" |
sample |
numeric; a vector of numbers between 0 and 1 indicating the points to sample - if defined sample overrules n, density and type. |
... |
Unused at this time. |
drop_units |
If |
cumulative |
If |
This function is proposed for addition to {elevatr}
:
https://github.com/elipousson/getdata/issues/4
Wraps the esri2sf::esri2sf()
and esri2sf::esri2df()
functions to download
an ArcGIS FeatureServer or MapServer. Supports spatial filtering with
bounding box based on location and filtering by location name (if location
name column is provided). As of fall 2022, this package suggests the
elipousson/esri2sf fork using
httr2.
get_esri_data( url, location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit"), asp = getOption("getdata.asp"), crs = getOption("getdata.crs", 3857), where = NULL, name = NULL, name_col = NULL, coords = NULL, from_crs = getOption("getdata.crs", 4326), clean_names = TRUE, token = NULL, progress = TRUE, quiet = FALSE, .name_repair = janitor::make_clean_names, ..., call = caller_env() ) get_esri_layers( location = NULL, layers = NULL, url = NULL, nm = NULL, token = NULL, clean_names = TRUE, quiet = FALSE, .name_repair = janitor::make_clean_names, ..., call = caller_env() ) get_esri_metadata( url, token = NULL, meta = NULL, clean_names = TRUE, .name_repair = janitor::make_clean_names, call = caller_env() )
get_esri_data( url, location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit"), asp = getOption("getdata.asp"), crs = getOption("getdata.crs", 3857), where = NULL, name = NULL, name_col = NULL, coords = NULL, from_crs = getOption("getdata.crs", 4326), clean_names = TRUE, token = NULL, progress = TRUE, quiet = FALSE, .name_repair = janitor::make_clean_names, ..., call = caller_env() ) get_esri_layers( location = NULL, layers = NULL, url = NULL, nm = NULL, token = NULL, clean_names = TRUE, quiet = FALSE, .name_repair = janitor::make_clean_names, ..., call = caller_env() ) get_esri_metadata( url, token = NULL, meta = NULL, clean_names = TRUE, .name_repair = janitor::make_clean_names, call = caller_env() )
url |
FeatureServer or MapServer url to retrieve data from. Passed to
|
location |
|
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 |
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, |
crs |
Cordinate reference system to return, Default: 4326 for
|
where |
where query string passed to esri2sf, Default: |
name , name_col
|
Name value and name column found in the ArcGIS FeatureServer or MapServer data. |
coords |
Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat"). |
from_crs |
For |
clean_names |
If |
token |
string for authentication token. defaults to |
progress |
Show progress bar from |
quiet |
If |
.name_repair |
Passed to |
... |
Arguments passed on to
|
call |
The execution environment of a currently
running function, e.g. |
layers |
Either a vector with URLs, a named list of urls, or a numeric
vector; defaults to |
nm |
Name or vector of names to add to the layers; defaults to |
meta |
Name of metadata list value to return from esri2sf::esrimeta,
e.g. "name" to return layer name. Defaults to |
get_flickr_photos()
uses FlickrAPI::get_photo_search()
to get a data
frame or sf objects with photos from a specified location or matching other
photo search parameters. Set API key using FlickrAPI::set_flickr_api_key()
or pass to the api_key parameter.
get_flickr_photos( location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, user_id = NULL, tags = NULL, license_id = "cc0", sort = "date-posted", desc = FALSE, img_size = "s", extras = c("description", "date_taken", "tags", "geo"), per_page = 100, page = 1, orientation = NULL, geometry = TRUE, crs = 4326, key = NULL )
get_flickr_photos( location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, user_id = NULL, tags = NULL, license_id = "cc0", sort = "date-posted", desc = FALSE, img_size = "s", extras = c("description", "date_taken", "tags", "geo"), per_page = 100, page = 1, orientation = NULL, geometry = TRUE, crs = 4326, key = NULL )
location |
A |
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 |
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, |
user_id |
The NSID of the user with photos to search. If this parameter is NULL passed then all public photos will be searched. |
tags |
A vector of tags to search for. |
license_id |
The license id for photos. For possible values see the Flickr API method flickr.photos.licenses.getInfo or see details for more information. |
sort |
Supported options include "date-posted","date-taken", "interestingness", or "relevance" |
desc |
If |
img_size |
Image size; defaults to "s" (small). Options ranging from smallest to largest size include "sq" (square), "t", "s", "q", "m", "n", "z", "c", "l", and "o" (original). |
extras |
Defaults to "description", "date_taken", "tags", and "geo". |
per_page |
Photos to return per page of search results, Default: 100. Maximum 250 if a location is provided or 500 otherwise. |
page |
Page to return. If page is greater than length 1, loop over all pages. This may cause issues with API access if a large page range is provided. Default: 1 |
orientation |
If img_size is length 1, photos are filtered to one or
more of the supported orientations ("portrait", "landscape", and "square");
defaults to |
geometry |
If |
crs |
Coordinate reference system of |
key |
Flickr API key. If api_key is |
License id options:
license_id can be an integer from 0 to 10 or a corresponding license code including:
"c" (All Rights Reserved),
"by-bc-sa" (Attribution-NonCommercial-ShareAlike),
"by-nc" (Attribution-NonCommercial),
"by-nc-nd" (Attribution-NonCommercial-NoDerivs),
"by" (Attribution),
"by-sa" (Attribution-ShareAlike),
"by-nd" (Attribution-NoDerivs),
"nkc" (No known copyright restrictions),
"pd-us" (United States Government Work),
"cc0" (Public Domain Dedication),
or "pd" (Public Domain Mark).
A data frame with photo information or sf
object with geometry
based on latitude and longitude of geocoded photos.
Use googlesheets4 to get a data frame or simple feature data from a Google Sheet
get_gsheet_data( url, sheet = NULL, ss = NULL, ask = FALSE, geometry = FALSE, location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", "meter"), asp = getOption("getdata.asp"), coords = getOption("getdata.coords", c("lon", "lat")), remove_coords = TRUE, address = getOption("getdata.address", "address"), geo = FALSE, from_crs = 4326, clean_names = TRUE, ... )
get_gsheet_data( url, sheet = NULL, ss = NULL, ask = FALSE, geometry = FALSE, location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", "meter"), asp = getOption("getdata.asp"), coords = getOption("getdata.coords", c("lon", "lat")), remove_coords = TRUE, address = getOption("getdata.address", "address"), geo = FALSE, from_crs = 4326, clean_names = TRUE, ... )
url |
A Google Sheets url |
sheet |
Sheet to read, in the sense of "worksheet" or "tab". You can identify a sheet by name, with a string, or by position, with a number. Ignored if the sheet is specified via |
ss |
Something that identifies a Google Sheet:
Processed through |
ask |
If |
geometry |
Type of geometry to include in data frame. options include "drop", "wkt", "centroid", "point", Default: 'centroid'. |
location |
sf object. If multiple areas are provided, they are unioned
into a single sf object using |
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 |
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, |
coords |
Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat"). |
remove_coords |
For |
address |
Address column name passed to |
geo |
If |
from_crs |
For |
clean_names |
If |
... |
Other parameters passed onto methods. |
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.
get_location( type, name = NULL, name_col = "name", id = NULL, id_col = "id", location = NULL, index = NULL, union = FALSE, crs = getOption("getdata.crs", 3857), label = NULL, class = "sf", ... )
get_location( type, name = NULL, name_col = "name", id = NULL, id_col = "id", location = NULL, index = NULL, union = FALSE, crs = getOption("getdata.crs", 3857), label = NULL, class = "sf", ... )
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 |
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 ( |
index |
Optional list used to match type to data, Default: |
union |
If |
crs |
Coordinate reference system to return; defaults to |
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 |
class |
Class of object to return; defaults to "sf". |
... |
Additional parameters passed to |
A simple feature object from data provided to type.
nc <- sfext::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") # if name is named, the name of name is used as name_col get_location(type = nc, name = c("NAME" = "Warren")) # 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) ) )
nc <- sfext::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") # if name is named, the name of name is used as name_col get_location(type = nc, name = c("NAME" = "Warren")) # 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) ) )
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 sfext::read_sf_url()
, sfext::read_sf_path()
, or
sfext::read_sf_pkg()
. This function uses sfext::st_filter_ext()
to
filter, crop, or trim data to the provided location. location can also be an
an address.
get_location_data( location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", default = "meter"), asp = getOption("getdata.asp"), data = NULL, pkg = getOption("getdata.package"), package = getOption("getdata.package"), fileext = getOption("getdata.fileext", default = "gpkg"), filetype = getOption("getdata.filetype", default = "gpkg"), fn = NULL, crop = TRUE, trim = FALSE, from_crs = getOption("getdata.from_crs"), crs = getOption("getdata.crs", 3857), class = "sf", label = NULL, index = NULL, col = NULL, var_names = NULL, clean_names = FALSE, range = NULL, .name_repair = "check_unique", ..., call = caller_env() ) map_location_data( location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, data = NULL, package = NULL, fileext = "gpkg", filetype = "gpkg", fn = NULL, crop = TRUE, trim = FALSE, from_crs = NULL, crs = NULL, class = "list", label = NULL, load = FALSE, index = NULL, range = NULL, ... )
get_location_data( location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", default = "meter"), asp = getOption("getdata.asp"), data = NULL, pkg = getOption("getdata.package"), package = getOption("getdata.package"), fileext = getOption("getdata.fileext", default = "gpkg"), filetype = getOption("getdata.filetype", default = "gpkg"), fn = NULL, crop = TRUE, trim = FALSE, from_crs = getOption("getdata.from_crs"), crs = getOption("getdata.crs", 3857), class = "sf", label = NULL, index = NULL, col = NULL, var_names = NULL, clean_names = FALSE, range = NULL, .name_repair = "check_unique", ..., call = caller_env() ) map_location_data( location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, data = NULL, package = NULL, fileext = "gpkg", filetype = "gpkg", fn = NULL, crop = TRUE, trim = FALSE, from_crs = NULL, crs = NULL, class = "list", label = NULL, load = FALSE, index = NULL, range = NULL, ... )
location |
sf object. If multiple areas are provided, they are unioned
into a single sf object using |
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 |
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, |
data |
Character string (e.g. url, file path, or name of data from
package) for a spatial data or a |
pkg , package
|
Name of the package to search for data. |
fileext , filetype
|
File extension or type to use if passing parameters
to |
fn |
Function to apply to data after filtering by location but before returning from function. |
crop |
If |
trim |
If |
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 |
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 |
col |
For as_sf_list, the name of the column used to group data if x is a sf object or used to group and nest data before passing to x. |
var_names |
A named list following the format, |
clean_names |
If |
range |
For |
.name_repair |
One of "unique", "universal", or "check_unique". See
|
... |
Additional parameters passed to |
call |
The execution environment of a currently
running function, e.g. |
load |
If |
This function previously supported county geoid, state name, abbreviation, or
geoid as a location. Currently, recommend using get_tigris_data()
and
passing a sf
object to location.
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()
).
get_socrata_data is get_open_data with source_type set to "socrata" (the only currently supported option). get_open_data can return a selected dataset using Socrata Query Language (SoQL) parameters as a tibble or sf object. Details on SoQL queries are found in the Socrata API documentation https://dev.socrata.com/docs/queries/.
get_open_data( data = NULL, source_url = NULL, source_type = "socrata", select = NULL, where = NULL, query = NULL, location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, name_col = NULL, name = NULL, location_col = NULL, coords = c("longitude", "latitude"), geometry = FALSE, token = NULL, type = NULL, from_crs = 4326, crs = NULL, clean_names = TRUE, quiet = FALSE, .name_repair = janitor::make_clean_names ) get_socrata_data( data = NULL, source_url = NULL, select = NULL, where = NULL, query = NULL, location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, name_col = NULL, name = NULL, location_col = NULL, coords = c("longitude", "latitude"), geometry = FALSE, token = NULL, type = NULL, from_crs = 4326, crs = NULL, clean_names = TRUE ) get_socrata_metadata(source_url = NULL, data = NULL) list_socrata_data(source_url)
get_open_data( data = NULL, source_url = NULL, source_type = "socrata", select = NULL, where = NULL, query = NULL, location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, name_col = NULL, name = NULL, location_col = NULL, coords = c("longitude", "latitude"), geometry = FALSE, token = NULL, type = NULL, from_crs = 4326, crs = NULL, clean_names = TRUE, quiet = FALSE, .name_repair = janitor::make_clean_names ) get_socrata_data( data = NULL, source_url = NULL, select = NULL, where = NULL, query = NULL, location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, name_col = NULL, name = NULL, location_col = NULL, coords = c("longitude", "latitude"), geometry = FALSE, token = NULL, type = NULL, from_crs = 4326, crs = NULL, clean_names = TRUE ) get_socrata_metadata(source_url = NULL, data = NULL) list_socrata_data(source_url)
data |
A data set identifier (known as a resource for Socrata) or a url for an individual dataset. If data is set to "list" and a valid source_url is provided, the function returns a list of all available resources. If data is a url, source_url must be NULL. get_socrata_metadata requires the data parameter. |
source_url |
A data source url. For Socrata, this should the base url for the open data portal. |
source_type |
Data source type; defaults to "socrata" which is currently the only supported option. |
select |
Names of of columns to return or transformed, equivalent to a SELECT in SQL. Passed to SODA $select parameter, see https://dev.socrata.com/docs/queries/select.html for more information. |
where |
Condition to filters the rows to return, equivalent to WHERE in SQL. Passed to the SODA $where parameter, see https://dev.socrata.com/docs/queries/where.html for more information. |
query |
A full SoQL query string, all as one parameter. Passed to the SODA $query parameter, see https://dev.socrata.com/docs/queries/query.html for more information. |
location |
sf object. If multiple areas are provided, they are unioned
into a single sf object using |
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 |
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, |
name , name_col
|
Name of column in Socrata data resource with location names (e.g. County) and name of location to return. |
location_col |
Name of a "location" or "point" type column in a Socrata dataset. |
coords |
Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat"). |
geometry |
If |
token , type
|
Access token or API Key and token type (name used to store token in .Renvironment). A token may be required to access data from Socrata and other open data portals but can be stored as an environment variable with set_access_token. |
from_crs |
Coordinate reference system used to match the location CRS to the source data. |
crs |
Coordinate reference system of bounding box to return; defaults to
|
clean_names |
If |
quiet |
If |
.name_repair |
One of "unique", "universal", or "check_unique". See
|
## Get Q2 2020 vehicle crash data for Cecil County, Maryland ## Not run: get_open_data( source_url = "https://opendata.maryland.gov", data = "65du-s3qu", where = "(year = '2020') AND (quarter = 'Q2')", name_col = "county_desc", name = "Cecil", token = Sys.getenv("MARYLAND_OPEN_DATA_API_KEY") ) ## End(Not run)
## Get Q2 2020 vehicle crash data for Cecil County, Maryland ## Not run: get_open_data( source_url = "https://opendata.maryland.gov", data = "65du-s3qu", where = "(year = '2020') AND (quarter = 'Q2')", name_col = "county_desc", name = "Cecil", token = Sys.getenv("MARYLAND_OPEN_DATA_API_KEY") ) ## End(Not run)
Use osmdata
functions to query the overpass API and access OSM data by
adjusted bounding box or by enclosing ways/relations around the center of a
location. For more information on key and value options, refer to the
osm_common_tags
reference table or the OSM Wiki
https://wiki.openstreetmap.org/wiki/Map_features. Use the osmdata
package
directly for more detailed control over queries
https://docs.ropensci.org/osmdata/
get_osm_data( location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, key, value = NULL, features = NULL, id = NULL, type = NULL, crs = NULL, geometry = NULL, osmdata = FALSE, enclosing = NULL, nodes_only = FALSE, key_exact = TRUE, value_exact = TRUE, match_case = TRUE ) get_osm_id(id, type = NULL, crs = NULL, geometry = NULL, osmdata = FALSE) get_osm_boundaries( location, level = NULL, lang = "en", crs = NULL, enclosing = "relation", geometry = NULL, osmdata = FALSE )
get_osm_data( location = NULL, dist = NULL, diag_ratio = NULL, unit = NULL, asp = NULL, key, value = NULL, features = NULL, id = NULL, type = NULL, crs = NULL, geometry = NULL, osmdata = FALSE, enclosing = NULL, nodes_only = FALSE, key_exact = TRUE, value_exact = TRUE, match_case = TRUE ) get_osm_id(id, type = NULL, crs = NULL, geometry = NULL, osmdata = FALSE) get_osm_boundaries( location, level = NULL, lang = "en", crs = NULL, enclosing = "relation", geometry = NULL, osmdata = FALSE )
location |
A |
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 |
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, |
key |
Feature key for overpass API query. |
value |
Value of the feature key; can be negated with an initial
exclamation mark, |
features |
A named list with the format |
id |
OpenStreetMap feature id with or without a type id prefix. If multiple id values are provided, they must use a single consistent value for geometry. |
type |
Type of feature for the id; "node", "way", or "relation". Optional if id includes a type prefix. |
crs |
Coordinate reference system for output data; if |
geometry |
Geometry type to output ("polygons", "points", "lines",
"multilines", or "multipolygons"); if multiple geometry types are needed
set osmdata to |
osmdata |
If |
enclosing |
If enclosing is "relation" or "way", this function uses the
|
nodes_only |
WARNING: this parameter is equivalent to
|
key_exact |
If FALSE, |
value_exact |
If FALSE, |
match_case |
If FALSE, matching for both |
level |
Numeric administrative level (admin_level) of boundary to
return; defaults to |
lang |
Language for boundary names to include in resulting data frame (e.g. "en" for English or "es" for Spanish). Default language names should always be included in results. Defaults to "en". See https://wiki.openstreetmap.org/wiki/Multilingual_names for more information. |
A simple feature object with features using selected geometry type or
an osmdata
object with features from all geometry types.
nc <- sfext::read_sf_path(system.file("shape/nc.shp", package = "sf")) civic_buildings <- get_osm_data( location = nc[37,], features = c("building" = "civic"), geometry = "polygons" ) civic_buildings
nc <- sfext::read_sf_path(system.file("shape/nc.shp", package = "sf")) civic_buildings <- get_osm_data( location = nc[37,], features = c("building" = "civic"), geometry = "polygons" ) civic_buildings
Get a static map image using the Mapbox Static Maps API using mapboxapi::static_mapbox or
the Bing Maps Static Map API
using bingmapr::get_map_image. An API key or access token is required for
both services. Set the bingmap API token using bingmapr::bing_maps_api_key
and the Mapbox token with mapboxapi::mb_access_token or use
set_access_token
with type = "BING_MAPS_API_KEY"
or type = "MAPBOX_PUBLIC_TOKEN"
.
get_static_mapbox( location, dist = NULL, unit = "meter", style_url = "mapbox://styles/mapbox/light-v10", overlay_location = FALSE, overlay_sf = NULL, overlay_style = NULL, zoom = NULL, width = 600, height = 400, bearing = NULL, pitch = NULL, token = NULL, ... ) get_osm_static_mapbox( id = NULL, key = NULL, level = NULL, location = NULL, dist = NULL, unit = "meter", overlay_location = TRUE, style_url = "mapbox://styles/mapbox/light-v10", overlay_sf = NULL, overlay_style = NULL, zoom = NULL, width = 600, height = 400, bearing = NULL, pitch = NULL, token = NULL, ... ) get_location_static_mapbox( type, dist = NULL, unit = "meter", name = NULL, name_col = "name", id = NULL, id_col = "id", location = NULL, index = NULL, union = FALSE, overlay_location = TRUE, style_url = "mapbox://styles/mapbox/light-v10", overlay_sf = NULL, overlay_style = NULL, zoom = NULL, width = 600, height = 400, bearing = NULL, pitch = NULL, token = NULL, ... ) get_static_bingmap( location = NULL, dist = NULL, unit = "m", imagery = "BirdsEye", zoom = NULL, width = 600, height = 400, bearing = NULL, token = NULL, ... )
get_static_mapbox( location, dist = NULL, unit = "meter", style_url = "mapbox://styles/mapbox/light-v10", overlay_location = FALSE, overlay_sf = NULL, overlay_style = NULL, zoom = NULL, width = 600, height = 400, bearing = NULL, pitch = NULL, token = NULL, ... ) get_osm_static_mapbox( id = NULL, key = NULL, level = NULL, location = NULL, dist = NULL, unit = "meter", overlay_location = TRUE, style_url = "mapbox://styles/mapbox/light-v10", overlay_sf = NULL, overlay_style = NULL, zoom = NULL, width = 600, height = 400, bearing = NULL, pitch = NULL, token = NULL, ... ) get_location_static_mapbox( type, dist = NULL, unit = "meter", name = NULL, name_col = "name", id = NULL, id_col = "id", location = NULL, index = NULL, union = FALSE, overlay_location = TRUE, style_url = "mapbox://styles/mapbox/light-v10", overlay_sf = NULL, overlay_style = NULL, zoom = NULL, width = 600, height = 400, bearing = NULL, pitch = NULL, token = NULL, ... ) get_static_bingmap( location = NULL, dist = NULL, unit = "m", imagery = "BirdsEye", zoom = NULL, width = 600, height = 400, bearing = NULL, token = NULL, ... )
location |
An input location for which you would like to request tiles.
Can be a length-4 vector representing a bounding box, or an |
dist |
Buffer distance passed to buffer_dist parameter of
|
unit |
Unit of |
style_url |
Style URL; defaults to "mapbox://styles/mapbox/light-v10" |
overlay_location |
If |
overlay_sf |
The overlay |
overlay_style |
A named list of vectors specifying how to style the sf
overlay. Possible names are "stroke", "stroke-width" (or "stroke_width"),
"stroke-opacity" (or "stroke_opacity"), "fill", and "fill-opacity" (or
"fill_opacity"). The fill and stroke color values can be specified as
six-digit hex codes or color names, and the opacity and width values should
be supplied as floating-point numbers. If overlay_style is |
zoom |
The map zoom. The map will infer this from the overlay unless longitude, latitude, and zoom are all specified. |
width , height
|
Map width and height; defaults to 600 px width and 400 px height. |
pitch , bearing
|
The map pitch and bearing; defaults to |
token |
Optional token or API key. Recommend setting the Bing Maps API
key using |
... |
Additional parameters passed to |
id |
OpenStreetMap feature id with or without a type id prefix. If multiple id values are provided, they must use a single consistent value for geometry. |
key |
Feature key for overpass API query. |
level |
Numeric administrative level (admin_level) of boundary to
return; defaults to |
type |
For |
name |
Location name to return. |
name_col |
Column name in type with name values, Default: 'name' Required if name provided. |
id_col |
Column name in type with id values, Default: 'id'. Required if id is provided. |
index |
Optional list used to match type to data, Default: |
union |
If |
imagery |
String with imagery type, Default: 'BirdsEye' Supported values include:
|
Variations on get_static_mapbox include
get_location_static_mapbox wrapping get_location()
get_osm_static_mapbox wrapping get_osm_data()
, get_osm_id()
, and
get_osm_boundaries()
In those cases, the ... parameters are passed on the getdata functions rather than the static map function.
For get_static_bingmap()
, parameter names are modified from
bingmapr::get_map_image()
for consistency, so the bearing parameter passed to
orientation and token is passed to key.
## Not run: get_osm_static_mapbox( id = "way/49664223", dist = 0.5, unit = "mi", overlay_style = list( stroke = "darkgreen", fill = "green", fill_opacity = 0.25 ) ) nc <- sfext::read_sf_path(system.file("shape/nc.shp", package = "sf")) get_location_static_mapbox( type = nc, name = "Ashe", name_col = "NAME", dist = 50, unit = "mi" ) ## End(Not run)
## Not run: get_osm_static_mapbox( id = "way/49664223", dist = 0.5, unit = "mi", overlay_style = list( stroke = "darkgreen", fill = "green", fill_opacity = 0.25 ) ) nc <- sfext::read_sf_path(system.file("shape/nc.shp", package = "sf")) get_location_static_mapbox( type = nc, name = "Ashe", name_col = "NAME", dist = 50, unit = "mi" ) ## End(Not run)
Use the {tigris} package to download state-level data from the U.S. Census Bureau API and optionally filter by name or GeoID.
get_tigris_data( type = NULL, state = getOption("getdata.state"), location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", "meter"), asp = getOption("getdata.asp"), crs = getOption("getdata.crs", default = 3857), name = NULL, name_col = c("name", "namelsad", "geoid"), cb = TRUE, clean_names = TRUE, cache = TRUE, ... )
get_tigris_data( type = NULL, state = getOption("getdata.state"), location = NULL, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", "meter"), asp = getOption("getdata.asp"), crs = getOption("getdata.crs", default = 3857), name = NULL, name_col = c("name", "namelsad", "geoid"), cb = TRUE, clean_names = TRUE, cache = TRUE, ... )
type |
Type of data to return, Default: |
state |
State name, abbreviation, or GeoID. Required. Defaults to getOption("getdata.state"). |
location |
A sf, sfc, or bbox object passed to |
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 |
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, |
crs |
Coordinate reference system of bounding box to return; defaults to
|
name , name_col
|
Name and columns to filter by name. name defaults to
|
cb |
If |
clean_names |
If |
cache |
If |
... |
Additional parameters passed on to tigris functions. |
Supported data types:
Different type values corresponded to different tigris functions for downloading from the U.S. Census Bureau API include. Supported options include: "counties", "census places", "congressional districts", "legislative districts", "senate district", "tracts", "block groups", "blocks", "pumas", "voting districts", "zctas", "roads", "primary secondary roads", "area water", "linear water", and "landmarks".
tigris functions that do not use a "state" parameter (e.g.
tigris::coastline or tigris::rails) are not supported by this
function. Note that the default value of the cb parameter for
get_tigris_data is TRUE
and the default value of for the original
{tigris} package is FALSE
.
A simple feature object matching the type provided.
Use the Wikipedia API geosearch API to get Wikipedia articles for a location. See https://www.mediawiki.org/wiki/Extension:GeoData for more information. Only returns Wikipedia articles with coordinates.
get_wiki_data( location, radius = FALSE, primary = NULL, details = NULL, limit = 50, list = "geosearch", lang = getOption("getdata.lang", default = "en"), geometry = TRUE, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", "meter"), asp = getOption("getdata.asp"), crs = getOption("getdata.unit", 3857), remove_coords = TRUE, clean_names = TRUE )
get_wiki_data( location, radius = FALSE, primary = NULL, details = NULL, limit = 50, list = "geosearch", lang = getOption("getdata.lang", default = "en"), geometry = TRUE, dist = getOption("getdata.dist"), diag_ratio = getOption("getdata.diag_ratio"), unit = getOption("getdata.unit", "meter"), asp = getOption("getdata.asp"), crs = getOption("getdata.unit", 3857), remove_coords = TRUE, clean_names = TRUE )
location |
sf object. If multiple areas are provided, they are unioned
into a single sf object using |
radius |
If |
primary |
If |
details |
Additional detailed to return with results. Options include
"type", "name", "country", "region"; defaults to |
limit |
Number of pages to return (max 500); defaults to 50 |
list |
method to use for query; "geosearch" returns data, "resp" returns response |
lang |
Language to search on Wikipedia; defaults to "en". |
geometry |
If |
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 |
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, |
crs |
Coordinate reference system of bounding box to return; defaults to
|
remove_coords |
For |
clean_names |
If |
For this function, location
can be either an sf
, sfc
, or bbox
object
or the title of a Wikipedia article with a related location.
GNfindNearbyWikipedia()
and GNwikipediaBoundingBox()
functions
in the geonames package
This function converts data and location into lists of sf objects using
as_sf_list. If location_col, data_col, or col (which sets both to the
same value), are provided the col is passed to as_sf_list to allow the
creation of an sf list from a sf data frame using dplyr::group_nest()
.
make_location_data_list(data, location, key = c("location", "data"), ...)
make_location_data_list(data, location, key = c("location", "data"), ...)
data , location
|
A sf object or list of sf objects with data and corresponding locations. |
key |
Names for location and data in the returned list. |
... |
Pass location_col and/or data_col to group and nest the data provided to location and data. Use col to set both to the same value. |
If location and data are the same length are the same length, they are combined into a single list. If either one is length 1 when the other is not, the length 1 object is repeated to match the length of the longer object. Different length objects where neither are length 1 gives a warning.
If location is a single feature sf object, the original columns of the object are included in the output grid. If location has mutiple features, the values of name_col are combined with sfext::st_union_ext and other columns are dropped. The input sf object should not have columns named id, rows, or cols.
make_location_grid(location, name_col = "name", unit = NULL, ...)
make_location_grid(location, name_col = "name", unit = NULL, ...)
location |
A sf, sfc, or bbox object passed to sfext::st_make_grid_ext |
name_col |
Column name to collapse into new name_col value, Default: 'name' |
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" |
... |
Arguments passed on to
|
label_with_xwalk()
or
rename_with_xwalk()
Make a crosswalk list for use with label_with_xwalk()
or
rename_with_xwalk()
make_xwalk_list(xwalk, cols = c("label", "name"), call = caller_env())
make_xwalk_list(xwalk, cols = c("label", "name"), call = caller_env())
xwalk |
A data frame with two columns or a named list. |
cols |
Column names to use for crosswalk. |
call |
The execution environment of a currently
running function, e.g. |
A named list
Used by get_osm_data if key = "building".
osm_building_tags
osm_building_tags
A character vector with length of 84
More information on the building key https://wiki.openstreetmap.org/wiki/Key:building
A subset of tags scraped from the OpenStreetMap Wiki page on Map features: https://wiki.openstreetmap.org/wiki/Map_features. Only those tags with a url are included in this reference table.
osm_common_tags
osm_common_tags
A data frame with 272 rows and 5 variables:
key
Key
value
Value
description
Description of tag/usage
category
Category
url
OSM Wiki url
Use stringr::str_replace_all()
to replace values in a character vector or
(with dplyr::across()
) in select columns from a data.frame.
replace_street_dir_prefixes()
and replace_street_suffixes()
pass
reference data (street_dir_prefixes and street_suffixes) to the dict
parameter to support formatting addresses with bind_block_col()
.
replace_with_xwalk( x, .cols = NULL, xwalk = NULL, dict = NULL, abb = TRUE, case = NULL, .strict = TRUE, ignore_case = TRUE ) replace_street_suffixes( x, street_suffix = "street_type", xwalk = NULL, abb = TRUE, case = NULL ) replace_street_dir_prefixes( x, street_dir_prefix = "street_dir_prefix", xwalk = NULL, abb = TRUE, case = NULL )
replace_with_xwalk( x, .cols = NULL, xwalk = NULL, dict = NULL, abb = TRUE, case = NULL, .strict = TRUE, ignore_case = TRUE ) replace_street_suffixes( x, street_suffix = "street_type", xwalk = NULL, abb = TRUE, case = NULL ) replace_street_dir_prefixes( x, street_dir_prefix = "street_dir_prefix", xwalk = NULL, abb = TRUE, case = NULL )
x |
A data.frame or character vector. If x is a character vector, .cols is optional. If x is a data.frame, x is required. |
.cols |
< |
xwalk , dict
|
Named list or data frame with a minimum of two columns
where one column contains the replacement values and the other the values
to replace. If xwalk is |
abb |
If abb is |
case |
Case to use for text in new columns or in modified values.
Options include "lower", "upper", "title", or "sentence". Defaults to
|
.strict |
If |
ignore_case |
Passed to |
street_suffix |
Street suffix column to apply replacement function to. |
street_dir_prefix |
Street direction prefix column to apply replacement function to. |
address_df <- data.frame( "bldg_num" = c("100", "1415", "600", "10"), "street_dir_prefix" = c(NA, NA, "N", NA), "street_name" = c("Holiday", "Key", "Charles", "Art Museum"), "street_type" = c("St", "Hwy", "St", "Dr") ) replace_street_suffixes( c("Street", "Highway", "Avenue", "Drive") ) replace_street_suffixes( address_df, abb = FALSE, case = "sentence" ) replace_street_dir_prefixes( c("North", "East", "West") ) replace_street_dir_prefixes( c("S", "W", "N"), abb = FALSE, case = "sentence" )
address_df <- data.frame( "bldg_num" = c("100", "1415", "600", "10"), "street_dir_prefix" = c(NA, NA, "N", NA), "street_name" = c("Holiday", "Key", "Charles", "Art Museum"), "street_type" = c("St", "Hwy", "St", "Dr") ) replace_street_suffixes( c("Street", "Highway", "Avenue", "Drive") ) replace_street_suffixes( address_df, abb = FALSE, case = "sentence" ) replace_street_dir_prefixes( c("North", "East", "West") ) replace_street_dir_prefixes( c("S", "W", "N"), abb = FALSE, case = "sentence" )
Based on the mapboxapi::mb_access_token()
function from the {mapboxapi}
package by Kyle Walker.
set_access_token( token, overwrite = FALSE, install = FALSE, type = NULL, quiet = FALSE, call = caller_env() ) get_access_token(token = NULL, type = NULL, call = caller_env())
set_access_token( token, overwrite = FALSE, install = FALSE, type = NULL, quiet = FALSE, call = caller_env() ) get_access_token(token = NULL, type = NULL, call = caller_env())
token |
An access token or API key; required for |
overwrite |
If |
install |
If |
type |
Default name used for environment variable where the token is saved. |
quiet |
If |
call |
The execution environment of a currently
running function, e.g. |
This function can set named options for a package using the convention of
"pkg.option". For examples set_pkg_options(crs = 2804, .pkg = "getdata")
sets the option "getdata.crs" to 2804. If "getdata.crs" is
already set, overwrite must be TRUE
to replace the existing value.
set_pkg_options(..., overwrite = FALSE, .pkg = "getdata")
set_pkg_options(..., overwrite = FALSE, .pkg = "getdata")
... |
Named list of options to set, e.g. "crs = 2804" with |
overwrite |
If |
.pkg |
Package name to append to option name. Defaults to "getdata". |
Implemented options (with defaults if used) for the getdata package include:
dist
diag_ratio
unit ("meter")
asp
crs (3857)
from_crs (4326)
address ("address")
package
filetype ("gpkg")
A similar convention is used for the maplayer package. The use of options is not implemented across all functions and may be changed in the future.
Apply stringr::str_squish()
and stringr::str_trim()
to all character
columns in a data.frame.
str_trim_squish_across(x)
str_trim_squish_across(x)
x |
A data.frame with character columns. |
A data frame based on Appendix I4 Directionals from the U.S. Postal Service Publication 28 - Postal Addressing Standards. According to the U.S. Postal Service, "Directionals are not commonly used in Puerto Rican addresses because other descriptions, such as the urbanization name identify geographic areas. In the ZIP+4 file, the English equivalents are used. Note: Although the Spanish word for West is Oeste, the abbreviation W is used."
street_dir_prefixes
street_dir_prefixes
A data frame with 8 rows and 3 variables:
street_dir_abb
Street directional abbreviation
street_dir_en
Street directional name (English)
street_dir_es
Street directional name (Spanish)
Source: https://pe.usps.com/text/pub28/28api_007.htm
A data frame based on Appendix C1 Street Suffix Abbreviations from the U.S. Postal Service Publication 28 - Postal Addressing Standards. This data includes examples of suffix forms that are primary street suffix names, common street suffixes or suffix abbreviations, and recommended official U.S. Postal Service standard suffix abbreviations.
street_suffixes
street_suffixes
A data frame with 206 rows and 3 variables:
street_suffix_abb
U.S. Postal Service standard suffix abbreviation
street_suffix
Street suffix name
street_suffix_common
List column with commonly used street suffix or abbreviation
Source: https://pe.usps.com/text/pub28/28apc_002.htm