get_measurements | R Documentation |
Get measurements for simple feature objects
get_area(x, units = NULL, keep_all = TRUE, drop = FALSE, .id = "area") get_length(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", ... ) get_bearing(x, 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 or s2_distance_matrix |
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:
convert_dist_scale()
,
convert_dist_units()
,
is_dist_units()
,
sf_bbox_misc
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 = nc) # Get length and bearing of the line get_length(nc_line) get_bearing(nc_line)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.