Title: | Extra Functions for Simple Feature Data |
---|---|
Description: | Extra functions with additional options for reading, writing, and transforming spatial data. Includes a variety of utility functions for working with tabular data with coordinates and distance and area units. |
Authors: | Eli Pousson [aut, cre, cph] |
Maintainer: | Eli Pousson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1.9000 |
Built: | 2024-11-11 22:18:24 UTC |
Source: | https://github.com/elipousson/sfext |
Wraps tidygeocoder::geo()
and tidygeocoder::geocode()
to convert a
character string or a data frame with an address column. Additional
parameters passed to tidygeocoder::geocode()
which passes ...
parameters to
tidygeocoder::geo()
.
address_to_sf( x, address = "address", method = "osm", coords = c("lon", "lat"), remove_coords = FALSE, crs = NULL, full_results = FALSE, ..., call = caller_env() )
address_to_sf( x, address = "address", method = "osm", coords = c("lon", "lat"), remove_coords = FALSE, crs = NULL, full_results = FALSE, ..., call = caller_env() )
x |
Data frame with an address column. Multiple address columns are not currently supported. |
address |
Address column name, Default: 'address' |
method |
the geocoding service to be used. API keys are loaded from environmental variables. Run
|
coords |
Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat"). |
remove_coords |
For |
crs |
Cordinate reference system to return, Default: 4326 for
|
full_results |
returns all available data from the geocoding service if TRUE. If FALSE (default) then only latitude and longitude columns are returned from the geocoding service. |
... |
Arguments passed on to
|
call |
The execution environment of a currently
running function, e.g. |
A sf
object with POINT geometry for all geocoded addresses with valid coordinates.
tidygeocoder::geo()
, tidygeocoder::geocode()
A vector of supported area units derived from dist_units
and
units::valid_udunits()
.
area_unit_options
area_unit_options
A character vector with 41 names, plural names, and aliases for area units.
as_crs: coerce x to a CRS object and (optionally) error if a NA value is returned.
is_same_crs: do x and y have the same coordinate reference system?
as_crs(x = NULL, allow_na = TRUE, arg = caller_arg(x), call = caller_env()) is_same_crs(x, y) is_wgs84(x)
as_crs(x = NULL, allow_na = TRUE, arg = caller_arg(x), call = caller_env()) is_same_crs(x, y) is_wgs84(x)
x |
For |
allow_na |
For |
arg |
An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem. |
call |
The execution environment of a currently
running function, e.g. |
y |
For |
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc[["category"]] <- sample(c("A", "B", "C"), nrow(nc), replace = TRUE) as_sf(nc$geometry) nc_bbox <- as_bbox(nc) nc_bbox as_sfc(nc_bbox) as_xy(nc[1,]) as_sf_list(nc, col = "category")
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc[["category"]] <- sample(c("A", "B", "C"), nrow(nc), replace = TRUE) as_sf(nc$geometry) nc_bbox <- as_bbox(nc) nc_bbox as_sfc(nc_bbox) as_xy(nc[1,]) as_sf_list(nc, col = "category")
Works with sf, sfc, and bbox objects using sf::st_centroid()
. Works with
sf_bbox_point()
as_point(..., to = "POINT") as_points(..., to = "POINT", call = caller_env()) as_startpoint(x) as_endpoint(x) as_line(..., to = "LINESTRING", call = caller_env()) as_lines(..., to = "LINESTRING") as_polygons(..., to = "POLYGON") as_centroid(x, ...)
as_point(..., to = "POINT") as_points(..., to = "POINT", call = caller_env()) as_startpoint(x) as_endpoint(x) as_line(..., to = "LINESTRING", call = caller_env()) as_lines(..., to = "LINESTRING") as_polygons(..., to = "POLYGON") as_centroid(x, ...)
... |
See details. |
to |
The geometry type to return, either POINT or MULTIPOINT or LINESTRING or MULTILINESTRING. |
call |
The execution environment of a currently
running function, e.g. |
x |
A |
Using as_point:
as_point()
always returns a single point sfg object. The ... parameter is
passed to sf::st_centroid()
if ... is a sf, sfc, or bbox object,
sf_bbox_point()
includes a bbox object and a string indicating the
requested point position, or sf::st_point()
if ... includes a numeric
vector.
Using as_points:
as_points()
always returns an sfc object. The parameters are passed to
as_point using purrr::map()
and then converted to sfc using
sf::st_as_sfc()
. The ... parameters must include a crs, otherwise the crs
will be NA for the resulting sfc object.
Using as_startpoint and as_endpoint:
as_startpoint()
and as_endpoint()
require a LINESTRING OR MULTILINESTRING
geometry type sf or sfc object that is passed to lwgeom::st_startpoint()
or
lwgeom::st_endpoint()
respectively. Both functions always return a sfc
object matching the CRS of the input geometry.
Using as_lines:
If params do not have POINT or MULTIPOINT geometry, they are passed to
as_points()
to convert to an sfc
object. If the parameters have POINT
geometry, they are combined to create a MULTIPOINT geometry.
For as_lines()
the ... parameters are passed to as_points()
and/or
sf::st_cast()
.
Both as_line and as_lines do not consistently retain the coordinate reference system of the original object but this should be improved in the future.
Using as_centroid()
as_centroid()
always returns a sfc object with the same length and crs as
the input object.
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) as_point(nc) as_point(c("xmax", "ymax"), bbox = as_bbox(nc)) as_points(nc) as_points(nc[1, ], nc[2, ]) nc_line <- as_line(c(as_points(nc[1, ]), as_points(nc[10, ]))) as_startpoint(nc_line) as_endpoint(nc_line) as_centroid(nc)
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) as_point(nc) as_point(c("xmax", "ymax"), bbox = as_bbox(nc)) as_points(nc) as_points(nc[1, ], nc[2, ]) nc_line <- as_line(c(as_points(nc[1, ]), as_points(nc[10, ]))) as_startpoint(nc_line) as_endpoint(nc_line) as_centroid(nc)
Both functions will pass a NULL
value without returning an error. If a
POINT or MULTIPOINT object is passed to as_bbox()
a 0.00000001 meter buffer
is applied. If a character object is passed to as_bbox()
it is passed to
osmdata::getbb()
using format_out = "matrix"
which is converted into a
bounding box.
as_sf( x, crs = NULL, sf_col = "geometry", ext = TRUE, ..., as_tibble = TRUE, call = caller_env() ) as_bbox(x, crs = NULL, ext = TRUE, ..., call = caller_env()) as_sfc(x, crs = NULL, ext = TRUE, ..., call = caller_env()) as_sf_class(x, class = NULL, allow_null = TRUE, ..., call = caller_env())
as_sf( x, crs = NULL, sf_col = "geometry", ext = TRUE, ..., as_tibble = TRUE, call = caller_env() ) as_bbox(x, crs = NULL, ext = TRUE, ..., call = caller_env()) as_sfc(x, crs = NULL, ext = TRUE, ..., call = caller_env()) as_sf_class(x, class = NULL, allow_null = TRUE, ..., call = caller_env())
x |
Object to convert to an sf, sfc, bbox or a sf list object. |
crs |
Coordinate reference system for |
sf_col |
A column name to use for the geometry column created by as_sf; defaults to "geometry". |
ext |
If |
... |
Additional parameters passed to as_sf, as_sfc, as_bbox, or as_sf_list |
as_tibble |
If |
call |
The execution environment of a currently
running function, e.g. |
class |
A class to convert data to; defaults to NULL (which returns "sf") |
allow_null |
For as_sf_class, if class is |
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc[["category"]] <- sample(c("A", "B", "C"), nrow(nc), replace = TRUE) as_sf(nc$geometry) nc_bbox <- as_bbox(nc) nc_bbox as_sfc(nc_bbox) as_xy(nc[1,]) as_sf_list(nc, col = "category")
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc[["category"]] <- sample(c("A", "B", "C"), nrow(nc), replace = TRUE) as_sf(nc$geometry) nc_bbox <- as_bbox(nc) nc_bbox as_sfc(nc_bbox) as_xy(nc[1,]) as_sf_list(nc, col = "category")
Wraps as_points()
, as_sfc()
, and sf_bbox_point()
to allow the
conversion of sf, sfc, or sfg objects into a simple data frame with X and Y
columns matching the provided nm parameter.
as_xy(x, bbox = NULL, crs = NULL, nm = c("x", "y"), ...)
as_xy(x, bbox = NULL, crs = NULL, nm = c("x", "y"), ...)
x |
A length 2 character string or numeric coordinate pair or a |
bbox |
A bbox object or object that can be converted with |
crs |
A character or numeric reference to a coordinate reference system
supported by |
nm |
Column names to use for X and Y columns. |
... |
Additional parameters passed to |
Utility function supporting get_area, get_dist, and get_bearing.
bind_units_col( x, y, units = NULL, drop = FALSE, keep_all = TRUE, .id = NULL, call = caller_env() )
bind_units_col( x, y, units = NULL, drop = FALSE, keep_all = TRUE, .id = NULL, call = caller_env() )
x |
Data frame or sf object. |
y |
Vector of numeric or units values to bind to x. |
units |
Units to use for y (if numeric) or convert to (if y is units
class); defaults to |
drop |
If |
keep_all |
If |
.id |
Name to use for vector of units provided to "y" parameter, when "y" is bound to the "x" data frame or tibble as a new column. |
call |
The execution environment of a currently
running function, e.g. |
If x is an sf
object invisibly return TRUE. If not, return an error with cli::cli_abort
check_sf( x, ..., ext = FALSE, allow_list = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env() )
check_sf( x, ..., ext = FALSE, allow_list = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env() )
x |
An |
... |
Additional parameters passed to |
ext |
If |
allow_list |
If |
allow_null |
If |
arg |
An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem. |
call |
The execution environment of a currently
running function, e.g. |
cli_format style for sf objects
## S3 method for class 'sf' cli_format(x, style = NULL, ...)
## S3 method for class 'sf' cli_format(x, style = NULL, ...)
x |
A sf object to format with the cli_format.sf method. |
style |
Not in use for the 'sf' class method. |
... |
Not in use for the 'sf' class method. |
cliExtras::register_cli_format()
## Not run: if (interactive()) { library(cli) library(sf) cliExtras::register_cli_format("sf", cli_format.sf) nc <- read_sf(system.file("shape/nc.shp", package = "sf")) cli_text("`nc` is a {.val {nc}}") } ## End(Not run)
## Not run: if (interactive()) { library(cli) library(sf) cliExtras::register_cli_format("sf", cli_format.sf) nc <- read_sf(system.file("shape/nc.shp", package = "sf")) cli_text("`nc` is a {.val {nc}}") } ## End(Not run)
Compare dist to a distance based on x. If to is "xdist" (default), "ydist",
"diagdist", or any length 2 character vector supported by sf_bbox_dist()
dist is compared to the resulting distance. If to is an sf or sfc object, the
comparison distance is the results from sf::st_distance()
with x as the
first parameter and to as the second. x can also be a numeric value with or
without a units class. Use the "how" argument to determine the type of
comparison: "ratio" (dist divided by comparison distance) "fit" (how many
lengths of dist can fit wholly within the comparison distance) "longer",
"shorter", "same" (uses tolerance parameter).
compare_dist( dist, x, units = NULL, to = "xdist", how = "ratio", tolerance = 1.5e-08, ... )
compare_dist( dist, x, units = NULL, to = "xdist", how = "ratio", tolerance = 1.5e-08, ... )
dist |
Distance to check as a units class or numeric vector |
x |
A |
units |
Units to compare. If dist or x are numeric they are assumed to
be in the provided units or the units of the coordinate reference system
(CRS) for x (if x is a |
to |
Distance to compare dist with. Standard options include "xdist"
(default), "ydist", or "diagdist" to compare to |
how |
If "ratio", dist divided by the comparison distance. If what is "fit", return the number of times dist fits in the comparison distance without remainder. If "longer", "shorter", "same", return a logical vector. |
tolerance |
passed to |
... |
Additional parameters passed to |
A logical or numeric vector.
Other dist:
convert_dist_scale()
,
convert_dist_units()
,
get_measurements
,
is_dist_units()
,
sf_bbox_dist()
This function converts scale distances to actual units based on named standard_scales.
convert_dist_scale( dist = NULL, scale = NULL, scale_standard = NULL, scale_series = NULL, scale_unit = "in", scale_factor = NULL, actual_unit = NULL, dpi = 120, paper = NULL, orientation = NULL, ... )
convert_dist_scale( dist = NULL, scale = NULL, scale_standard = NULL, scale_series = NULL, scale_unit = "in", scale_factor = NULL, actual_unit = NULL, dpi = 120, paper = NULL, orientation = NULL, ... )
dist |
distance to convert. If paper is provided, dist is optional and paper width and height are used as dist. |
scale |
Scale name from |
scale_standard , scale_series
|
Passed to standard and scale parameters of
|
scale_unit |
"mm" (converted to cm by dividing by 10), "cm", "px" (converted to inches by dividing by dpi), or "in". |
scale_factor |
factor for converting from scale_unit to actual_unit,
e.g. if 1" = 1', the scale factor is 12. optional if scale if provided;
defaults to |
actual_unit |
any unit supported by |
dpi |
dots per square inch (used as conversion factor for "px" to "in") |
paper |
Paper, Default: 'letter'. |
orientation |
Orientation "portrait", "landscape", or "square", Default: 'portrait'. |
... |
Arguments passed on to
|
If paper is not provided, return a vector of dist values converted from scale_unit to actual_unit based on scale_factor or information from standard_scales data.
If paper is provided, return a data.frame with converted distances appends as columns named actual_width and actual_height.
Other dist:
compare_dist()
,
convert_dist_units()
,
get_measurements
,
is_dist_units()
,
sf_bbox_dist()
Convert distance (and area) values between different units
convert_dist_units( dist, from = NULL, to = "meter", drop = FALSE, digits = NULL )
convert_dist_units( dist, from = NULL, to = "meter", drop = FALSE, digits = NULL )
dist |
Numeric or units object |
from |
Existing unit for dist, Default: |
to |
Unit to convert distance to, Default: 'meter' |
drop |
If |
digits |
Number of digits to include in result; defaults to |
Object created by units::set_units()
Other dist:
compare_dist()
,
convert_dist_scale()
,
get_measurements
,
is_dist_units()
,
sf_bbox_dist()
coords_to_sf()
: Convert a data frame with coordinates into a simple
feature object
check_coords()
: Check if a provided vector with coordinate column names
are valid for the provided data frame
separate_coords()
: Separate coordinates from a single combined column
into two columns
format_coords()
: Format coordinates as numeric values and remove missing
coordinates from a data.frame
has_coords()
: Suggests a coordinate pair by comparing common values to
the column names for a provided data.frame
rev_coords()
: Reverse a vector of coordinate names if the text "lat" or
"y" appears in the first position
coords_to_sf( x, coords = c("lon", "lat"), into = NULL, sep = ",", rev = FALSE, remove_coords = FALSE, crs = 4326, call = caller_env() ) check_coords( x = NULL, coords = NULL, default = c("lon", "lat"), rev = FALSE, call = caller_env() ) rev_coords(coords, pattern = c("lat", "^y"), ignore.case = TRUE) has_coords(x, coords = NULL, value = TRUE) format_coords( x, coords = c("lon", "lat"), keep_missing = FALSE, call = caller_env() ) separate_coords(x, coords, into = c("lon", "lat"), sep = ",")
coords_to_sf( x, coords = c("lon", "lat"), into = NULL, sep = ",", rev = FALSE, remove_coords = FALSE, crs = 4326, call = caller_env() ) check_coords( x = NULL, coords = NULL, default = c("lon", "lat"), rev = FALSE, call = caller_env() ) rev_coords(coords, pattern = c("lat", "^y"), ignore.case = TRUE) has_coords(x, coords = NULL, value = TRUE) format_coords( x, coords = c("lon", "lat"), keep_missing = FALSE, call = caller_env() ) separate_coords(x, coords, into = c("lon", "lat"), sep = ",")
x |
A data.frame with one or more coordinate columns. If coordinates are contained within a single column, coord must be length 1 and a length 2 into parameter must be provided. |
coords |
Coordinate columns for input data.frame or output sf object (if geometry is 'centroid' or 'point') Default: c("lon", "lat"). |
into |
If coords is a single column name with both longitude and
latitude, |
sep |
If coords is a single column name with both longitude and
latitude, |
rev |
If |
remove_coords |
For |
crs |
Coordinate reference system used by the coordinates in the provided data frame. |
call |
The execution environment of a currently
running function, e.g. |
default |
Default coordinate values; defaults to |
pattern |
Pattern passed by |
ignore.case |
If |
value |
If |
keep_missing |
If |
Use st_join_ext()
and dplyr::count()
to count features in x based on
their spatial relationship with y. Very similar to count_sf_ext()
so they
may be merged in the future.
count_features( x = NULL, y = NULL, nm = "data", join = NULL, .id = "name", by = NULL, count = NULL, sort = FALSE, name = NULL, geometry = "y", ... )
count_features( x = NULL, y = NULL, nm = "data", join = NULL, .id = "name", by = NULL, count = NULL, sort = FALSE, name = NULL, geometry = "y", ... )
x |
Data frame or |
y |
Length 1 named |
nm |
Vector of names to use with |
join |
geometry predicate function; defaults to |
.id |
Column name with the values that should be added as a column to
the input |
by |
A character vector of variables to join by passed to
|
count |
Name of column to count. If |
sort |
If |
name |
The name of the new column in the output. If omitted, it will default to |
geometry |
If "y", replace x geometry with y geometry joining based on
by. If by is |
... |
Additional parameters passed to |
An extended version of dplyr::count()
that makes it easier to count the
occurrences of features from data that intersect with features from a second
sf object (set by y) or created by passing x or data to st_make_grid_ext()
.
Similar to count_features()
and the two functions may be combined in the
future.
count_sf_ext( data, x = NULL, y = NULL, join = sf::st_intersects, largest = TRUE, wt = NULL, sort = FALSE, replace_na = FALSE, keep_na = FALSE, lims = NULL, geometry = TRUE, .id = "id", name = NULL, ... )
count_sf_ext( data, x = NULL, y = NULL, join = sf::st_intersects, largest = TRUE, wt = NULL, sort = FALSE, replace_na = FALSE, keep_na = FALSE, lims = NULL, geometry = TRUE, .id = "id", name = NULL, ... )
data |
Data to count in relationship to y |
x |
Optional sf object passed to |
y |
If |
join |
geometry predicate function with the same profile as st_intersects; see details |
largest |
logical; if |
wt |
<
|
sort |
If |
replace_na |
If |
keep_na |
If |
lims |
Optional numeric vector with minimum or both minimum and maximum count values. If provided, any values below the minimum are set to that minimum and any values above the maximum as set to the maximum. If only one value is provided, it is assumed to be a minimum limit. |
geometry |
If |
.id |
A name to use for the cell id column. Defaults to "id". |
name |
The name of the new column in the output. If omitted, it will default to |
... |
Arguments passed on to
|
A sf object or a tibble (if geometry = FALSE
) with a column
counting occurrences of features from data.
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) data <- sf::st_sample(nc, size = 75) # Count data based on nc count <- count_sf_ext(data = data, y = nc, .id = "FIPS") plot(count[, "n"], reset = FALSE) plot(data, col = "gray60", pch = 3, add = TRUE) # Count data based grid created by passing nc to st_make_grid_ext count_grid <- count_sf_ext(data = data, x = nc, .id = "FIPS") plot(count_grid[, "n"], reset = FALSE) plot(data, col = "gray60", pch = 3, add = TRUE)
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) data <- sf::st_sample(nc, size = 75) # Count data based on nc count <- count_sf_ext(data = data, y = nc, .id = "FIPS") plot(count[, "n"], reset = FALSE) plot(data, col = "gray60", pch = 3, add = TRUE) # Count data based grid created by passing nc to st_make_grid_ext count_grid <- count_sf_ext(data = data, x = nc, .id = "FIPS") plot(count_grid[, "n"], reset = FALSE) plot(data, col = "gray60", pch = 3, add = TRUE)
A vector of supported distance units pulled from dist_units
.
dist_unit_options
dist_unit_options
A character vector with 86 names, plural names, aliases, and symbols for distance units.
A subset of units supported by the units package accessible through the
units::valid_udunits()
function.
dist_units
dist_units
A data frame with 33 rows and 12 variables:
symbol
symbols
symbol_aliases
symbol aliases
name_singular
singular names
name_singular_aliases
singular name aliases
name_plural
character plural names
name_plural_aliases
plural name aliases
def
short definition
definition
definition
comment
comment
dimensionless
logical indicator for dimensionless units
source_xml
source XML
unit_opts
character vector with symbols, singular, and plural names for the unit
Get aspect ratio from string or based on specific paper and margins
get_asp( asp = NULL, paper = NULL, orientation = NULL, bbox = NULL, margin = NULL, block_asp = FALSE, allow_null = TRUE, ... )
get_asp( asp = NULL, paper = NULL, orientation = NULL, bbox = NULL, margin = NULL, block_asp = FALSE, allow_null = TRUE, ... )
asp |
Aspect ratio of width to height as a numeric value (e.g. 0.33) or
character (e.g. "1:3"). If numeric, |
paper |
Paper, Default: 'letter'. |
orientation |
Orientation "portrait", "landscape", or "square", Default: 'portrait'. |
bbox |
A bounding box to use to get orientation using |
margin |
A numeric vector or ggplot2 margin object. |
block_asp |
If |
allow_null |
If |
... |
Arguments passed on to
|
A numeric aspect ratio.
An extended version of sf::st_coordinates()
that supports binding
coordinates to the object, optionally dropping the geometry, and returning
wkt or a point on surface (geometry = "surface point") instead of the
centroid.
get_coords( x, coords = NULL, geometry = "centroid", crs = NULL, keep_all = TRUE, drop = TRUE, call = caller_env() ) get_minmax(x, crs = NULL, keep_all = TRUE, drop = TRUE)
get_coords( x, coords = NULL, geometry = "centroid", crs = NULL, keep_all = TRUE, drop = TRUE, call = caller_env() ) get_minmax(x, crs = NULL, keep_all = TRUE, drop = TRUE)
x |
A |
coords |
Column names to use for coordinates in results, Default:
|
geometry |
geometry to use for coordinates "centroid", "surface point",
or alternatively "wkt"; defaults to |
crs |
Coordinate reference system to use for coordinates; defaults to
|
keep_all |
If |
drop |
If |
call |
The execution environment of a currently
running function, e.g. |
get_minmax()
get a bounding box for each feature (or group of features)
appends the xmin, ymin, xmax, and ymax values for each feature to the simple
feature object.
Get the path for a package-specific cache directory with
rappdirs::user_cache_dir()
, check for the existence of a data directory,
optionally create a new directory at the provided path location.
get_data_dir( path = NULL, cache = FALSE, create = TRUE, pkg = "sfext", allow_null = TRUE, recursive = TRUE ) list_data_files( path = NULL, pkg = "sfext", cache = FALSE, fileext = NULL, pattern = NULL, full.names = TRUE, ignore.case = TRUE, ... )
get_data_dir( path = NULL, cache = FALSE, create = TRUE, pkg = "sfext", allow_null = TRUE, recursive = TRUE ) list_data_files( path = NULL, pkg = "sfext", cache = FALSE, fileext = NULL, pattern = NULL, full.names = TRUE, ignore.case = TRUE, ... )
path |
Path to directory for use as data directory. |
cache |
If |
create |
If |
pkg |
Package name; defaults to "sfext" |
allow_null |
If |
recursive |
logical. Should elements of the path other than the
last be created? If true, like the Unix command |
fileext |
If pattern is NULL, fileext is used to set the pattern and filter listed files to those matching the file extension. |
pattern |
an optional regular expression. Only file names which match the regular expression will be returned. |
full.names |
a logical value. If |
ignore.case |
logical. Should pattern-matching be case-insensitive? |
... |
Additional parameters passed to |
This function works in combination with the get_paper()
function to make it
easier to position a map on a page before saving to file. This is primarily
useful when using a map or plot created with ggplot2 as part of a print
document format that is composed outside of R using a page layout application
such as Adobe InDesign.
get_margin( margin = NULL, paper = NULL, orientation = NULL, dist = NULL, unit = "in", block_width = NULL, header = 0, footer = 0 )
get_margin( margin = NULL, paper = NULL, orientation = NULL, dist = NULL, unit = "in", block_width = NULL, header = 0, footer = 0 )
margin |
Margin style (options include "extrawide", "wide", "standard",
"narrow", "none"), Additional "auto" option to generate margin based on
line length is planned but not yet implemented. Default: |
paper |
Paper, Default: 'letter'. |
orientation |
Orientation "portrait", "landscape", or "square", Default: 'portrait'. |
dist |
Margin distance (single value used to all sides), Default: |
unit |
Unit for margin distance, Default: 'in'. |
block_width |
Plot or map width in units. If |
header , footer
|
Header and footer height in units; defaults to 0. Please note: headers and footers are not currently supported for "px" units. |
A ggplot2::margin()
element intended for use with
ggplot2::element_rect()
and the plot.background
theme element.
get_margin("standard") get_margin("none") get_margin(dist = 25, unit = "mm") get_margin(paper = "letter", block_width = 5.5)
get_margin("standard") get_margin("none") get_margin(dist = 25, unit = "mm") get_margin(paper = "letter", block_width = 5.5)
Get measurements for simple feature objects
get_area(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "area") st_area_ext(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "area") get_length(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "length") st_length_ext(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "length") get_dist( x, to, by_element = TRUE, units = NULL, drop = FALSE, keep_all = TRUE, .id = "dist", ... ) st_distance_ext( x, to, by_element = TRUE, units = NULL, drop = FALSE, keep_all = TRUE, .id = "dist", ... ) get_bearing(x, to = NULL, dir = FALSE, keep_all = TRUE, .id = "bearing") st_bearing(x, to = NULL, dir = FALSE, keep_all = TRUE, .id = "bearing")
get_area(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "area") st_area_ext(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "area") get_length(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "length") st_length_ext(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "length") get_dist( x, to, by_element = TRUE, units = NULL, drop = FALSE, keep_all = TRUE, .id = "dist", ... ) st_distance_ext( x, to, by_element = TRUE, units = NULL, drop = FALSE, keep_all = TRUE, .id = "dist", ... ) get_bearing(x, to = NULL, dir = FALSE, keep_all = TRUE, .id = "bearing") st_bearing(x, to = NULL, dir = FALSE, keep_all = TRUE, .id = "bearing")
x |
A |
units |
Units to return for area, length, perimeter, or distance;
Default: |
keep_all |
If |
drop |
If |
.id |
Column name to use for area, line length/perimeter, distance, or bearing. |
to |
A |
by_element |
logical; if |
... |
passed on to s2_distance, s2_distance_matrix, or s2_perimeter |
dir |
Logical indicator whether to include direction in bearing; If
|
Wrapper functions for sf::geos_measures:
get_area()
: Wraps on sf::st_area()
but MULTIPOINT or MULTILINESTRING
geometry is converted to a polygon using sf::st_polygonize()
which is used to
determine the coverage area.
get_length()
: Wraps to sf::st_length()
but POINT and MULTIPOINT geometry is
converted to LINESTRING using as_lines()
. If x has POLYGON geometry,
lwgeom::st_perimeter()
is used to return the perimeter instead of the length.
get_dist()
: Wraps sf::st_distance()
but x is converted to a POINT using
st_center()
and "to" can be a POINT, a sf object that can be converted to a
POINT, or a character vector indicating a point on the overall bounding box
for x.
Additional measurement functions:
get_bearing()
: Wraps geosphere::bearing()
.
Other dist:
compare_dist()
,
convert_dist_scale()
,
convert_dist_units()
,
is_dist_units()
,
sf_bbox_dist()
nc <- read_sf_path(system.file("shape/nc.shp", package = "sf")) # Get area for North Caroline counties get_area(nc[1:2,])$area get_area(nc[1:2,], units = "acres")$area get_area(nc[1:2,], units = "acres", .id = "acreage")$acreage # Get distances for North Caroline counties get_dist(nc[1,], to = c("xmax", "ymax"), units = "mile")$dist get_dist(nc[1,], to = nc[30,], units = "km")$dist # Create a line between two counties nc_line <- as_line(c(as_point(nc[1,]), as_point(nc[30,])), crs = sf::st_crs(nc)) # Get length and bearing of the line get_length(nc_line) get_bearing(nc_line)
nc <- read_sf_path(system.file("shape/nc.shp", package = "sf")) # Get area for North Caroline counties get_area(nc[1:2,])$area get_area(nc[1:2,], units = "acres")$area get_area(nc[1:2,], units = "acres", .id = "acreage")$acreage # Get distances for North Caroline counties get_dist(nc[1,], to = c("xmax", "ymax"), units = "mile")$dist get_dist(nc[1,], to = nc[30,], units = "km")$dist # Create a line between two counties nc_line <- as_line(c(as_point(nc[1,]), as_point(nc[30,])), crs = sf::st_crs(nc)) # Get length and bearing of the line get_length(nc_line) get_bearing(nc_line)
get_paper( paper = "letter", orientation = "portrait", standard = NULL, series = NULL, size = NULL, width = NULL, height = NULL, units = NULL, ncol = 1, nrow = 1, gutter = 0, bbox = NULL, margin = NULL, ... )
get_paper( paper = "letter", orientation = "portrait", standard = NULL, series = NULL, size = NULL, width = NULL, height = NULL, units = NULL, ncol = 1, nrow = 1, gutter = 0, bbox = NULL, margin = NULL, ... )
paper |
Paper, Default: 'letter'. |
orientation |
Orientation "portrait", "landscape", or "square", Default: 'portrait'. |
standard |
Size standard, "ANSI", "ISO", "British Imperial", "JIS", "USPS", "Facebook", "Instagram", or "Twitter". |
series |
Size series (e.g. A), Default: |
size |
Size number (only used for "ISO" and "JIS" series). Standard, series, and size may all be required to return a single paper when using these parameters. |
width , height
|
Width and height in units, Default: |
units |
Paper size units, either "in", "mm", or "px"; defaults to |
ncol , nrow
|
Number of expected columns and rows in paper; used to
determine row_height and section_asp in paper data frame returned by
get_paper if nrow or ncol is greater than 1; defaults to |
gutter |
Gutter distance in units. Gutter is used as the spacing between nrow and columns (variable spacing is not currently supported); defaults to 0. |
bbox |
A bounding box to use to get orientation using |
margin |
A numeric vector or ggplot2 margin object. |
... |
Additional parameters passed to get_margin. plot_width can only be passed in these parameters if paper has only a single row. margin is returned as a list column. |
Use the "paper" parameter (matching name from paper_sizes), standard (optionally including series and size) parameter, or width, height and units. May return multiple paper sizes depending on parameters.
If margin is provided, a block_width, block_height, and block_asp are calculated and included as columns in the returned data frame.
Paper can also be a data frame with "width", "height", "orientation", and "units" columns.
Data frame with one or more paper/image sizes.
get_paper("letter") get_paper(paper = NULL, standard = "ISO", series = "A", size = 4) get_paper(width = 11, height = 17)
get_paper("letter") get_paper(paper = NULL, standard = "ISO", series = "A", size = 4) get_paper(width = 11, height = 17)
This function returns a scale from standard_scales based on a provided name, standard, and/or series.
get_scale(scale = NULL, standard = NULL, series = NULL)
get_scale(scale = NULL, standard = NULL, series = NULL)
scale |
Scale name from |
standard |
Scale standard. Options include "USGS", "Engineering", or "Architectural". |
series |
Map series from |
A tibble based on standard_scales with rows filtered to values that match parameters.
See paper_sizes[paper_sizes$type == "social",]$name
for support image
options.
get_social_image( image = NULL, platform = NULL, format = NULL, orientation = NULL )
get_social_image( image = NULL, platform = NULL, format = NULL, orientation = NULL )
image |
Image size name, Default: |
platform |
Social media platform, "Instagram", "Facebook", or "Twitter",
Default: |
format |
Image format, "post", "story", or "cover", Default: |
orientation |
Image orientation, Default: |
is_dist_units()
: Is x a distance unit object?
is_diff_dist()
: What is the difference between x and y distance?
is_same_dist()
: Is x the same distance as y? or does the bbox of x and bbox
of y have the same x, y, or diagonal distance?
is_shorter()
, is_longer()
: Is x shorter or longer than y?
is_same_area()
: do x and y have the same area?
is_same_units()
: are x and y character strings that represent the same
units or objects that use the same units?
is_dist_units(x) is_diff_dist(x, y, units = NULL) is_same_dist(x, y, dist = NULL, diff = FALSE, call = caller_env(), ...) is_longer(x, y) is_shorter(x, y) get_dist_units(x, allow_null = TRUE, multiple = TRUE, quiet = FALSE) as_dist_units(x, units = NULL, allow_null = FALSE, call = caller_env()) is_diff_area(x, y, units = NULL, combine = TRUE) is_same_area(x, y, units = NULL, combine = TRUE, diff = FALSE, ...) is_same_units(x, y = NULL)
is_dist_units(x) is_diff_dist(x, y, units = NULL) is_same_dist(x, y, dist = NULL, diff = FALSE, call = caller_env(), ...) is_longer(x, y) is_shorter(x, y) get_dist_units(x, allow_null = TRUE, multiple = TRUE, quiet = FALSE) as_dist_units(x, units = NULL, allow_null = FALSE, call = caller_env()) is_diff_area(x, y, units = NULL, combine = TRUE) is_same_area(x, y, units = NULL, combine = TRUE, diff = FALSE, ...) is_same_units(x, y = NULL)
x , y
|
objects to check |
units |
For is_diff_dist, if x and y are both not units objects, use
units; default to |
dist |
type of distance to compare if x and y are |
diff |
If |
call |
The execution environment of a currently
running function, e.g. |
... |
Additional parameters passed to |
allow_null |
If allow_null is |
multiple |
If |
quiet |
If |
combine |
If |
There are two additional functions that support these utility functions:
get_dist_units()
: Get the distance units from x (if x is a sf or units
objects or a character string from dist_unit_options)
as_dist_units()
: Convert x to units using units::as_units
Other dist:
compare_dist()
,
convert_dist_scale()
,
convert_dist_units()
,
get_measurements
,
sf_bbox_dist()
is_geom_type()
extends sf::st_geometry_type()
to return a list with the
standard output ("TYPES") and additional list values with logical vectors
from sf::st_is()
for "POINTS" (passing "POINT" and "MULTIPOINT" as type),
"POLYGONS" (passing "POLYGON", "MULTIPOLYGON"), "LINESTRINGS" ("LINESTRING"
and "MULTILINESTRING"), "GEOMETRYCOLLECTION" and "OTHER".
st_is_ext()
adds a by_geometry argument that passes the results of
sf::st_is()
to all()
if by_geometry is FALSE
.
is_geom_type(x, type = NULL, by_geometry = FALSE, ext = TRUE) is_point(x, by_geometry = FALSE) is_multipoint(x, by_geometry = FALSE) is_line(x, by_geometry = FALSE) is_multiline(x, by_geometry = FALSE) is_polygon(x, by_geometry = FALSE) is_multipolygon(x, by_geometry = FALSE) st_is_ext(x, type = NULL, by_geometry = FALSE)
is_geom_type(x, type = NULL, by_geometry = FALSE, ext = TRUE) is_point(x, by_geometry = FALSE) is_multipoint(x, by_geometry = FALSE) is_line(x, by_geometry = FALSE) is_multiline(x, by_geometry = FALSE) is_polygon(x, by_geometry = FALSE) is_multipolygon(x, by_geometry = FALSE) st_is_ext(x, type = NULL, by_geometry = FALSE)
x |
A |
type |
If "POINT", check if geometry type is POINT. Same for all
available geometry types; not case sensitive; Default: |
by_geometry |
Passed to |
ext |
For |
If ext is FALSE
and type is NULL
, returns vector with geometry types
identical to sf::st_geometry_type()
.
If ext is TRUE
, returns a list and, if type is not NULL
, returns a
logical vector.
What is the class or spatial attributes of this feature?
is_sf(x, ext = FALSE, allow_null = FALSE, allow_list = FALSE) is_sfg(x, allow_null = FALSE) is_sfc(x, allow_null = FALSE) is_bbox(x, allow_null = FALSE, allow_na = FALSE) is_raster(x, allow_null = FALSE) is_sp(x, allow_null = FALSE) is_geo_coords(x, allow_null = FALSE)
is_sf(x, ext = FALSE, allow_null = FALSE, allow_list = FALSE) is_sfg(x, allow_null = FALSE) is_sfc(x, allow_null = FALSE) is_bbox(x, allow_null = FALSE, allow_na = FALSE) is_raster(x, allow_null = FALSE) is_sp(x, allow_null = FALSE) is_geo_coords(x, allow_null = FALSE)
x |
An |
ext |
If |
allow_null |
If |
allow_list |
If |
allow_na |
If |
is_sf: is x a sf
class object?
is_sfc: is x is a sfc
class object?
is_bbox: is x is a bbox
class object?
is_sf_list: is x is a list of sf
class objects (with or without names)?
is_raster: is x a Raster
class object?
is_sp: is x a Spatial
class object of any type?
is_geo_coords: is x likely a geodetic coordinate pair (a length 2 numeric vector, with a max absolute value less than or equal to 180)?
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) is_sf(nc) is_sfc(nc$geometry) is_sf_list(list(nc[1, ], nc[2, ])) is_bbox(sf::st_bbox(nc)) is_wgs84(sf::st_transform(nc, 4326)) is_same_crs(nc, 4267)
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) is_sf(nc) is_sfc(nc$geometry) is_sf_list(list(nc[1, ], nc[2, ])) is_bbox(sf::st_bbox(nc)) is_wgs84(sf::st_transform(nc, 4326)) is_same_crs(nc, 4267)
lonlat_to_sfc( x, range = getOption("sfext.coord_range", c(xmin = -180, ymin = -50, xmax = 180, ymax = 60)), quiet = FALSE, call = parent.frame(), ... )
lonlat_to_sfc( x, range = getOption("sfext.coord_range", c(xmin = -180, ymin = -50, xmax = 180, ymax = 60)), quiet = FALSE, call = parent.frame(), ... )
x |
A length 2 numeric vector with geodetic coordinates in a EPSG:4326 coordinate reference system. |
range |
For |
quiet |
If |
call |
The execution environment of a currently
running function, e.g. |
... |
Arguments passed on to
|
Create a grid with st_make_grid_ext()
and
make_sf_grid_list( x, style = "rect", ncol = 2, nrow = 2, .id = "grid_id", crs = NULL, ... )
make_sf_grid_list( x, style = "rect", ncol = 2, nrow = 2, .id = "grid_id", crs = NULL, ... )
x |
A |
style |
Style of cell to return with options including "rect", "square", "hex", "flat_top_hex", "circle", "circle_offset" |
ncol , nrow
|
Used to set n if either are not |
.id |
A name to use for the cell id column. Defaults to "id". |
crs |
Coordinate reference system of bounding box to return; defaults to
|
... |
Arguments passed on to
|
A wrapper for mapview::mapview()
that drops list columns and makes it
easier to quickly specify a zcol value.
mapview_ext(x, zcol = NULL, remove_na = FALSE, ...) mapview_exif( path = NULL, fileext = "jpeg", popup = TRUE, tooltip = FALSE, images = NULL, width = 320, ... ) mapview_popup_img( images, popup = TRUE, tooltip = FALSE, map = NULL, width = 320, ..., call = caller_env() )
mapview_ext(x, zcol = NULL, remove_na = FALSE, ...) mapview_exif( path = NULL, fileext = "jpeg", popup = TRUE, tooltip = FALSE, images = NULL, width = 320, ... ) mapview_popup_img( images, popup = TRUE, tooltip = FALSE, map = NULL, width = 320, ..., call = caller_env() )
x |
a |
zcol |
attribute name(s) or column number(s) in attribute table of the column(s) to be rendered. See also Details. |
remove_na |
If |
... |
Arguments passed on to |
path |
A path to folder or file. |
fileext |
File extension. Defaults to "jpeg". |
popup |
If |
tooltip |
logical, whether to show image(s) as popup(s) (on click) or tooltip(s) (on hover). |
images |
A simple feature object with columns for the image path/url, image width, and image height. |
width |
the width of the image(s) in pixels. |
map |
an optional existing map to be updated/added to. |
call |
The execution environment of a currently
running function, e.g. |
transform_sf()
is similar to sf::st_transform()
but supports sf, sfc,
or bbox objects as the crs parameter, supports sfg objects (transformed to
sfc), and uses sf::st_set_crs()
if the CRS for the provided object is NA
.
This function does not support bounding box transformations.
relocate_sf_col()
relocates the sf geometry column after specified column
(by default after everything).
rename_sf_col()
a wrapper for sf::st_set_geometry()
that renames the sf
column.
get_sf_col()
returns the "sf_column" attribute.
get_sf_colnames()
returns the column names of a file that can be read
with sf::read_sf()
to allow you to use column names to build a query (or
provide a value for name_col) without reading the whole file.
transform_sf(x, crs = NULL, allow_null = TRUE, ...) relocate_sf_col(x, .after = dplyr::everything()) rename_sf_col(x, sf_col = "geometry") get_sf_col(x = NULL) get_sf_colnames(x = NULL, dsn = NULL, layer = NULL, ...)
transform_sf(x, crs = NULL, allow_null = TRUE, ...) relocate_sf_col(x, .after = dplyr::everything()) rename_sf_col(x, sf_col = "geometry") get_sf_col(x = NULL) get_sf_colnames(x = NULL, dsn = NULL, layer = NULL, ...)
x |
A |
crs |
A coordinate reference system identifier (numeric or character) or
a |
allow_null |
If |
... |
Additional parameters passed to |
.after |
The location to place sf column after; defaults to
|
sf_col |
Name to use for the sf column after renaming; defaults to "geometry". |
dsn |
data source name (interpretation varies by driver - for some
drivers, |
layer |
layer name (varies by driver, may be a file name without
extension); in case |
Used by layer_numbers() function from maplayer package. Supports multiple types of sorting including sorting:
by centroid coordinates ("lon", "lat") appended with get_coords()
by one or more bounding box min or max values ("xmin", "ymin", "xmax",
"ymax") appended with get_minmax()
by distance from the corner, side midpoint, or center of a bounding box ("dist_xmin_ymin", "dist_xmax_ymax", "dist_xmin_ymax", "dist_xmax_ymin", "dist_xmin_ymid", "dist_xmax_ymid", "dist_xmid_ymin", "dist_xmid_ymax", "dist_xmid_ymid")
by distance to a point (or sf
, sfc
, or bbox
object) passed to the to
parameter
For example, in the eastern United States, you can sort and number features from the top-left corner of the map to the bottom right by setting sort to "dist_xmin_ymax" (default).
number_features also supports a range of different numbering styles designed to match the standard enumeration options available in LaTeX.
number_features( x, col = NULL, sort = "dist_xmin_ymax", to = NULL, desc = FALSE, crs = NULL, num_style = "arabic", num_start = 1, suffix = NULL, .id = "number" ) number_sf( x, col = NULL, sort = "dist_xmin_ymax", to = NULL, desc = FALSE, crs = NULL, num_style = "arabic", num_start = 1, suffix = NULL, .id = "number" ) sort_features( x, col = NULL, sort = c("lon", "lat"), to = NULL, desc = FALSE, crs = NULL ) sort_sf( x, col = NULL, sort = c("lon", "lat"), to = NULL, desc = FALSE, crs = NULL )
number_features( x, col = NULL, sort = "dist_xmin_ymax", to = NULL, desc = FALSE, crs = NULL, num_style = "arabic", num_start = 1, suffix = NULL, .id = "number" ) number_sf( x, col = NULL, sort = "dist_xmin_ymax", to = NULL, desc = FALSE, crs = NULL, num_style = "arabic", num_start = 1, suffix = NULL, .id = "number" ) sort_features( x, col = NULL, sort = c("lon", "lat"), to = NULL, desc = FALSE, crs = NULL ) sort_sf( x, col = NULL, sort = c("lon", "lat"), to = NULL, desc = FALSE, crs = NULL )
x |
A |
col |
Group column name, Default: |
sort |
Sort column name, Default: "dist_xmin_ymax". |
to |
A |
desc |
If |
crs |
Coordinate reference to use with |
num_style |
Style of enumeration, either "arabic", "alph", "Alph", "roman", "Roman". |
num_start |
Starting number; defaults to 1. |
suffix |
Character to appended to "number" column. (e.g. "." for "1." or ":" for "1:"). Can also be a character vector with the same length as the number column. |
.id |
Name of the column to use for the feature numbers; defaults to "number". |
A sf
object with a number column ordered by sort values.
Reference table of standard paper, postcard, photo print, social media image
sizes, and playing card sizes for get_paper()
and get_social_image()
functions. Derived from
visioguy/PaperSizes repo, Adobe UK guide to photo sizes
and other sources.
paper_sizes
paper_sizes
A data frame with 123 rows and 9 variables:
name
Name of paper
series
Series
standard
Standard
size
Size in series
units
Units ("in", "mm", or "px") for dimensions
width
Width in units
height
Height in units
orientation
Portrait (width less than height), landscape, or square
type
Type (paper, postcard, print, or social)
A wrapper for rdeck::editor_options()
that automatically converts features
to WGS84.
rdeck_edit(features, mode = rdeck::cur_value(), initial_bounds = NULL, ...) rdeck_select(features, ..., mode = "select") editor_options(mode = rdeck::cur_value(), features = rdeck::cur_value())
rdeck_edit(features, mode = rdeck::cur_value(), initial_bounds = NULL, ...) rdeck_select(features, ..., mode = "select") editor_options(mode = rdeck::cur_value(), features = rdeck::cur_value())
features |
< |
mode |
<
|
initial_bounds |
< |
... |
Arguments passed on to
|
read_sf_exif()
read EXIF data from folder of files and, geometry is TRUE
and coordinate metadata is available, convert the data to a sf object. This
function also assigns a cardinal direction based on the direction metadata
and recodes the orientation metadata.
For write_exif()
the parameters are used to multiple tags with the same
values:
title: Title, IPTC:Headline, IPTC:ObjectName, XMP-dc:Title
description: ImageDescription, XMP-dc:Description, and IPTC:Caption-Abstract
keywords: Keywords, IPTC:Keywords, XMP-dc:Subject
read_sf_exif( path = NULL, fileext = NULL, filetype = NULL, bbox = NULL, sort = NULL, tags = NULL, geometry = TRUE, quiet = TRUE, ... )
read_sf_exif( path = NULL, fileext = NULL, filetype = NULL, bbox = NULL, sort = NULL, tags = NULL, geometry = TRUE, quiet = TRUE, ... )
path |
A path to folder or file. |
fileext , filetype
|
File extension or file type. filetype is used if
fileext is |
bbox |
Bounding box to filter by. |
sort |
Column name for variable to sort by passed to |
tags |
Optional list of EXIF tags to read from files. Must include GPS
tags to create an |
geometry |
If |
quiet |
If |
... |
Additional parameters to pass to |
Other read_write:
read_sf_ext()
## Not run: read_sf_exif( path = system.file("extdata/photos", package = "overedge"), filetype = "jpeg" ) ## End(Not run)
## Not run: read_sf_exif( path = system.file("extdata/photos", package = "overedge"), filetype = "jpeg" ) ## End(Not run)
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. A RDS,
RDA, or RData file Optionally provide a bounding box to filter data (data is
filtered before download or reading into memory where possible).
read_sf_ext(...) read_sf_pkg( data, bbox = NULL, package = NULL, pkg = NULL, fileext = "gpkg", filetype = NULL, ... ) read_sf_path(path, bbox = NULL, ...) read_sf_zip( path, bbox = NULL, exdir = NULL, overwrite = TRUE, unzip = "internal", ... ) read_sf_rdata( path, file = NULL, refhook = NULL, bbox = NULL, .name_repair = "check_unique", ... ) read_sf_query( path, dsn = NULL, bbox = NULL, query = NULL, table = NULL, name = NULL, name_col = NULL, wkt_filter = NULL, zm_drop = FALSE, .name_repair = "check_unique", ... ) read_sf_excel( path, sheet = NULL, combine_sheets = FALSE, bbox = NULL, coords = c("lon", "lat"), from_crs = 4326, geo = FALSE, address = "address", .name_repair = "check_unique", ... ) read_sf_csv( path, url = NULL, bbox = NULL, coords = c("lon", "lat"), from_crs = 4326, geo = FALSE, address = "address", wkt = NULL, .name_repair = "check_unique", show_col_types = FALSE, ... ) read_sf_url(url, bbox = NULL, coords = c("lon", "lat"), ...) read_sf_esri( url, bbox = NULL, where = NULL, name = NULL, name_col = NULL, coords = c("lon", "lat"), from_crs = 4326, .name_repair = "check_unique", ... ) read_sf_felt( url = NULL, bbox = NULL, map_id = NULL, .name_repair = "check_unique", ... ) read_sf_gist(url, id = NULL, bbox = NULL, nth = 1, ...) read_sf_gmap( url, bbox = NULL, layer = NULL, combine_layers = FALSE, zm_drop = TRUE, .name_repair = "check_unique" ) read_sf_download( url, filename, bbox = NULL, path = NULL, filetype = "geojson", prefix = "date", method = "auto", unzip = FALSE, .name_repair = "check_unique", ... ) read_sf_gsheet( url, sheet = NULL, ss = NULL, bbox = NULL, ask = FALSE, coords = c("lon", "lat"), from_crs = 4326, geo = FALSE, address = "address", .name_repair = "check_unique", ... )
read_sf_ext(...) read_sf_pkg( data, bbox = NULL, package = NULL, pkg = NULL, fileext = "gpkg", filetype = NULL, ... ) read_sf_path(path, bbox = NULL, ...) read_sf_zip( path, bbox = NULL, exdir = NULL, overwrite = TRUE, unzip = "internal", ... ) read_sf_rdata( path, file = NULL, refhook = NULL, bbox = NULL, .name_repair = "check_unique", ... ) read_sf_query( path, dsn = NULL, bbox = NULL, query = NULL, table = NULL, name = NULL, name_col = NULL, wkt_filter = NULL, zm_drop = FALSE, .name_repair = "check_unique", ... ) read_sf_excel( path, sheet = NULL, combine_sheets = FALSE, bbox = NULL, coords = c("lon", "lat"), from_crs = 4326, geo = FALSE, address = "address", .name_repair = "check_unique", ... ) read_sf_csv( path, url = NULL, bbox = NULL, coords = c("lon", "lat"), from_crs = 4326, geo = FALSE, address = "address", wkt = NULL, .name_repair = "check_unique", show_col_types = FALSE, ... ) read_sf_url(url, bbox = NULL, coords = c("lon", "lat"), ...) read_sf_esri( url, bbox = NULL, where = NULL, name = NULL, name_col = NULL, coords = c("lon", "lat"), from_crs = 4326, .name_repair = "check_unique", ... ) read_sf_felt( url = NULL, bbox = NULL, map_id = NULL, .name_repair = "check_unique", ... ) read_sf_gist(url, id = NULL, bbox = NULL, nth = 1, ...) read_sf_gmap( url, bbox = NULL, layer = NULL, combine_layers = FALSE, zm_drop = TRUE, .name_repair = "check_unique" ) read_sf_download( url, filename, bbox = NULL, path = NULL, filetype = "geojson", prefix = "date", method = "auto", unzip = FALSE, .name_repair = "check_unique", ... ) read_sf_gsheet( url, sheet = NULL, ss = NULL, bbox = NULL, ask = FALSE, coords = c("lon", "lat"), from_crs = 4326, geo = FALSE, address = "address", .name_repair = "check_unique", ... )
... |
Additional parameters passed to multiple functions; see details. |
data |
Name of a package dataset; used by |
bbox |
A bounding box object; defaults to |
package , pkg
|
Package name; used by |
fileext |
File extension. If supplied to |
filetype |
File type supported by |
path |
A file path. |
exdir |
The directory to extract files to (the equivalent of
|
overwrite |
If |
unzip |
If |
file |
The file path to read from/write to. |
refhook |
A function to handle reference objects. |
.name_repair |
Passed to repair parameter of |
dsn |
data source name (interpretation varies by driver - for some
drivers, |
query |
SQL query to select records; see details |
table |
table can usually be inferred from basename of the data source.
table is used to generate a custom query if both name and name_col are
provided. Use |
name , name_col
|
Name value and name column to use in generated a query
for sources read with |
wkt_filter |
character; WKT representation of a spatial filter (may be used as bounding box, selecting overlapping geometries); see examples |
zm_drop |
If |
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
|
coords |
Character vector with coordinate values. Coordinates must use
the same crs as the |
from_crs |
For |
geo |
If |
address |
Address column name, Default: 'address' |
url |
A url for a spatial data file, tabular data with coordinates, or a
ArcGIS FeatureServer or MapServer to access with |
wkt |
Name of column with well-known text for geometry. Used by
|
show_col_types |
If |
where |
string for where condition. Default is |
map_id |
A Felt map URL, map ID string, or a named list with a id and
type element. If map_id is a list, it must be equivalent to the output from
|
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 |
nth |
For |
layer |
layer name (varies by driver, may be a file name without
extension); in case |
combine_layers , combine_sheets
|
If |
filename |
File name; if filename is |
prefix |
File name prefix. "date" adds a date prefix, "time" adds a
date/time prefix; defaults to |
method |
Method to be used for downloading files. Current
download methods are The method can also be set through the option
|
ss |
Something that identifies a Google Sheet:
Processed through |
ask |
If |
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, CSV file, Excel file, or RDS file (RDA and
RData files supported by read_sf_path()
)
A Google Sheets URL
A public Google Maps URL
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()
read_sf_ext()
is a flexible function where ... are passed to one of the
other read functions depending on the provided parameters. If you are using
more than one parameter, all parameters must be named.
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 read_sf_esri()
) 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()
).
Other read_write:
read_sf_exif()
If x is an sf object, the results include a column with a name matching .id containing the values "SW", "SE", "NE", and "NW" corresponding to the cardinal position of each corner.
sf_bbox_corners(x, .id = "corner", class = "sf")
sf_bbox_corners(x, .id = "corner", class = "sf")
x |
A |
.id |
A name to use for added column with cardinal position of points, Default: 'corner' |
class |
Class of object to return. Must be "sf" (default) or "sfc". |
A sf
with four features (duplicating input feature with new
geometry derived from bounding box) or a length 4 sfc
object with POINT
geometry.
Measure distances (sf_bbox_dist()
, sf_bbox_xdist()
, sf_bbox_ydist()
,
and sf_bbox_diagdist()
)
Convert a diag_ratio value to a distance value if a bbox and diag_ratio are
provided (sf_bbox_diag_ratio_to_dist()
); return NULL
if bbox and
diag_ratio are NULL
Get an aspect ratio or orientation (sf_bbox_asp()
) (counts asp between
0.9 and 1.1 as "square" when tolerance is 0.1) or (sf_bbox_orientation()
)
sf_bbox_dist( bbox, from, to, units = NULL, drop = TRUE, by_element = TRUE, call = caller_env(), ... ) sf_bbox_xdist(bbox, units = NULL, drop = TRUE) sf_bbox_ydist(bbox, units = NULL, drop = TRUE) sf_bbox_diagdist(bbox, units = NULL, drop = TRUE) sf_bbox_diag_ratio_to_dist(bbox, diag_ratio, units = NULL, drop = TRUE) sf_bbox_asp(bbox) sf_bbox_orientation(bbox, tolerance = 0.1, call = caller_env()) sf_bbox_check_fit(bbox, dist)
sf_bbox_dist( bbox, from, to, units = NULL, drop = TRUE, by_element = TRUE, call = caller_env(), ... ) sf_bbox_xdist(bbox, units = NULL, drop = TRUE) sf_bbox_ydist(bbox, units = NULL, drop = TRUE) sf_bbox_diagdist(bbox, units = NULL, drop = TRUE) sf_bbox_diag_ratio_to_dist(bbox, diag_ratio, units = NULL, drop = TRUE) sf_bbox_asp(bbox) sf_bbox_orientation(bbox, tolerance = 0.1, call = caller_env()) sf_bbox_check_fit(bbox, dist)
bbox |
A |
from , to
|
Length 2 character vectors with xy pairs (e.g. c("xmax", "ymax) defining points to measure distance from and to. |
units |
The units to return for sf_bbox_dist. Defaults to NULL. |
drop |
If |
by_element |
logical; if |
call |
The execution environment of a currently
running function, e.g. |
... |
passed on to s2_distance, s2_distance_matrix, or s2_perimeter |
diag_ratio |
Proportion of the diagonal distance (ratio of distance to the full diagonal distance) across the bounding box. |
tolerance |
Numeric value above or below 1 used by
|
dist |
Distance to compare with bounding box for |
Other dist:
compare_dist()
,
convert_dist_scale()
,
convert_dist_units()
,
get_measurements
,
is_dist_units()
Simple bounding box functions that you can use to:
Convert a bounding box to a simple feature object
(sf_bbox_to_sf()
) or simple feature collection (sf_bbox_to_sfc()
)
Transform the coordinate reference system (sf_bbox_transform()
)
Return a point from any of the corners, center, or midpoints
(sf_bbox_point()
)
Convert a bounding box to a SQL style query (sf_bbox_to_lonlat_query()
),
well known text (sf_bbox_to_wkt()
)
Convert a point and a corresponding bounding box into into a npc
(normalised parent coordinates) value with sf_bbox_to_npc()
If sf (>=1.0-17) is installed, sf_bbox_transform()
uses
sf::st_transform()
without converting to a sfc object and back to bbox.
sf_bbox_to_sf(bbox, sf_col = "geometry") sf_bbox_to_sfc(bbox) sf_bbox_transform(bbox, crs = NULL) sf_bbox_point(bbox, point = NULL, crs = NULL, call = caller_env()) sf_bbox_to_wkt(bbox, crs = NULL) sf_bbox_to_lonlat_query(bbox, coords = c("longitude", "latitude"), crs = 4326) sf_bbox_to_npc(bbox, point)
sf_bbox_to_sf(bbox, sf_col = "geometry") sf_bbox_to_sfc(bbox) sf_bbox_transform(bbox, crs = NULL) sf_bbox_point(bbox, point = NULL, crs = NULL, call = caller_env()) sf_bbox_to_wkt(bbox, crs = NULL) sf_bbox_to_lonlat_query(bbox, coords = c("longitude", "latitude"), crs = 4326) sf_bbox_to_npc(bbox, point)
bbox |
A bbox object. |
sf_col |
name to use for geometry column after converting to simple feature object; defaults to "geometry". |
crs |
A coordinate reference system to use for
|
point |
point to find npc coords for center |
call |
The execution environment of a currently
running function, e.g. |
coords |
Column names with coordinates for query. e.g. |
sf object
st_extent() in sfx package
Shift, expand, or contract a bounding box (sf_bbox_shift()
,
sf_bbox_expand()
, sf_bbox_contract()
)
sf_bbox_shift( bbox, nudge_x = 0, nudge_y = 0, side = c("all", "top", "bottom", "left", "right"), dir = NULL, call = caller_env() ) sf_bbox_contract(bbox, nudge_x = 0, nudge_y = 0) sf_bbox_expand(bbox, nudge_x = 0, nudge_y = 0)
sf_bbox_shift( bbox, nudge_x = 0, nudge_y = 0, side = c("all", "top", "bottom", "left", "right"), dir = NULL, call = caller_env() ) sf_bbox_contract(bbox, nudge_x = 0, nudge_y = 0) sf_bbox_expand(bbox, nudge_x = 0, nudge_y = 0)
bbox |
A |
nudge_x , nudge_y
|
Length 1 or 2 numeric vector; unitless. Used by or
passed to |
side |
one or more sides to shift: "top", "bottom", "left", "right", or
"all". Required for |
dir |
If "in", contract the |
call |
The execution environment of a currently
running function, e.g. |
Functions for coercing an object to an sf_list class objects created by
vctrs::new_list_of()
and checking lists of sf objects. Any function with
the allow_list
parameter supports this type of input.
as_sf_list( x, nm = "data", col = NULL, crs = NULL, clean_names = TRUE, .name_repair = "check_unique", call = caller_env() ) new_sf_list( x, nm = "data", col = NULL, clean_names = TRUE, .name_repair = "check_unique", call = caller_env() ) is_sf_list(x, ext = TRUE, allow_null = FALSE) sf_list_rbind(x, ...) map_as_sf_list(x, .f, ...) map_as_sf(x, .f, ...)
as_sf_list( x, nm = "data", col = NULL, crs = NULL, clean_names = TRUE, .name_repair = "check_unique", call = caller_env() ) new_sf_list( x, nm = "data", col = NULL, clean_names = TRUE, .name_repair = "check_unique", call = caller_env() ) is_sf_list(x, ext = TRUE, allow_null = FALSE) sf_list_rbind(x, ...) map_as_sf_list(x, .f, ...) map_as_sf(x, .f, ...)
x |
An |
nm |
For as_sf_list, name(s) for sf list; defaults to "data". If col is provided, the values of the grouping column are used as names. |
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. |
crs |
A character or numeric reference to a coordinate reference system
supported by |
clean_names |
If |
.name_repair |
One of "unique", "universal", or "check_unique". See
|
call |
The execution environment of a currently
running function, e.g. |
ext |
If |
allow_null |
If |
... |
For |
.f |
A function, specified in one of the following ways:
|
sf_to_df()
converts a simple feature object to a data.frame by dropping
geometry or, using get_coords()
, converting geometry to well known text, or
(if the geometry type is not POINT) getting coordinates for a centroid or
point on surface. If an sfc object is provided,the "drop" geometry option is
not supported.
df_to_sf()
converts a data.frame to a simple feature object using a
geometry column (named "geometry"), address column (name matching the address
parameter), well known text column (named "wkt"), or coords (must have
columns matching coords values). Related helper functions include
check_coords()
to suggest the appropriate coordinate column names based on
the column names in the provided data frame; has_coords()
to check if a
data frame has the specified coordinates.
sf_to_df( x, crs = 4326, coords = c("lon", "lat"), geometry = "centroid", keep_all = TRUE ) df_to_sf( x, crs = NULL, coords = c("lon", "lat"), from_crs = 4326, into = NULL, sep = ",", rev = TRUE, remove_coords = FALSE, geo = FALSE, address = "address", y = NULL, by = NULL, ..., as_tibble = TRUE, .name_repair = "unique", call = caller_env() )
sf_to_df( x, crs = 4326, coords = c("lon", "lat"), geometry = "centroid", keep_all = TRUE ) df_to_sf( x, crs = NULL, coords = c("lon", "lat"), from_crs = 4326, into = NULL, sep = ",", rev = TRUE, remove_coords = FALSE, geo = FALSE, address = "address", y = NULL, by = NULL, ..., as_tibble = TRUE, .name_repair = "unique", call = caller_env() )
x |
A |
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"). |
geometry |
Type of geometry to include in data frame. options include "drop", "wkt", "centroid", "point", Default: 'centroid'. |
keep_all |
If |
from_crs |
For |
into |
If coords is a single column name with both longitude and
latitude, |
sep |
If coords is a single column name with both longitude and
latitude, |
rev |
If |
remove_coords |
For |
geo |
If |
address |
Address column name passed to |
y |
A sf object passed as y argument to |
by |
A character vector of variables to join by passed to
|
... |
Other parameters passed onto methods. |
as_tibble |
If |
.name_repair |
Passed to |
call |
The execution environment of a currently
running function, e.g. |
sf_to_df()
returns a data frame with geometry dropped or converted
to wkt or coordinates for the centroid or point on surface; df_to_sf()
returns a simple feature object with POINT geometry.
df_spatial() in the ggspatial package
sf::st_as_sf()
nc <- read_sf_path(system.file("shape/nc.shp", package = "sf")) # Convert a sf object to a data frame nc_df <- sf_to_df(nc) # Convert a data frame to a sf object df_to_sf(nc_df, coords = c("lon", "lat"), remove_coords = TRUE) # If lon and lat values are present in a single column, use the into parameter # to split the values back into separate columns nc_df$xy <- paste(nc_df$lon, nc_df$lat, sep = ",") df_to_sf(nc_df, coords = "xy", into = c("lon", "lat"))
nc <- read_sf_path(system.file("shape/nc.shp", package = "sf")) # Convert a sf object to a data frame nc_df <- sf_to_df(nc) # Convert a data frame to a sf object df_to_sf(nc_df, coords = c("lon", "lat"), remove_coords = TRUE) # If lon and lat values are present in a single column, use the into parameter # to split the values back into separate columns nc_df$xy <- paste(nc_df$lon, nc_df$lat, sep = ",") df_to_sf(nc_df, coords = "xy", into = c("lon", "lat"))
st_bbox_ext()
converts the input to a bounding box with as_bbox()
,
applies a buffer (based on a specified distance or proportion of the diagonal
distance across the bounding box) and adjusts the bounding box aspect ratio
before returning a bounding box (or another class specified by the class
parameter). If the input object is a list or sf_list
object, the function
always returns a list
or sf_list
.
st_bbox_ext( x, dist = NULL, diag_ratio = NULL, asp = NULL, unit = NULL, crs = NULL, class = "bbox", nudge = NULL, allow_null = TRUE, allow_list = TRUE ) st_bbox_asp( x, asp = NULL, class = "bbox", allow_null = TRUE, allow_list = TRUE )
st_bbox_ext( x, dist = NULL, diag_ratio = NULL, asp = NULL, unit = NULL, crs = NULL, class = "bbox", nudge = NULL, allow_null = TRUE, allow_list = TRUE ) st_bbox_asp( x, asp = NULL, class = "bbox", allow_null = TRUE, allow_list = TRUE )
x |
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 |
asp |
Aspect ratio of width to height as a numeric value (e.g. 0.33) or
character (e.g. "1:3"). If numeric, |
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" |
crs |
Coordinate reference system of bounding box to return; defaults to
|
class |
Class of object to return passed to |
nudge |
Passed as to parameter |
allow_null |
If |
allow_list |
If |
st_bbox_asp()
supports aspect ratio adjustments without applying a buffer.
asp can be supplied as a number or a string matching the format of
"width:height". Common aspect ratios include "1:1" (1), "4:6" (0.666),
"8.5:11", "16:9" (1.777).
A bbox
object converted to match the class of the class parameter.
Return an sf object with a buffer based on dist
or a proportion of the
diagonal distance defined by diag_ratio
. If x uses geographic coordinates,
the coordinate reference system is transformed into EPSG:3857 and then
transformed back into the original CRS after the buffer has been applied.
st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, allow_null = TRUE, allow_list = TRUE, ... ) ## Default S3 method: st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, allow_null = TRUE, ... ) ## S3 method for class 'bbox' st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, ... ) ## S3 method for class 'list' st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, allow_null = TRUE, allow_list = TRUE, ... ) ## S3 method for class 'sf_list' st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, allow_null = TRUE, allow_list = TRUE, ... ) st_edge(x, dist = NULL, diag_ratio = NULL, unit = "meter", ...)
st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, allow_null = TRUE, allow_list = TRUE, ... ) ## Default S3 method: st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, allow_null = TRUE, ... ) ## S3 method for class 'bbox' st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, ... ) ## S3 method for class 'list' st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, allow_null = TRUE, allow_list = TRUE, ... ) ## S3 method for class 'sf_list' st_buffer_ext( x, dist = NULL, diag_ratio = NULL, unit = "meter", dist_limits = NULL, end_style = NULL, join_style = NULL, single_side = FALSE, allow_null = TRUE, allow_list = TRUE, ... ) st_edge(x, dist = NULL, diag_ratio = NULL, unit = "meter", ...)
x |
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" |
dist_limits |
Numeric vector of any length (minimum and maximum values
used as lower and upper limits on distance buffer). Units must match the
provided units; defaults to |
end_style |
"round" (default), "flat", or "square" passed to the
endCapStyle parameter of |
join_style |
"round" (default), "mitre", or "bevel" passed to the
joinStyle parameter of |
single_side |
If |
allow_null |
If |
allow_list |
If |
... |
Additional parameters passed to |
st_edge()
is a variation on st_buffer_ext()
where dist or diag_ratio is used to
define the width of the edge to return either outside the existing geometry
(for positive dist values) or inside the existing geometry (for negative dist
values).
Wrapper for sf::st_cast()
that currently supports casting MULTIPOLYGON to
POLYGON or MULTIPOLYGON or POLYGON to POINT or, if simplify = FALSE, can cast
MULTIPOINT to LINESTRING. This is not very different than the basic
functionality of st_cast but further development may improve the utility of
this function.
st_cast_ext(x, to = "POINT", simplify = TRUE, ...)
st_cast_ext(x, to = "POINT", simplify = TRUE, ...)
x |
A |
to |
character; target type, if missing, simplification is tried; when |
simplify |
If |
... |
Arguments passed on to |
Clip based on the corner of the object bounding box.
st_clip( x, clip = NULL, keep = NULL, flip = FALSE, dist = NULL, diag_ratio = NULL, unit = "meter" )
st_clip( x, clip = NULL, keep = NULL, flip = FALSE, dist = NULL, diag_ratio = NULL, unit = "meter" )
x |
|
clip |
Character string describing the part of the area to clip or remove. Options include c("top", "right", "bottom", "left", "topright", "bottomright", "bottomleft", "topleft"). If NULL, the area is not clipped and a full edge can be returned. |
keep |
Alternate way of defining clip (by naming the section to keep). |
flip |
Logical. Default FALSE. If TRUE, than the clip area is kept instead of removed. If keep is provided, flip is automatically set to TRUE. |
dist |
Numeric. Distance to use for the edge. Default NULL meters. Use negative values for an inside edge or positive numbers for an outside edge. |
diag_ratio |
Alternate way to define edge distance. |
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" |
sf
object clipped based on parameters
Make a concave hull around simple feature object by attribute
st_concave_hull_ext( x, by = NULL, centroid = FALSE, ratio = 0.5, allow_holes = FALSE )
st_concave_hull_ext( x, by = NULL, centroid = FALSE, ratio = 0.5, allow_holes = FALSE )
x |
A sf object. |
by |
Column name to use for grouping and combining geometry, Default:
|
centroid |
If |
ratio |
numeric; fraction convex: 1 returns the convex hulls, 0 maximally concave hulls |
allow_holes |
logical; if |
st_dissolve()
dissolves sf and sfc objects. If the input object is an sf
object, any existing grouping variables or added grouping variables passed to
the .by
parameter are included in the output sf data frame.
st_dissolve( x, ..., .by = NULL, .keep = "nest", do_union = TRUE, .data_key = "data", .dissolve_key = "group.comp.id", call = caller_env )
st_dissolve( x, ..., .by = NULL, .keep = "nest", do_union = TRUE, .data_key = "data", .dissolve_key = "group.comp.id", call = caller_env )
x |
A sf or sfc object. If sf object, a grouped data frame is allowed. |
... |
Arguments passed on to
|
.by |
< |
.keep |
Method for handling attributes for input data. By default
("nest"), input data is converted to a nested list column with the name
from |
do_union |
Use |
.data_key |
Passed to |
.dissolve_key |
Used as the column name for the dissolve grouping variable. x can't have any existing columns with this name. |
call |
The execution environment of a currently
running function, e.g. |
st_erase()
extends sf::st_difference()
by unioning the second parameter
by default, checking validity of inputs, and optionally (when flip = TRUE
)
using sf::st_intersection()
instead of sf::st_difference. st_trim()
is
equivalent to st_erase()
with flip set to TRUE
.
st_erase(x, y, flip = FALSE, union = TRUE, combine = FALSE, ...) st_trim(x, y, union = TRUE, combine = FALSE, ...)
st_erase(x, y, flip = FALSE, union = TRUE, combine = FALSE, ...) st_trim(x, y, union = TRUE, combine = FALSE, ...)
x |
A |
y |
A |
flip |
If |
union |
If |
combine |
If |
... |
arguments passed on to s2_options |
nc <- read_sf_ext(system.file("shape/nc.shp", package = "sf")) nc <- st_transform_ext(nc, 3657) plot( st_erase( sf::st_buffer(nc[1, ], 1000), nc[1, ] ), max.plot = 1 ) plot( st_trim( nc, sf::st_buffer(nc[1, ], 2000) ), max.plot = 1 )
nc <- read_sf_ext(system.file("shape/nc.shp", package = "sf")) nc <- st_transform_ext(nc, 3657) plot( st_erase( sf::st_buffer(nc[1, ], 1000), nc[1, ] ), max.plot = 1 ) plot( st_trim( nc, sf::st_buffer(nc[1, ], 2000) ), max.plot = 1 )
Extend sf::st_filter()
to filter a sf list or a sf
, sfc
, or bbox
with
options to crop, trim or erase the geometry of the input object based on a
predicate function. Returns x transformed to match crs if y is NULL
.
st_filter_ext( x, y = NULL, crop = FALSE, trim = FALSE, erase = FALSE, crs = NULL, .predicate = sf::st_intersects, type = NULL, allow_list = TRUE, ... ) st_filter_geom_type(x, type = NULL)
st_filter_ext( x, y = NULL, crop = FALSE, trim = FALSE, erase = FALSE, crs = NULL, .predicate = sf::st_intersects, type = NULL, allow_list = TRUE, ... ) st_filter_geom_type(x, type = NULL)
x , y
|
A |
crop |
If |
trim |
If |
erase |
If |
crs |
Coordinate reference system to return. |
.predicate |
geometry predicate function with the same profile as
|
type |
Geometry type. |
allow_list |
If |
... |
Arguments passed on to |
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) plot( st_filter_ext( nc, nc[c(1:10), ] ), max.plot = 1 ) plot( st_filter_ext( nc, nc[c(1:10), ], crop = TRUE ), max.plot = 1 ) plot( st_filter_ext( nc, nc[c(1:10), ], erase = TRUE ), max.plot = 1 ) plot( st_filter_ext( nc, sf::st_union(nc[c(1:10), ]), .predicate = sf::st_disjoint ), max.plot = 1 ) st_filter_geom_type(nc, "POINT") st_filter_geom_type(nc, "MULTIPOLYGON")
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) plot( st_filter_ext( nc, nc[c(1:10), ] ), max.plot = 1 ) plot( st_filter_ext( nc, nc[c(1:10), ], crop = TRUE ), max.plot = 1 ) plot( st_filter_ext( nc, nc[c(1:10), ], erase = TRUE ), max.plot = 1 ) plot( st_filter_ext( nc, sf::st_union(nc[c(1:10), ]), .predicate = sf::st_disjoint ), max.plot = 1 ) st_filter_geom_type(nc, "POINT") st_filter_geom_type(nc, "MULTIPOLYGON")
st_filter_pct(x, y, pct = NULL, ...) st_filter_pct_area(x, y, pct = NULL) st_filter_pct_length(x, y, pct = NULL)
st_filter_pct(x, y, pct = NULL, ...) st_filter_pct_area(x, y, pct = NULL) st_filter_pct_length(x, y, pct = NULL)
x |
A sf object to filter. |
y |
A sf or sfc object to filter by. |
pct |
Percent of length or area to use as a threshold value for filter. Numeric value of 1 or less. |
... |
Additional parameters. Not used currently. |
A filtered version of the input sf object.
Wrapper for sf::st_join()
that works with sf lists.
st_join_ext(x, y, col = NULL, .id = "name", join = NULL, ...)
st_join_ext(x, y, col = NULL, .id = "name", join = NULL, ...)
x |
A |
y |
An |
col |
Column name used to convert y into a |
.id |
Column name with the values that should be added as a column to
the input |
join |
geometry predicate function; defaults to |
... |
Additional parameters passed to |
Create a grid with an id column and optionally a set number of columns and rows. This documentation is incomplete the function may change.
st_make_grid_ext( x, ..., unit = NULL, crs = NULL, ncol = NULL, nrow = NULL, n = NULL, gutter = 0, desc = FALSE, cellsize = NULL, what = NULL, style = "rect", .id = "id", filter = FALSE, trim = FALSE )
st_make_grid_ext( x, ..., unit = NULL, crs = NULL, ncol = NULL, nrow = NULL, n = NULL, gutter = 0, desc = FALSE, cellsize = NULL, what = NULL, style = "rect", .id = "id", filter = FALSE, trim = FALSE )
x |
A |
... |
Arguments passed on to
|
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" |
crs |
Coordinate reference system of bounding box to return; defaults to
|
ncol , nrow
|
Used to set n if either are not |
n |
If n is NULL and square is |
gutter |
Distance in units between each column cell; gutter effectively serves as a margin as the negative buffer is applied to all cells (including those at the edges of the grid). |
desc |
If TRUE, reverse standard order of cell id numbering; defaults
|
cellsize |
numeric of length 1 or 2 with target cellsize: for square or rectangular cells the width and height, for hexagonal cells the distance between opposite edges (edge length is cellsize/sqrt(3)). A length units object can be passed, or an area unit object with area size of the square or hexagonal cell. |
what |
"polygons", "corners", "centers"; set to centers automatically if style is "circle", "circle_offset" but a buffer is applied to return circular polygons. |
style |
Style of cell to return with options including "rect", "square", "hex", "flat_top_hex", "circle", "circle_offset" |
.id |
A name to use for the cell id column. Defaults to "id". |
filter |
If |
trim |
If |
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) # Make a 2 by 2 grid across a location with a 1000 meter gutter between each cell plot( st_make_grid_ext( x = nc[24, ], dist = 500, unit = "meter", ncol = 2, nrow = 2, gutter = 1000 ) ) # Make a 5 by 5 grid with a 8.5 by 11 aspect ratio filtered to x plot( st_make_grid_ext( x = nc[24, ], asp = 8.5 / 11, ncol = 5, nrow = 5, filter = TRUE ) ) # Make a 4 by 5 grid of circles trimmed to x boundaries plot( st_make_grid_ext( x = nc[24, ], ncol = 4, nrow = 5, style = "circle_offset", trim = TRUE ), max.plot = 1 )
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) # Make a 2 by 2 grid across a location with a 1000 meter gutter between each cell plot( st_make_grid_ext( x = nc[24, ], dist = 500, unit = "meter", ncol = 2, nrow = 2, gutter = 1000 ) ) # Make a 5 by 5 grid with a 8.5 by 11 aspect ratio filtered to x plot( st_make_grid_ext( x = nc[24, ], asp = 8.5 / 11, ncol = 5, nrow = 5, filter = TRUE ) ) # Make a 4 by 5 grid of circles trimmed to x boundaries plot( st_make_grid_ext( x = nc[24, ], ncol = 4, nrow = 5, style = "circle_offset", trim = TRUE ), max.plot = 1 )
Checks if all geometries are already valid and make valid if not
st_make_valid_ext(x, ...)
st_make_valid_ext(x, ...)
x |
object of class |
... |
passed on to s2_options |
Support sf
, sfc
, and bbox
and objects as inputs.
Get the center point for a sf
object
Get a circumscribed circle or inscribed circle in a sf
object
Get a donut for a sf
object (may not work if inscribed = TRUE
)
st_inscribed_square wraps sf::st_inscribed_circle()
but limits the circle
to 1 segment per quadrant (nQuadSegs = 1
) and then rotates the resulting
geometry 45 degrees to provide a (mostly) inscribed square. A different
rotation value can be provided to change the orientation of the shape, e.g.
rotate = -45
to return a diamond shape. st_square()
wraps st_bbox_ext()
with asp = 1
.
st_center(x, class = "list", ext = TRUE, ...) st_circle( x, scale = 1, inscribed = TRUE, dTolerance = 0.01, by_feature = FALSE, use_hull = FALSE, use_lwgeom = FALSE ) st_circumscribed_circle(x, scale = 1, dTolerance = 0, by_feature = FALSE) st_donut(x, width = 0.4, scale = 1, inscribed = FALSE, by_feature = TRUE, ...)
st_center(x, class = "list", ext = TRUE, ...) st_circle( x, scale = 1, inscribed = TRUE, dTolerance = 0.01, by_feature = FALSE, use_hull = FALSE, use_lwgeom = FALSE ) st_circumscribed_circle(x, scale = 1, dTolerance = 0, by_feature = FALSE) st_donut(x, width = 0.4, scale = 1, inscribed = FALSE, by_feature = TRUE, ...)
x |
A |
class |
Class to return for |
ext |
If |
... |
Additional parameters passed to |
scale |
For |
inscribed |
If |
dTolerance |
numeric; tolerance parameter, specified for all or for each
feature geometry. If you run |
by_feature |
For |
use_hull |
For |
use_lwgeom |
If |
width |
Donut width as proportion of outer size. |
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, crs = 3857) plot(nc, max.plot = 1) plot(st_circumscribed_circle(nc, by_feature = FALSE), max.plot = 1) plot(st_circle(nc, by_feature = FALSE), max.plot = 1, add = TRUE) plot(st_donut(nc[1:10,], by_feature = TRUE), max.plot = 1)
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, crs = 3857) plot(nc, max.plot = 1) plot(st_circumscribed_circle(nc, by_feature = FALSE), max.plot = 1) plot(st_circle(nc, by_feature = FALSE), max.plot = 1, add = TRUE) plot(st_donut(nc[1:10,], by_feature = TRUE), max.plot = 1)
Nudge, move, or shift a sf
, sfc
, or bbox
object to the center of
another feature and/or by a set distance.
st_nudge( x, to = NULL, nudge_y = 0, nudge_x = 0, unit = NULL, scale = 1, rotate = 0, crs = NULL ) ## Default S3 method: st_nudge( x, to = NULL, nudge_y = 0, nudge_x = 0, unit = NULL, scale = 1, rotate = 0, crs = NULL ) ## S3 method for class 'bbox' st_nudge(x, ...) ## S3 method for class 'sf' st_nudge(x, ...)
st_nudge( x, to = NULL, nudge_y = 0, nudge_x = 0, unit = NULL, scale = 1, rotate = 0, crs = NULL ) ## Default S3 method: st_nudge( x, to = NULL, nudge_y = 0, nudge_x = 0, unit = NULL, scale = 1, rotate = 0, crs = NULL ) ## S3 method for class 'bbox' st_nudge(x, ...) ## S3 method for class 'sf' st_nudge(x, ...)
x |
Object to convert to an sf, sfc, bbox or a sf list object. |
to |
sf object to use as new center for x or length 2 numeric vector with the nudge_y and nudge_x distance (in that order). |
nudge_y , nudge_x
|
Distance to nudge geometry in unit. If unit is |
unit |
Units for nudge_y and nudge_x distance (also used if to is numeric). |
scale |
numeric; scale factor, Default: 1 |
rotate |
numeric; degrees to rotate (-360 to 360), Default: 0 |
crs |
Coordinate reference system for |
... |
Additional parameters passed to as_sf, as_sfc, as_bbox, or as_sf_list |
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, crs = 3857) plot(sf::st_union(st_nudge(nc, to = nc[1, ]), nc), max.plot = 1)
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, crs = 3857) plot(sf::st_union(st_nudge(nc, to = nc[1, ]), nc), max.plot = 1)
Scale or rotate a simple feature or bounding box object using affine transformations.
st_scale_rotate(x, scale = 1, rotate = 0, call = caller_env())
st_scale_rotate(x, scale = 1, rotate = 0, call = caller_env())
x |
A |
scale |
numeric; scale factor, Default: 1 |
rotate |
numeric; degrees to rotate (-360 to 360), Default: 0 |
call |
The execution environment of a currently
running function, e.g. |
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, crs = 3857) plot(st_scale_rotate(nc, scale = 0.75, rotate = 15), max.plot = 1)
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, crs = 3857) plot(st_scale_rotate(nc, scale = 0.75, rotate = 15), max.plot = 1)
Get a circumscribed square or approximate inscribed square in a sf
object.
If inscribed is TRUE
, the square geometry returned may not be contained
wholly within the original geometry. The inscribed square is created from the
bounding box of an inscribed circle rotated 45 degrees.
st_square( x, scale = 1, rotate = 0, inscribed = FALSE, by_feature = FALSE, call = caller_env() ) ## Default S3 method: st_square(x, ...) ## S3 method for class 'sfc' st_square( x, scale = 1, rotate = 0, inscribed = FALSE, by_feature = FALSE, call = caller_env() ) ## S3 method for class 'sf' st_square(x, ..., by_feature = FALSE) ## S3 method for class 'bbox' st_square(x, ...) st_inscribed_square(x, scale = 1, rotate = 0, by_feature = FALSE)
st_square( x, scale = 1, rotate = 0, inscribed = FALSE, by_feature = FALSE, call = caller_env() ) ## Default S3 method: st_square(x, ...) ## S3 method for class 'sfc' st_square( x, scale = 1, rotate = 0, inscribed = FALSE, by_feature = FALSE, call = caller_env() ) ## S3 method for class 'sf' st_square(x, ..., by_feature = FALSE) ## S3 method for class 'bbox' st_square(x, ...) st_inscribed_square(x, scale = 1, rotate = 0, by_feature = FALSE)
x |
A |
scale |
numeric; scale factor, Default: 1 |
rotate |
numeric; degrees to rotate (-360 to 360), Default: 0 |
inscribed |
If |
by_feature |
If |
call |
The execution environment of a currently
running function, e.g. |
... |
Additional parameters passed to |
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, crs = 3857) plot(st_square(nc), max.plot = 1) plot(st_square(nc[1:10, ], by_feature = TRUE), max.plot = 1)
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc <- sf::st_transform(nc, crs = 3857) plot(st_square(nc), max.plot = 1) plot(st_square(nc[1:10, ], by_feature = TRUE), max.plot = 1)
This function wraps sf::st_transform()
but supports a wider range of input
objects and, using the as_sf_class()
function, returns a wider range of
objects. Typically, takes a sf
, sfc
, or bbox
object and transform to
coordinate reference system to match the value of crs or the object provided
to crs. If x
is a data.frame or if x
is NULL
and allow_null
is TRUE
(defaults to FALSE
) it is returned as is.
st_transform_ext( x, crs = NULL, class = NULL, rotate = 0, allow_null = FALSE, allow_list = TRUE ) st_omerc(x, rotate = 0) st_wgs84(x)
st_transform_ext( x, crs = NULL, class = NULL, rotate = 0, allow_null = FALSE, allow_list = TRUE ) st_omerc(x, rotate = 0) st_wgs84(x)
x |
An |
crs |
A character or numeric reference to a coordinate reference system
supported by |
class |
Class of object to return ( |
rotate |
If rotate is greater or less than 0, |
allow_null |
If |
allow_list |
If |
An sf
, sfc
, or bbox
object transformed to a new coordinate
reference system.
sf::st_transform()
,sf::st_crs()
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc_bbox <- sf::st_bbox(nc) nc_3857 <- st_transform_ext(nc, 3857) st_transform_ext(nc_bbox, crs = 4326) sf::st_crs(st_transform_ext(nc_3857, crs = nc))$input sf::st_crs(st_wgs84(nc_3857))$input
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf")) nc_bbox <- sf::st_bbox(nc) nc_3857 <- st_transform_ext(nc, 3857) st_transform_ext(nc_bbox, crs = 4326) sf::st_crs(st_transform_ext(nc_3857, crs = nc))$input sf::st_crs(st_wgs84(nc_3857))$input
Wrapper for sf::st_union()
supporting the additional feature of a combined
name column collapsed into a single vector with cli::pluralize()
.
st_union_by()
wraps dplyr::group_by()
and dplyr::summarise()
to allow
quick unioning geometry by the passed parameters.
st_union_ext( x, y = NULL, name_col = "name", .sf_col = NULL, label = NULL, ext = TRUE, ... ) st_union_by(x, ..., .sf_col = NULL)
st_union_ext( x, y = NULL, name_col = "name", .sf_col = NULL, label = NULL, ext = TRUE, ... ) st_union_by(x, ..., .sf_col = NULL)
x |
A |
y |
A |
name_col |
Column name to collapse into new name_col value, Default: 'name' |
.sf_col |
Geometry column name to use if x is an |
label |
Length 1 character vector used if name_col is |
ext |
If |
... |
Additional parameters passed to |
A sfc
object if y is NULL
and ext is FALSE
. A tibble sf if x is
a sf object and y is NULL
. If y is provided, st_union_ext()
is
identical to sf::st_union()
nc <- read_sf_path(system.file("shape/nc.shp", package = "sf")) nc_union <- st_union_ext(nc[10:15,], name_col = "NAME") nc_union plot(nc_union)
nc <- read_sf_path(system.file("shape/nc.shp", package = "sf")) nc_union <- st_union_ext(nc[10:15,], name_col = "NAME") nc_union plot(nc_union)
Standard map scales derived from USGS 2002 report on map scales https://pubs.usgs.gov/fs/2002/0015/report.pdf
standard_scales
standard_scales
A data frame with 36 rows and 16 variables:
scale
Scale name
standard
Standard (USGS, architectural, or engineering)
series
Series name (USGS map scales only)
actual_ft
Scale distance for 1 ft actual.
actual_ft_unit
Unit of scale for 1 ft actual.
scale_in
Actual distance for 1 in scale.
scale_in_unit
Unit of actual distance for 1 in scale.
scale_in_accuracy
Accuracy of 1 in scale (approximate or exact)
scale_cm
Actual distance for 1 cm scale.
scale_cm_unit
Unit of actual distance for 1 cm scale.
scale_cm_accuracy
Accuracy of 1 cm scale (approximate or exact)
size_latlon
Standard size in latitude/longitude
size_latlon_unit
Unit of latitude/longitude size (minutes or degrees)
area_approx
Approximate actual area
area_approx_unit
Approximate area unit
series_status
Series status (select USGS map series are "abandoned")
Common architectural and engineering scales derived from FEMA guide to using scales https://www.usfa.fema.gov/downloads/pdf/nfa/engineer-architect-scales.pdf
Extends read_sf_exif()
and filenamr::write_exif()
write_exif_from( path, fileext = NULL, filetype = NULL, from, .id = "name", tag = "keywords", join = NULL, overwrite = TRUE )
write_exif_from( path, fileext = NULL, filetype = NULL, from, .id = "name", tag = "keywords", join = NULL, overwrite = TRUE )
path |
A path to folder or file. |
fileext , filetype
|
File extension or file type. filetype is used if
fileext is |
from |
A sf object or list of sf objects where each object has a column with a name matching the .id parameter. The attribute value in this column are used to assign the tag parameter to the file at the provided path based on the spatial relationship set by join. For example, from may be boundary data used to assign keywords based on photo locations. |
.id |
Column name in from with the values to use for tag values. |
tag |
EXIF tag to update, supported options include "keywords", "title", or "description". |
join |
geometry predicate function; defaults to |
overwrite |
If |
The write_sf_ext and write_sf_cache helper functions wrap the sf::write_sf()
function to provide some additional options including consistent file naming
with make_filename()
and features including:
write_sf_ext( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, fileext = NULL, filetype = NULL, description = NULL, path = NULL, cache = FALSE, pkg = "sfext", overwrite = FALSE, onefile = FALSE, ... ) write_sf_list( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, fileext = NULL, filetype = NULL, path = NULL, overwrite = FALSE, onefile = FALSE, cache = FALSE, ... ) write_sf_cache( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, fileext = NULL, filetype = NULL, data_dir = NULL, pkg = "sfext", overwrite = FALSE, create = TRUE, ... ) write_sf_gist( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, fileext = "geojson", filetype = NULL, description = NULL, public = TRUE, browse = FALSE, token = Sys.getenv("GITHUB_PAT") ) write_sf_gsheet( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, sheet = 1, ask = FALSE, key = NULL, ... )
write_sf_ext( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, fileext = NULL, filetype = NULL, description = NULL, path = NULL, cache = FALSE, pkg = "sfext", overwrite = FALSE, onefile = FALSE, ... ) write_sf_list( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, fileext = NULL, filetype = NULL, path = NULL, overwrite = FALSE, onefile = FALSE, cache = FALSE, ... ) write_sf_cache( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, fileext = NULL, filetype = NULL, data_dir = NULL, pkg = "sfext", overwrite = FALSE, create = TRUE, ... ) write_sf_gist( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, fileext = "geojson", filetype = NULL, description = NULL, public = TRUE, browse = FALSE, token = Sys.getenv("GITHUB_PAT") ) write_sf_gsheet( data, name = NULL, label = NULL, prefix = NULL, postfix = NULL, filename = NULL, sheet = 1, ask = FALSE, key = NULL, ... )
data |
A |
name |
Name to make file name converted to snake case with
|
label |
Label to combine with name converted to snake case with
|
prefix |
File name prefix. "date" adds a date prefix, "time" adds a
date/time prefix; defaults to |
postfix |
File name postfix; defaults to |
filename , fileext , filetype
|
File name and/or file extension to write.
filetype is superseded in favor of fileext. Both are optional if path
includes filename and type, e.g. "~/Documents/data.geojson". fileext can be
provided as part of the filename, e.g. "data.geojson". If a filename
includes a file extensions and a separate fileext is also provided, the
separate fileext parameter is used. Supported file extensions include
"csv", "xlsx", "gsheet" (writes a Google Sheet), "rda", or any fileext
supported by the available drivers (use |
description |
(character) Brief description of gist (optional) |
path |
Path to file or data directory. Optional. If path includes a file
extension and filename and fileext are both |
cache |
If |
pkg |
The name of the package cache directory to use for
write_sf_cache or write_sf_ext if |
overwrite |
Logical. Default |
onefile |
If |
... |
If data is an sf object and the fileext is "csv" or "xlsx", the
... parameters are passed to |
data_dir |
cache data directory, defaults to |
create |
If |
public |
(logical) Whether gist is public (default: TRUE) |
browse |
(logical) To open newly create gist in default browser (default: TRUE) |
token |
A personal access token on GitHub with permission to create gists; defaults to Sys.getenv("GITHUB_PAT") |
sheet |
Sheet to write into, in the sense of "worksheet" or "tab". You can identify a sheet by name, with a string, or by position, with a number. |
ask |
If |
key |
If ask is |
If fileext is "csv", "xlsx", or "gsheet" the file is converted to a
dataframe using df_to_sf()
If the data is not an sf
object and none of these filenames are provided,
the user is prompted to save the file as an rda file with readr::write_rds()
.
If cache is TRUE
use write_sf_cache()
to cache file after writing a copy to
the path provided.
If data is a named sf list, pass the name of each sf object in the list to the name parameter and keep all other parameters consistent to write a file for each object in the list. No ... parameters are passed if data is an sf list.
write_sf_svg()
uses plot()
and svg()
to create a simple plot of an sf
object geometry. This function is convenient for working with designers or
other collaborators interested in using spatial data outside of R or a
desktop GIS application.
write_sf_svg(data, filename = NULL, path = NULL, ..., width = 10, height = 10)
write_sf_svg(data, filename = NULL, path = NULL, ..., width = 10, height = 10)
data |
A sf object to save as a svg file. |
filename |
the file path of the output file(s).
The page number is substituted if a C integer format is included in
the character string, as in the default. (Depending on the platform,
the result must be less
than |
path |
File path to combine with filename. Optional if filename is provided. filename is optional if path includes a svg file extension. |
... |
Arguments passed on to
|
width |
the width of the device in inches. |
height |
the height of the device in inches. |