read_sf_ext: Read spatial data in a bounding box to a simple feature...

View source: R/read_sf_ext.R

read_sf_extR Documentation

Read spatial data in a bounding box to a simple feature object

Description

An extended version of sf::read_sf() that support reading spatial data based on a file path, URL, or the data name and associated package. Optionally provide a bounding box to filter data (not supported for all data types). If a file path or url is provided for a GeoJSON file, the read_sf_geojson function (using the suggested geojsonsf package) is used.

Usage

read_sf_ext(..., bbox = NULL)

read_sf_pkg(data, bbox = NULL, package = NULL, filetype = "gpkg", ...)

read_sf_path(path, bbox = NULL, ...)

read_sf_excel(
  path,
  sheet = NULL,
  bbox = NULL,
  coords = c("lon", "lat"),
  geo = FALSE,
  address = "address",
  from_crs = 4326,
  ...
)

read_sf_csv(
  path,
  url = NULL,
  bbox = NULL,
  coords = c("lon", "lat"),
  geo = FALSE,
  address = "address",
  show_col_types = FALSE,
  from_crs = 4326,
  ...
)

read_sf_url(url, bbox = NULL, coords = NULL, zm_drop = TRUE, ...)

read_sf_geojson(url, path = NULL, geojson = NULL, bbox = NULL, ...)

read_sf_gist(url, id = NULL, bbox = NULL, ...)

read_sf_gmap(url, bbox = NULL, zm_drop = TRUE)

read_sf_download(
  url,
  filename,
  bbox = NULL,
  path = NULL,
  filetype = "geojson",
  prefix = "date",
  method = "auto",
  unzip = FALSE,
  ...
)

read_sf_gsheet(
  url,
  sheet = NULL,
  ss = NULL,
  bbox = NULL,
  coords = c("lon", "lat"),
  ask = FALSE,
  geo = FALSE,
  address = "address",
  from_crs = 4326,
  ...
)

Arguments

...

Additional parameters passed to multiple functions; see details.

bbox

A bounding box object; defaults to NULL. If "bbox" is provided, only returns features intersecting the bounding box.

data

Character; name of dataset; used by read_sf_pkg() only.

package

Character; package name; used by read_sf_pkg() only.

filetype

File type supported for dsn parameter of sf::read_sf(); Default: 'gpkg'; used by read_sf_pkg() only and required only if the data is in the package cache directory or extdata system files.

path

A file path.

sheet

Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). Ignored if the sheet is specified via range. If neither argument specifies the sheet, defaults to the first sheet.

coords

Character vector with coordinate values. Coordinates must be latlon data (with coordinate reference system 4326).

geo

If TRUE, use address_to_sf to geocode address column; defaults to FALSE.

address

Address column name, Default: 'address'

from_crs

For df_to_sf, coordinate reference system used by coordinates or well known text in data frame.

url

A url for a spatial data file, a GitHub gist, or a ArcGIS FeatureServer or MapServer to access with get_esri_data()

show_col_types

If FALSE, do not show the guessed column types. If TRUE always show the column types, even if they are supplied. If NULL (the default) only show the column types if they are not explicitly supplied by the col_types argument.

zm_drop

If TRUE, drop Z and/or M dimensions using sf::st_zm

geojson

string or vector of GeoJSON, or a URL or file pointing to a geojson file

id

The name of a column in which to store the file path. This is useful when reading multiple input files and there is data in the file paths, such as the data collection date. If NULL (the default) no extra column is created.

filename

File name; if file name is NULL, name and file type are both required.

prefix

File name prefix. "date" adds a date prefix, "time" adds a date/time prefix; defaults to NULL.

method

Method to be used for downloading files. Current download methods are "internal", "wininet" (Windows only) "libcurl", "wget" and "curl", and there is a value "auto": see ‘Details’ and ‘Note’.

The method can also be set through the option "download.file.method": see options().

unzip

If TRUE, url must be a zip file that is downloaded, unzipped into a temporary directory (created with tempdir()), and then read to a file using the specified file type.

ss

Something that identifies a Google Sheet:

  • its file id as a string or drive_id

  • a URL from which we can recover the id

  • a one-row dribble, which is how googledrive represents Drive files

  • an instance of googlesheets4_spreadsheet, which is what gs4_get() returns

Processed through as_sheets_id().

ask

If TRUE, ask for the name of the Google Sheet to read if ss is not provided to read_sf_gsheet.

Details

Reading data from a url:

read_sf_url supports multiple types of urls:

  • A MapServer or FeatureServer URL

  • A URL for a GitHub gist with a single spatial data file (first file used if gist contains multiple)

  • A URL for a spatial data file or a CSV file

  • A Google Sheets URL

  • A public Google Maps URL

Reading data from a package:

read_sf_pkg looks for three types of package data:

  • Data loaded with the package

  • External data in the extdata system files folder.

  • Cached data in the cache directory returned by rappdirs::user_cache_dir

Additional ... parameters:

read_sf_pkg and read_sf_download both pass additional parameters to read_sf_path which supports query, name_col, name, and table. name and name_col are ignored if a query parameter is provided. If table is not provided, a expected layer name is created based on the file path.

read_sf_url pass the where, name_col, and name for any ArcGIS FeatureServer or MapServer url (passed to get_esri_data) or sheet if the url is for a Google Sheet (passed to googlesheets4::read_sheet), or a query or wkt filter parameter if the url is some other type (passed to sf::read_sf).

read_sf_ext is a flexible function that only has bbox as a named parameter and all other parameters in ... are passed to one of the other overedge read_sf functions.

See Also

Other read_write: make_filename(), read_sf_exif()


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