Title: | Lightweight Well-Known Geometry Parsing |
---|---|
Description: | Provides a minimal R and C++ API for parsing well-known binary and well-known text representation of geometries to and from R-native formats. Well-known binary is compact and fast to parse; well-known text is human-readable and is useful for writing tests. These formats are useful in R only if the information they contain can be accessed in R, for which high-performance functions are provided here. |
Authors: | Dewey Dunnington [aut, cre] |
Maintainer: | Dewey Dunnington <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.9.2.9000 |
Built: | 2024-09-05 20:45:56 UTC |
Source: | https://github.com/paleolimbot/wk |
2D Circle Vectors
crc(x = double(), y = double(), r = double(), crs = wk_crs_auto()) as_crc(x, ...) ## S3 method for class 'wk_crc' as_crc(x, ...) ## S3 method for class 'matrix' as_crc(x, ..., crs = NULL) ## S3 method for class 'data.frame' as_crc(x, ..., crs = NULL)
crc(x = double(), y = double(), r = double(), crs = wk_crs_auto()) as_crc(x, ...) ## S3 method for class 'wk_crc' as_crc(x, ...) ## S3 method for class 'matrix' as_crc(x, ..., crs = NULL) ## S3 method for class 'data.frame' as_crc(x, ..., crs = NULL)
x , y
|
Coordinates of the center |
r |
Circle radius |
crs |
A value to be propagated as the CRS for this vector. |
... |
Extra arguments passed to |
A vector along the recycled length of bounds.
crc(1, 2, 3)
crc(1, 2, 3)
Circle accessors
crc_x(x) crc_y(x) crc_center(x) crc_r(x)
crc_x(x) crc_y(x) crc_center(x) crc_r(x)
x |
A |
Components of the crc()
vector
x <- crc(1, 2, r = 3) crc_x(x) crc_y(x) crc_r(x) crc_center(x)
x <- crc(1, 2, r = 3) crc_x(x) crc_y(x) crc_r(x) crc_center(x)
grd()
objects are just an array (any object with more than
two dim()
s) and a bounding box (a rct()
, which may or
may not have a wk_crs()
attached). The ordering of the dimensions
is y (indices increasing downwards), x (indices increasing to the right).
This follows the ordering of as.raster()
/rasterImage()
and aligns
with the printing of matrices.
grd( bbox = NULL, nx = NULL, ny = NULL, dx = NULL, dy = NULL, type = c("polygons", "corners", "centers") ) grd_rct(data, bbox = rct(0, 0, dim(data)[2], dim(data)[1])) grd_xy(data, bbox = rct(0, 0, dim(data)[2] - 1, dim(data)[1] - 1)) as_grd_rct(x, ...) ## S3 method for class 'wk_grd_rct' as_grd_rct(x, ...) ## S3 method for class 'wk_grd_xy' as_grd_rct(x, ...) as_grd_xy(x, ...) ## S3 method for class 'wk_grd_xy' as_grd_xy(x, ...) ## S3 method for class 'wk_grd_rct' as_grd_xy(x, ...)
grd( bbox = NULL, nx = NULL, ny = NULL, dx = NULL, dy = NULL, type = c("polygons", "corners", "centers") ) grd_rct(data, bbox = rct(0, 0, dim(data)[2], dim(data)[1])) grd_xy(data, bbox = rct(0, 0, dim(data)[2] - 1, dim(data)[1] - 1)) as_grd_rct(x, ...) ## S3 method for class 'wk_grd_rct' as_grd_rct(x, ...) ## S3 method for class 'wk_grd_xy' as_grd_rct(x, ...) as_grd_xy(x, ...) ## S3 method for class 'wk_grd_xy' as_grd_xy(x, ...) ## S3 method for class 'wk_grd_rct' as_grd_xy(x, ...)
bbox |
A |
nx , ny , dx , dy
|
Either a number of cells in the x- and y- directions
or delta in the x- and y-directions (in which case |
type |
Use "polygons" to return a grid whose objects can be
represented using an |
data |
An object with two or more dimensions. Most usefully, a matrix. |
x |
An object to convert to a grid |
... |
Passed to S3 methods |
grd()
returns a grd_rct()
for type == "polygons
or
a grd_xy()
otherwise.
grd_rct()
returns an object of class "wk_grd_rct".
grd_xy()
returns an object of class "wk_grd_xy".
# create a grid with no data (just for coordinates) (grid <- grd(nx = 2, ny = 2)) as_rct(grid) as_xy(grid) plot(grid, border = "black") # more usefully, wraps a matrix or nd array + bbox # approx volcano in New Zealand Transverse Mercator bbox <- rct( 5917000, 1757000 + 870, 5917000 + 610, 1757000, crs = "EPSG:2193" ) (grid <- grd_rct(volcano, bbox)) # these come with a reasonable default plot method for matrix data plot(grid) # you can set the data or the bounding box after creation grid$bbox <- rct(0, 0, 1, 1) # subset by indices or rct plot(grid[1:2, 1:2]) plot(grid[c(start = NA, stop = NA, step = 2), c(start = NA, stop = NA, step = 2)]) plot(grid[rct(0, 0, 0.5, 0.5)])
# create a grid with no data (just for coordinates) (grid <- grd(nx = 2, ny = 2)) as_rct(grid) as_xy(grid) plot(grid, border = "black") # more usefully, wraps a matrix or nd array + bbox # approx volcano in New Zealand Transverse Mercator bbox <- rct( 5917000, 1757000 + 870, 5917000 + 610, 1757000, crs = "EPSG:2193" ) (grid <- grd_rct(volcano, bbox)) # these come with a reasonable default plot method for matrix data plot(grid) # you can set the data or the bounding box after creation grid$bbox <- rct(0, 0, 1, 1) # subset by indices or rct plot(grid[1:2, 1:2]) plot(grid[c(start = NA, stop = NA, step = 2), c(start = NA, stop = NA, step = 2)]) plot(grid[rct(0, 0, 0.5, 0.5)])
Grid cell operators
grd_cell(grid, point, ..., snap = grd_snap_next) grd_cell_range( grid, bbox = wk_bbox(grid), ..., step = 1L, snap = grd_snap_next ) grd_cell_rct(grid, i, j = NULL, ...) ## S3 method for class 'wk_grd_rct' grd_cell_rct(grid, i, j = NULL, ..., out_of_bounds = "keep") ## S3 method for class 'wk_grd_xy' grd_cell_rct(grid, i, j = NULL, ..., out_of_bounds = "keep") grd_cell_xy(grid, i, j = NULL, ...) ## S3 method for class 'wk_grd_rct' grd_cell_xy(grid, i, j = NULL, ..., out_of_bounds = "keep") ## S3 method for class 'wk_grd_xy' grd_cell_xy(grid, i, j = NULL, ..., out_of_bounds = "keep")
grd_cell(grid, point, ..., snap = grd_snap_next) grd_cell_range( grid, bbox = wk_bbox(grid), ..., step = 1L, snap = grd_snap_next ) grd_cell_rct(grid, i, j = NULL, ...) ## S3 method for class 'wk_grd_rct' grd_cell_rct(grid, i, j = NULL, ..., out_of_bounds = "keep") ## S3 method for class 'wk_grd_xy' grd_cell_rct(grid, i, j = NULL, ..., out_of_bounds = "keep") grd_cell_xy(grid, i, j = NULL, ...) ## S3 method for class 'wk_grd_rct' grd_cell_xy(grid, i, j = NULL, ..., out_of_bounds = "keep") ## S3 method for class 'wk_grd_xy' grd_cell_xy(grid, i, j = NULL, ..., out_of_bounds = "keep")
grid |
A |
point |
A handleable of points. |
... |
Unused |
snap |
A function that transforms real-valued indices to integer
indices (e.g., |
bbox |
An |
step |
The difference between adjascent indices in the output |
i , j
|
1-based index values. |
out_of_bounds |
One of 'keep', 'censor', 'discard', or 'squish' |
grd_cell()
: returns a list(i, j)
of index values corresponding
to the input points and adjusted according to snap
. Index values
will be outside dim(grid)
for points outside wk_bbox(grid)
including
negative values.
grd_cell_range()
returns a slice describing the range of indices
in the i
and j
directions.
grd_cell_rct()
returns a rct()
of the cell extent at i, j
.
grd_cell_xy()
returns a xy()
of the cell center at i, j
.
grid <- grd(nx = 3, ny = 2) grd_cell(grid, xy(0.5, 0.5)) grd_cell_range(grid, grid$bbox) grd_cell_rct(grid, 1, 1) grd_cell_xy(grid, 1, 1)
grid <- grd(nx = 3, ny = 2) grd_cell(grid, xy(0.5, 0.5)) grd_cell_range(grid, grid$bbox) grd_cell_rct(grid, 1, 1) grd_cell_xy(grid, 1, 1)
Unlike grd_subset()
, which subsets like a matrix, grd_extract()
returns
values.
grd_extract(grid, i = NULL, j = NULL) grd_extract_nearest(grid, point, out_of_bounds = c("censor", "squish")) grd_data_extract(grid_data, i = NULL, j = NULL)
grd_extract(grid, i = NULL, j = NULL) grd_extract_nearest(grid, point, out_of_bounds = c("censor", "squish")) grd_data_extract(grid_data, i = NULL, j = NULL)
grid |
A |
i , j
|
Index values as in |
point |
A handleable of points. |
out_of_bounds |
One of 'keep', 'censor', 'discard', or 'squish' |
grid_data |
The |
A matrix or vector with two fewer dimensions than the input.
These functions can be used in grd_cell()
and
grd_cell_range()
. These functions differ in the way
they round 0.5: grd_snap_next()
always rounds up
and grd_snap_previous()
always rounds down. You can
also use floor()
and ceiling()
as index
snap functions.
grd_snap_next(x) grd_snap_previous(x)
grd_snap_next(x) grd_snap_previous(x)
x |
A vector of rescaled but non-integer indices |
A vector of integer indices
grd_snap_next(seq(0, 2, 0.25)) grd_snap_previous(seq(0, 2, 0.25))
grd_snap_next(seq(0, 2, 0.25)) grd_snap_previous(seq(0, 2, 0.25))
The grd_subset()
method handles the subsetting of a grd()
in x-y space. Ordering of indices is not considered and logical
indies are recycled silently along dimensions. The result of
a grd_subset()
is always a grd()
of the same type whose
relationship to x-y space has not changed.
grd_subset(grid, i = NULL, j = NULL, ...) grd_crop(grid, bbox, ..., step = 1L, snap = NULL) grd_extend(grid, bbox, ..., step = 1L, snap = NULL) ## S3 method for class 'wk_grd_rct' grd_crop(grid, bbox, ..., step = 1L, snap = NULL) ## S3 method for class 'wk_grd_xy' grd_crop(grid, bbox, ..., step = 1L, snap = NULL) ## S3 method for class 'wk_grd_rct' grd_extend(grid, bbox, ..., step = 1L, snap = NULL) ## S3 method for class 'wk_grd_xy' grd_extend(grid, bbox, ..., step = 1L, snap = NULL) grd_data_subset(grid_data, i = NULL, j = NULL)
grd_subset(grid, i = NULL, j = NULL, ...) grd_crop(grid, bbox, ..., step = 1L, snap = NULL) grd_extend(grid, bbox, ..., step = 1L, snap = NULL) ## S3 method for class 'wk_grd_rct' grd_crop(grid, bbox, ..., step = 1L, snap = NULL) ## S3 method for class 'wk_grd_xy' grd_crop(grid, bbox, ..., step = 1L, snap = NULL) ## S3 method for class 'wk_grd_rct' grd_extend(grid, bbox, ..., step = 1L, snap = NULL) ## S3 method for class 'wk_grd_xy' grd_extend(grid, bbox, ..., step = 1L, snap = NULL) grd_data_subset(grid_data, i = NULL, j = NULL)
grid |
A |
i , j
|
1-based index values. |
... |
Passed to subset methods |
bbox |
An |
step |
The difference between adjascent indices in the output |
snap |
A function that transforms real-valued indices to integer
indices (e.g., |
grid_data |
The |
A modified grid
whose cell centres have not changed location
as a result of the subset.
grid <- grd_rct(volcano) grd_subset(grid, 1:20, 1:30) grd_crop(grid, rct(-10, -10, 10, 10)) grd_extend(grid, rct(-10, -10, 10, 10))
grid <- grd_rct(volcano) grd_subset(grid, 1:20, 1:30) grd_crop(grid, rct(-10, -10, 10, 10)) grd_extend(grid, rct(-10, -10, 10, 10))
Grid information
grd_summary(grid)
grd_summary(grid)
grid |
A |
grd_summary()
returns a list()
with components
xmin
, ymin
, xmax
, ymax
,
nx
, ny
, dx
, dy
, width
, and height
.
grd_summary(grd(nx = 3, ny = 2))
grd_summary(grd(nx = 3, ny = 2))
Unlike grd_tile_template()
, which returns a grd()
whose elements are
the boundaries of the specified tiles with no data attached, grd_tile()
returns the actual tile with the data.
grd_tile(grid, level, i, j = NULL) ## S3 method for class 'wk_grd_rct' grd_tile(grid, level, i, j = NULL) ## S3 method for class 'wk_grd_xy' grd_tile(grid, level, i, j = NULL)
grd_tile(grid, level, i, j = NULL) ## S3 method for class 'wk_grd_rct' grd_tile(grid, level, i, j = NULL) ## S3 method for class 'wk_grd_xy' grd_tile(grid, level, i, j = NULL)
grid |
A |
level |
An integer describing the overview level. This is related to
the |
i , j
|
1-based index values. |
A grd_subset()
ed version
grid <- grd_rct(volcano) plot(grd_tile(grid, 4, 1, 1)) plot(grd_tile(grid, 3, 1, 1), add = TRUE) plot(grd_tile(grid, 3, 1, 2), add = TRUE) plot(grd_tile(grid, 3, 2, 1), add = TRUE) plot(grd_tile(grid, 3, 2, 2), add = TRUE) grid <- as_grd_xy(grd_tile(grid, 4, 1, 1)) plot(grid, add = TRUE, pch = ".") plot(grd_tile(grid, 3, 1, 1), add = TRUE, col = "green", pch = ".") plot(grd_tile(grid, 3, 1, 2), add = TRUE, col = "red", pch = ".") plot(grd_tile(grid, 3, 2, 1), add = TRUE, col = "blue", pch = ".") plot(grd_tile(grid, 3, 2, 2), add = TRUE, col = "magenta", pch = ".")
grid <- grd_rct(volcano) plot(grd_tile(grid, 4, 1, 1)) plot(grd_tile(grid, 3, 1, 1), add = TRUE) plot(grd_tile(grid, 3, 1, 2), add = TRUE) plot(grd_tile(grid, 3, 2, 1), add = TRUE) plot(grd_tile(grid, 3, 2, 2), add = TRUE) grid <- as_grd_xy(grd_tile(grid, 4, 1, 1)) plot(grid, add = TRUE, pch = ".") plot(grd_tile(grid, 3, 1, 1), add = TRUE, col = "green", pch = ".") plot(grd_tile(grid, 3, 1, 2), add = TRUE, col = "red", pch = ".") plot(grd_tile(grid, 3, 2, 1), add = TRUE, col = "blue", pch = ".") plot(grd_tile(grid, 3, 2, 2), add = TRUE, col = "magenta", pch = ".")
A useful workflow for raster data in a memory bounded environment is to
chunk a grid into sections or tiles. These functions compute tiles
suitable for such processing. Use grd_tile_summary()
to generate
statistics for level
values to choose for your application.
grd_tile_template(grid, level) grd_tile_summary(grid, levels = NULL)
grd_tile_template(grid, level) grd_tile_summary(grid, levels = NULL)
grid |
A |
level |
An integer describing the overview level. This is related to
the |
levels |
A vector of |
A grd()
grid <- grd_rct(volcano) grd_tile_summary(grid) grd_tile_template(grid, 3)
grid <- grd_rct(volcano) grd_tile_summary(grid) grd_tile_template(grid, 3)
Test handlers for handling of unknown size vectors
handle_wkt_without_vector_size(handleable, handler)
handle_wkt_without_vector_size(handleable, handler)
handleable |
A geometry vector (e.g., |
handler |
A wk_handler object. |
handle_wkt_without_vector_size(wkt(), wk_vector_meta_handler())
handle_wkt_without_vector_size(wkt(), wk_vector_meta_handler())
S3 details for crc objects
new_wk_crc(x = list(x = double(), y = double(), r = double()), crs = NULL)
new_wk_crc(x = list(x = double(), y = double(), r = double()), crs = NULL)
x |
A |
crs |
A value to be propagated as the CRS for this vector. |
S3 details for grid objects
new_wk_grd(x, subclass = character())
new_wk_grd(x, subclass = character())
x |
A |
subclass |
An optional subclass. |
An object inheriting from 'grd'
S3 details for rct objects
new_wk_rct( x = list(xmin = double(), ymin = double(), xmax = double(), ymax = double()), crs = NULL )
new_wk_rct( x = list(xmin = double(), ymin = double(), xmax = double(), ymax = double()), crs = NULL )
x |
A |
crs |
A value to be propagated as the CRS for this vector. |
S3 Details for wk_wkb
new_wk_wkb(x = list(), crs = NULL, geodesic = NULL) validate_wk_wkb(x) is_wk_wkb(x)
new_wk_wkb(x = list(), crs = NULL, geodesic = NULL) validate_wk_wkb(x) is_wk_wkb(x)
x |
A (possibly) |
crs |
A value to be propagated as the CRS for this vector. |
geodesic |
|
S3 Details for wk_wkt
new_wk_wkt(x = character(), crs = NULL, geodesic = NULL) is_wk_wkt(x) validate_wk_wkt(x)
new_wk_wkt(x = character(), crs = NULL, geodesic = NULL) is_wk_wkt(x) validate_wk_wkt(x)
x |
A (possibly) |
crs |
A value to be propagated as the CRS for this vector. |
geodesic |
|
S3 details for xy objects
new_wk_xy(x = list(x = double(), y = double()), crs = NULL) new_wk_xyz(x = list(x = double(), y = double(), z = double()), crs = NULL) new_wk_xym(x = list(x = double(), y = double(), m = double()), crs = NULL) new_wk_xyzm( x = list(x = double(), y = double(), z = double(), m = double()), crs = NULL ) validate_wk_xy(x) validate_wk_xyz(x) validate_wk_xym(x) validate_wk_xyzm(x)
new_wk_xy(x = list(x = double(), y = double()), crs = NULL) new_wk_xyz(x = list(x = double(), y = double(), z = double()), crs = NULL) new_wk_xym(x = list(x = double(), y = double(), m = double()), crs = NULL) new_wk_xyzm( x = list(x = double(), y = double(), z = double(), m = double()), crs = NULL ) validate_wk_xy(x) validate_wk_xyz(x) validate_wk_xym(x) validate_wk_xyzm(x)
x |
A |
crs |
A value to be propagated as the CRS for this vector. |
Plot grid objects
## S3 method for class 'wk_grd_xy' plot(x, ...) ## S3 method for class 'wk_grd_rct' plot( x, ..., image = NULL, interpolate = FALSE, oversample = 4, border = NA, asp = 1, bbox = NULL, xlab = "", ylab = "", add = FALSE )
## S3 method for class 'wk_grd_xy' plot(x, ...) ## S3 method for class 'wk_grd_rct' plot( x, ..., image = NULL, interpolate = FALSE, oversample = 4, border = NA, asp = 1, bbox = NULL, xlab = "", ylab = "", add = FALSE )
x |
|
... |
Passed to plotting functions for features: |
image |
A raster or nativeRaster to pass to |
interpolate |
Use |
oversample |
A scale on the number of pixels on the device to use for
sampling estimation of large raster values. Use |
border |
Color to use for polygon borders. Use |
asp , xlab , ylab
|
Passed to |
bbox |
The limits of the plot as a |
add |
Should a new plot be created, or should |
x
, invisibly.
plot(grd_rct(volcano)) plot(grd_xy(volcano))
plot(grd_rct(volcano)) plot(grd_xy(volcano))
2D rectangle vectors
rct( xmin = double(), ymin = double(), xmax = double(), ymax = double(), crs = wk_crs_auto() ) as_rct(x, ...) ## S3 method for class 'wk_rct' as_rct(x, ...) ## S3 method for class 'matrix' as_rct(x, ..., crs = NULL) ## S3 method for class 'data.frame' as_rct(x, ..., crs = NULL)
rct( xmin = double(), ymin = double(), xmax = double(), ymax = double(), crs = wk_crs_auto() ) as_rct(x, ...) ## S3 method for class 'wk_rct' as_rct(x, ...) ## S3 method for class 'matrix' as_rct(x, ..., crs = NULL) ## S3 method for class 'data.frame' as_rct(x, ..., crs = NULL)
xmin , ymin , xmax , ymax
|
Rectangle bounds. |
crs |
A value to be propagated as the CRS for this vector. |
x |
An object to be converted to a |
... |
Extra arguments passed to |
A vector along the recycled length of bounds.
rct(1, 2, 3, 4)
rct(1, 2, 3, 4)
Rectangle accessors and operators
rct_xmin(x) rct_ymin(x) rct_xmax(x) rct_ymax(x) rct_width(x) rct_height(x) rct_intersects(x, y) rct_contains(x, y) rct_intersection(x, y)
rct_xmin(x) rct_ymin(x) rct_xmax(x) rct_ymax(x) rct_width(x) rct_height(x) rct_intersects(x, y) rct_contains(x, y) rct_intersection(x, y)
x , y
|
|
rct_xmin()
, rct_xmax()
, rct_ymin()
, and rct_ymax()
return
the components of the rct()
.
x <- rct(0, 0, 10, 10) y <- rct(5, 5, 15, 15) rct_xmin(x) rct_ymin(x) rct_xmax(x) rct_ymax(x) rct_height(x) rct_width(x) rct_intersects(x, y) rct_intersection(x, y) rct_contains(x, y) rct_contains(x, rct(4, 4, 6, 6))
x <- rct(0, 0, 10, 10) y <- rct(5, 5, 15, 15) rct_xmin(x) rct_ymin(x) rct_xmax(x) rct_ymax(x) rct_height(x) rct_width(x) rct_intersects(x, y) rct_intersection(x, y) rct_contains(x, y) rct_contains(x, rct(4, 4, 6, 6))
Vctrs methods
vec_cast.wk_wkb(x, to, ...) vec_ptype2.wk_wkb(x, y, ...) vec_cast.wk_wkt(x, to, ...) vec_ptype2.wk_wkt(x, y, ...) vec_cast.wk_xy(x, to, ...) vec_ptype2.wk_xy(x, y, ...) vec_cast.wk_xyz(x, to, ...) vec_ptype2.wk_xyz(x, y, ...) vec_cast.wk_xym(x, to, ...) vec_ptype2.wk_xym(x, y, ...) vec_cast.wk_xyzm(x, to, ...) vec_ptype2.wk_xyzm(x, y, ...) vec_cast.wk_rct(x, to, ...) vec_ptype2.wk_rct(x, y, ...) vec_cast.wk_crc(x, to, ...) vec_ptype2.wk_crc(x, y, ...)
vec_cast.wk_wkb(x, to, ...) vec_ptype2.wk_wkb(x, y, ...) vec_cast.wk_wkt(x, to, ...) vec_ptype2.wk_wkt(x, y, ...) vec_cast.wk_xy(x, to, ...) vec_ptype2.wk_xy(x, y, ...) vec_cast.wk_xyz(x, to, ...) vec_ptype2.wk_xyz(x, y, ...) vec_cast.wk_xym(x, to, ...) vec_ptype2.wk_xym(x, y, ...) vec_cast.wk_xyzm(x, to, ...) vec_ptype2.wk_xyzm(x, y, ...) vec_cast.wk_rct(x, to, ...) vec_ptype2.wk_rct(x, y, ...) vec_cast.wk_crc(x, to, ...) vec_ptype2.wk_crc(x, y, ...)
x , y , to , ...
|
See |
2D bounding rectangles
wk_bbox(handleable, ...) wk_envelope(handleable, ...) ## Default S3 method: wk_bbox(handleable, ...) ## Default S3 method: wk_envelope(handleable, ...) ## S3 method for class 'wk_rct' wk_envelope(handleable, ...) ## S3 method for class 'wk_crc' wk_envelope(handleable, ...) ## S3 method for class 'wk_xy' wk_envelope(handleable, ...) wk_bbox_handler() wk_envelope_handler()
wk_bbox(handleable, ...) wk_envelope(handleable, ...) ## Default S3 method: wk_bbox(handleable, ...) ## Default S3 method: wk_envelope(handleable, ...) ## S3 method for class 'wk_rct' wk_envelope(handleable, ...) ## S3 method for class 'wk_crc' wk_envelope(handleable, ...) ## S3 method for class 'wk_xy' wk_envelope(handleable, ...) wk_bbox_handler() wk_envelope_handler()
handleable |
A geometry vector (e.g., |
... |
Passed to the |
A rct()
of length 1.
wk_bbox(wkt("LINESTRING (1 2, 3 5)"))
wk_bbox(wkt("LINESTRING (1 2, 3 5)"))
It is often impractical, inefficient, or impossible to perform an operation on a vector of geometries with all the geometries loaded into memory at the same time. These functions help generalize the pattern of split-apply-combine to one or more handlers recycled along a common length. These functions are designed for developers rather than users and should be considered experimental.
wk_chunk_strategy_single() wk_chunk_strategy_feature(n_chunks = NULL, chunk_size = NULL) wk_chunk_strategy_coordinates(n_chunks = NULL, chunk_size = NULL, reduce = "*")
wk_chunk_strategy_single() wk_chunk_strategy_feature(n_chunks = NULL, chunk_size = NULL) wk_chunk_strategy_coordinates(n_chunks = NULL, chunk_size = NULL, reduce = "*")
n_chunks , chunk_size
|
Exactly one of the number of
chunks or the chunk size. For |
reduce |
For |
A function that returns a data.frame
with columns from
and to
when called with a handleable
and the feature count.
feat <- c(as_wkt(xy(1:4, 1:4)), wkt("LINESTRING (1 1, 2 2)")) wk_chunk_strategy_single()(list(feat), 5) wk_chunk_strategy_feature(chunk_size = 2)(list(feat), 5) wk_chunk_strategy_coordinates(chunk_size = 2)(list(feat), 5)
feat <- c(as_wkt(xy(1:4, 1:4)), wkt("LINESTRING (1 1, 2 2)")) wk_chunk_strategy_single()(list(feat), 5) wk_chunk_strategy_feature(chunk_size = 2)(list(feat), 5) wk_chunk_strategy_coordinates(chunk_size = 2)(list(feat), 5)
Counts the number of geometries, rings, and coordinates found within
each feature. As opposed to wk_meta()
, this handler will iterate
over the entire geometry.
wk_count(handleable, ...) ## Default S3 method: wk_count(handleable, ...) wk_count_handler()
wk_count(handleable, ...) ## Default S3 method: wk_count(handleable, ...) wk_count_handler()
handleable |
A geometry vector (e.g., |
... |
Passed to the |
A data.frame with one row for every feature encountered and columns:
n_geom
: The number of geometries encountered, including the
root geometry. Will be zero for a null feature.
n_ring
: The number of rings encountered. Will be zero for a
null feature.
n_coord
: The number of coordinates encountered. Will be zero
for a null feature.
wk_count(as_wkt("LINESTRING (0 0, 1 1)")) wk_count(as_wkb("LINESTRING (0 0, 1 1)"))
wk_count(as_wkt("LINESTRING (0 0, 1 1)")) wk_count(as_wkb("LINESTRING (0 0, 1 1)"))
The wk package doesn't operate on CRS objects, but does propagate them through subsetting and concatenation. A CRS object can be any R object, and x can be any object whose 'crs' attribute carries a CRS. These functions are S3 generics to keep them from being used on objects that do not use this system of CRS propagation.
wk_crs(x) ## S3 method for class 'wk_vctr' wk_crs(x) ## S3 method for class 'wk_rcrd' wk_crs(x) wk_crs(x) <- value wk_set_crs(x, crs) wk_crs_output(...) wk_is_geodesic_output(...)
wk_crs(x) ## S3 method for class 'wk_vctr' wk_crs(x) ## S3 method for class 'wk_rcrd' wk_crs(x) wk_crs(x) <- value wk_set_crs(x, crs) wk_crs_output(...) wk_is_geodesic_output(...)
x , ...
|
Objects whose "crs" attribute is used to carry a CRS. |
value |
See |
crs |
An object that can be interpreted as a CRS |
The wk_crs_equal()
function uses special S3 dispatch on wk_crs_equal_generic()
to evaluate whether or not two CRS values can be considered equal. When implementing
wk_crs_equal_generic()
, every attempt should be made to make wk_crs_equal(x, y)
and wk_crs_equal(y, x)
return identically.
wk_crs_equal(x, y) wk_crs_equal_generic(x, y, ...)
wk_crs_equal(x, y) wk_crs_equal_generic(x, y, ...)
x , y
|
Objects stored in the |
... |
Unused |
TRUE
if x
and y
can be considered equal, FALSE
otherwise.
The CRS handling in the wk package requires two sentinel CRS values.
The first, wk_crs_inherit()
, signals that the vector should inherit
a CRS of another vector if combined. This is useful for empty, NULL
,
and/or zero-length geometries. The second, wk_crs_auto()
, is used
as the default argument of crs
for constructors so that zero-length
geometries are assigned a CRS of wk_crs_inherit()
by default.
wk_crs_inherit() wk_crs_longlat(crs = NULL) wk_crs_auto() wk_crs_auto_value(x, crs)
wk_crs_inherit() wk_crs_longlat(crs = NULL) wk_crs_auto() wk_crs_auto_value(x, crs)
crs |
A value for the coordinate reference system supplied by the user. |
x |
A raw input to a construuctor whose length and crs attributte
is used to determine the default CRS returned by |
wk_crs_auto_value(list(), wk_crs_auto()) wk_crs_auto_value(list(), 1234) wk_crs_auto_value(list(NULL), wk_crs_auto())
wk_crs_auto_value(list(), wk_crs_auto()) wk_crs_auto_value(list(), 1234) wk_crs_auto_value(list(NULL), wk_crs_auto())
CRS object generic methods
wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) wk_crs_projjson(crs) ## S3 method for class ''NULL'' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) ## S3 method for class 'wk_crs_inherit' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) ## S3 method for class 'character' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) ## S3 method for class 'double' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) ## S3 method for class 'integer' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE)
wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) wk_crs_projjson(crs) ## S3 method for class ''NULL'' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) ## S3 method for class 'wk_crs_inherit' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) ## S3 method for class 'character' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) ## S3 method for class 'double' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE) ## S3 method for class 'integer' wk_crs_proj_definition(crs, proj_version = NULL, verbose = FALSE)
crs |
An arbitrary R object |
proj_version |
A |
verbose |
Use |
wk_crs_proj_definition()
Returns a string used to represent the
CRS in PROJ. For recent PROJ version you'll want to return PROJJSON;
however you should check proj_version
if you want this to work with
older versions of PROJ.
wk_crs_projjson()
Returns a PROJJSON string or NA_character_ if this
representation is unknown or can't be calculated.
wk_crs_proj_definition("EPSG:4326")
wk_crs_proj_definition("EPSG:4326")
Debug filters and handlers
wk_debug(handleable, handler = wk_void_handler(), ...) wk_debug_filter(handler = wk_void_handler())
wk_debug(handleable, handler = wk_void_handler(), ...) wk_debug_filter(handler = wk_void_handler())
handleable |
A geometry vector (e.g., |
handler |
A wk_handler object. |
... |
Passed to the |
The result of the handler
.
wk_debug(wkt("POINT (1 1)")) wk_handle(wkt("POINT (1 1)"), wk_debug_filter())
wk_debug(wkt("POINT (1 1)")) wk_handle(wkt("POINT (1 1)"), wk_debug_filter())
Create example geometry objects
wk_example(which = "nc", crs = NA, geodesic = FALSE) wk_example_wkt
wk_example(which = "nc", crs = NA, geodesic = FALSE) wk_example_wkt
which |
An example name. Valid example names are
|
crs |
An object that can be interpreted as a CRS |
geodesic |
|
An object of class list
of length 29.
A wkt()
with the specified example.
wk_example("polygon")
wk_example("polygon")
Extract simple geometries
wk_flatten(handleable, ..., max_depth = 1) wk_flatten_filter(handler, max_depth = 1L, add_details = FALSE)
wk_flatten(handleable, ..., max_depth = 1) wk_flatten_filter(handler, max_depth = 1L, add_details = FALSE)
handleable |
A geometry vector (e.g., |
... |
Passed to the |
max_depth |
The maximum (outer) depth to remove. |
handler |
A wk_handler object. |
add_details |
Use |
handleable
transformed such that collections have been
expanded and only simple geometries (point, linestring, polygon)
remain.
wk_flatten(wkt("MULTIPOINT (1 1, 2 2, 3 3)")) wk_flatten( wkt("GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 1))))"), max_depth = 2 )
wk_flatten(wkt("MULTIPOINT (1 1, 2 2, 3 3)")) wk_flatten( wkt("GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 1))))"), max_depth = 2 )
Provides an abbreviated version of the well-known text representation of a geometry. This returns a constant number of coordinates for each geometry, so is safe to use for geometry vectors with many (potentially large) features. Parse errors are passed on to the format string and do not cause this handler to error.
wk_format(handleable, precision = 7, trim = TRUE, max_coords = 6, ...) wkt_format_handler(precision = 7, trim = TRUE, max_coords = 6)
wk_format(handleable, precision = 7, trim = TRUE, max_coords = 6, ...) wkt_format_handler(precision = 7, trim = TRUE, max_coords = 6)
handleable |
A geometry vector (e.g., |
precision |
If |
trim |
Use |
max_coords |
The maximum number of coordinates to include in the output. |
... |
Passed to the |
A character vector of abbreviated well-known text.
wk_format(wkt("MULTIPOLYGON (((0 0, 10 0, 0 10, 0 0)))")) wk_format(new_wk_wkt("POINT ENTPY")) wk_handle( wkt("MULTIPOLYGON (((0 0, 10 0, 0 10, 0 0)))"), wkt_format_handler() )
wk_format(wkt("MULTIPOLYGON (((0 0, 10 0, 0 10, 0 0)))")) wk_format(new_wk_wkt("POINT ENTPY")) wk_handle( wkt("MULTIPOLYGON (((0 0, 10 0, 0 10, 0 0)))"), wkt_format_handler() )
Handle specific regions of objects
## S3 method for class 'data.frame' wk_handle_slice(handleable, handler, from = NULL, to = NULL, ...) wk_handle_slice( handleable, handler = wk_writer(handleable), from = NULL, to = NULL, ... ) ## Default S3 method: wk_handle_slice( handleable, handler = wk_writer(handleable), from = NULL, to = NULL, ... )
## S3 method for class 'data.frame' wk_handle_slice(handleable, handler, from = NULL, to = NULL, ...) wk_handle_slice( handleable, handler = wk_writer(handleable), from = NULL, to = NULL, ... ) ## Default S3 method: wk_handle_slice( handleable, handler = wk_writer(handleable), from = NULL, to = NULL, ... )
handleable |
A geometry vector (e.g., |
handler |
A wk_handler object. |
from |
1-based index of the feature to start from |
to |
1-based index of the feature to end at |
... |
Passed to the |
A subset of handleable
wk_handle_slice(xy(1:5, 1:5), wkt_writer(), from = 3, to = 5) wk_handle_slice( data.frame(let = letters[1:5], geom = xy(1:5, 1:5)), wkt_writer(), from = 3, to = 5 )
wk_handle_slice(xy(1:5, 1:5), wkt_writer(), from = 3, to = 5) wk_handle_slice( data.frame(let = letters[1:5], geom = xy(1:5, 1:5)), wkt_writer(), from = 3, to = 5 )
Use data.frame with wk
## S3 method for class 'data.frame' wk_handle(handleable, handler, ...) ## S3 method for class 'data.frame' wk_restore(handleable, result, ...) ## S3 method for class 'tbl_df' wk_restore(handleable, result, ...) ## S3 method for class 'data.frame' wk_translate(handleable, to, ...) ## S3 method for class 'tbl_df' wk_translate(handleable, to, ...) ## S3 method for class 'sf' wk_translate(handleable, to, ...) ## S3 method for class 'sf' wk_restore(handleable, result, ...)
## S3 method for class 'data.frame' wk_handle(handleable, handler, ...) ## S3 method for class 'data.frame' wk_restore(handleable, result, ...) ## S3 method for class 'tbl_df' wk_restore(handleable, result, ...) ## S3 method for class 'data.frame' wk_translate(handleable, to, ...) ## S3 method for class 'tbl_df' wk_translate(handleable, to, ...) ## S3 method for class 'sf' wk_translate(handleable, to, ...) ## S3 method for class 'sf' wk_restore(handleable, result, ...)
handleable |
A geometry vector (e.g., |
handler |
A wk_handler object. |
... |
Passed to the |
result |
The result of a filter operation intended to be a transformation. |
to |
A prototype object. |
wk_handle(data.frame(a = wkt("POINT (0 1)")), wkb_writer()) wk_translate(wkt("POINT (0 1)"), data.frame(col_name = wkb())) wk_translate(data.frame(a = wkt("POINT (0 1)")), data.frame(wkb()))
wk_handle(data.frame(a = wkt("POINT (0 1)")), wkb_writer()) wk_translate(wkt("POINT (0 1)"), data.frame(col_name = wkb())) wk_translate(data.frame(a = wkt("POINT (0 1)")), data.frame(wkb()))
The handler is the basic building block of the wk package. In
particular, the wk_handle()
generic allows operations written
as handlers to "just work" with many different input types. The
wk package provides the wk_void()
handler, the wk_format()
handler, the wk_debug()
handler, the wk_problems()
handler,
and wk_writer()
s for wkb()
, wkt()
, xy()
, and sf::st_sfc()
)
vectors.
## S3 method for class 'wk_crc' wk_handle( handleable, handler, ..., n_segments = getOption("wk.crc_n_segments", NULL), resolution = getOption("wk.crc_resolution", NULL) ) ## S3 method for class 'wk_rct' wk_handle(handleable, handler, ...) ## S3 method for class 'sfc' wk_handle(handleable, handler, ...) ## S3 method for class 'wk_wkb' wk_handle(handleable, handler, ...) ## S3 method for class 'wk_wkt' wk_handle(handleable, handler, ...) ## S3 method for class 'wk_xy' wk_handle(handleable, handler, ...) wk_handle(handleable, handler, ...) is_handleable(handleable) new_wk_handler(handler_ptr, subclass = character()) is_wk_handler(handler) as_wk_handler(handler, ...) ## S3 method for class 'sfg' wk_handle(handleable, handler, ...) ## S3 method for class 'sf' wk_handle(handleable, handler, ...) ## S3 method for class 'bbox' wk_handle(handleable, handler, ...)
## S3 method for class 'wk_crc' wk_handle( handleable, handler, ..., n_segments = getOption("wk.crc_n_segments", NULL), resolution = getOption("wk.crc_resolution", NULL) ) ## S3 method for class 'wk_rct' wk_handle(handleable, handler, ...) ## S3 method for class 'sfc' wk_handle(handleable, handler, ...) ## S3 method for class 'wk_wkb' wk_handle(handleable, handler, ...) ## S3 method for class 'wk_wkt' wk_handle(handleable, handler, ...) ## S3 method for class 'wk_xy' wk_handle(handleable, handler, ...) wk_handle(handleable, handler, ...) is_handleable(handleable) new_wk_handler(handler_ptr, subclass = character()) is_wk_handler(handler) as_wk_handler(handler, ...) ## S3 method for class 'sfg' wk_handle(handleable, handler, ...) ## S3 method for class 'sf' wk_handle(handleable, handler, ...) ## S3 method for class 'bbox' wk_handle(handleable, handler, ...)
handleable |
A geometry vector (e.g., |
handler |
A wk_handler object. |
... |
Passed to the |
n_segments , resolution
|
The number of segments to use when approximating
a circle. The default uses |
handler_ptr |
An external pointer to a newly created WK handler |
subclass |
The handler subclass |
A WK handler.
Handler interface for grid objects
## S3 method for class 'wk_grd_xy' wk_handle(handleable, handler, ..., data_order = c("y", "x")) ## S3 method for class 'wk_grd_rct' wk_handle(handleable, handler, ..., data_order = c("y", "x"))
## S3 method for class 'wk_grd_xy' wk_handle(handleable, handler, ..., data_order = c("y", "x")) ## S3 method for class 'wk_grd_rct' wk_handle(handleable, handler, ..., data_order = c("y", "x"))
handleable |
A geometry vector (e.g., |
handler |
A wk_handler object. |
... |
Passed to the |
data_order |
A vector of length 2 describing the order in which
values should appear. The default, |
The result of the handler
.
wk_handle(grd(nx = 3, ny = 3), wkt_writer()) wk_handle(grd(nx = 3, ny = 3, type = "centers"), wkt_writer())
wk_handle(grd(nx = 3, ny = 3), wkt_writer()) wk_handle(grd(nx = 3, ny = 3, type = "centers"), wkt_writer())
Copy a geometry vector
wk_identity(handleable, ...) wk_identity_filter(handler) wk_restore(handleable, result, ...) ## Default S3 method: wk_restore(handleable, result, ...)
wk_identity(handleable, ...) wk_identity_filter(handler) wk_restore(handleable, result, ...) ## Default S3 method: wk_restore(handleable, result, ...)
handleable |
A geometry vector (e.g., |
... |
Passed to the |
handler |
A wk_handler object. |
result |
The result of a filter operation intended to be a transformation. |
A copy of handleable
.
wk_identity(wkt("POINT (1 2)"))
wk_identity(wkt("POINT (1 2)"))
Set and get vector geodesic edge interpolation
wk_is_geodesic(x) wk_set_geodesic(x, geodesic) wk_is_geodesic(x) <- value wk_geodesic_inherit()
wk_is_geodesic(x) wk_set_geodesic(x, geodesic) wk_is_geodesic(x) <- value wk_geodesic_inherit()
x |
An R object that contains edges |
geodesic |
|
value |
See |
TRUE
if edges must be interpolated as geodesics when
coordinates are spherical, FALSE
otherwise.
Create lines, polygons, and collections
wk_linestring(handleable, feature_id = 1L, ..., geodesic = NULL) wk_polygon(handleable, feature_id = 1L, ring_id = 1L, ..., geodesic = NULL) wk_collection( handleable, geometry_type = wk_geometry_type("geometrycollection"), feature_id = 1L, ... ) wk_linestring_filter(handler, feature_id = 1L) wk_polygon_filter(handler, feature_id = 1L, ring_id = 1L) wk_collection_filter( handler, geometry_type = wk_geometry_type("geometrycollection"), feature_id = 1L )
wk_linestring(handleable, feature_id = 1L, ..., geodesic = NULL) wk_polygon(handleable, feature_id = 1L, ring_id = 1L, ..., geodesic = NULL) wk_collection( handleable, geometry_type = wk_geometry_type("geometrycollection"), feature_id = 1L, ... ) wk_linestring_filter(handler, feature_id = 1L) wk_polygon_filter(handler, feature_id = 1L, ring_id = 1L) wk_collection_filter( handler, geometry_type = wk_geometry_type("geometrycollection"), feature_id = 1L )
handleable |
A geometry vector (e.g., |
feature_id |
An identifier where changes in sequential values indicate a new feature. This is recycled silently as needed. |
... |
Passed to the |
geodesic |
Use |
ring_id |
An identifier where changes in sequential values indicate a new ring. Rings are automatically closed. This is recycled silently as needed. |
geometry_type |
The collection type to create. |
handler |
A wk_handler object. |
An object of the same class as handleable
with
whose coordinates have been assembled into the given
type.
wk_linestring(xy(c(1, 1), c(2, 3))) wk_polygon(xy(c(0, 1, 0), c(0, 0, 1))) wk_collection(xy(c(1, 1), c(2, 3)))
wk_linestring(xy(c(1, 1), c(2, 3))) wk_polygon(xy(c(0, 1, 0), c(0, 0, 1))) wk_collection(xy(c(1, 1), c(2, 3)))
These functions return the non-coordinate information of a geometry and/or vector. They do not parse an entire geometry/vector and are intended to be very fast even for large vectors.
wk_meta(handleable, ...) ## Default S3 method: wk_meta(handleable, ...) wk_vector_meta(handleable, ...) ## Default S3 method: wk_vector_meta(handleable, ...) wk_meta_handler() wk_vector_meta_handler() wk_geometry_type_label(geometry_type) wk_geometry_type(geometry_type_label)
wk_meta(handleable, ...) ## Default S3 method: wk_meta(handleable, ...) wk_vector_meta(handleable, ...) ## Default S3 method: wk_vector_meta(handleable, ...) wk_meta_handler() wk_vector_meta_handler() wk_geometry_type_label(geometry_type) wk_geometry_type(geometry_type_label)
handleable |
A geometry vector (e.g., |
... |
Passed to the |
geometry_type |
An integer code for the geometry type. These integers follow the WKB specification (e.g., 1 for point, 7 for geometrycollection). |
geometry_type_label |
A character vector of (lowercase) geometry type labels as would be found in WKT (e.g., point, geometrycollection). |
A data.frame with columns:
geometry_type
: An integer identifying the geometry type.
A value of 0 indicates that the types of geometry in the vector
are not known without parsing the entire vector.
size
: For points and linestrings, the number of coordinates; for
polygons, the number of rings; for collections, the number of
child geometries. A value of zero indicates an EMPTY geometry.
A value of NA
means this value is unknown without parsing the
entire geometry.
has_z
: TRUE
if coordinates contain a Z value. A value of NA
means this value is unknown without parsing the entire vector.
has_m
: TRUE
if coordinates contain an M value. A value of NA
means this value is unknown without parsing the entire vector.
srid
: An integer identifying a CRS or NA if this value was not
provided.
precision
: A grid size or 0.0 if a grid size was not provided.
Note that coordinate values may not have been rounded; the grid
size only refers to the level of detail with which they should
be interpreted.
is_empty
: TRUE
if there is at least one non-empty coordinate.
For the purposes of this value, a non-empty coordinate is one that
contains at least one value that is not NA
or NaN
.
wk_vector_meta(as_wkt("LINESTRING (0 0, 1 1)")) wk_meta(as_wkt("LINESTRING (0 0, 1 1)")) wk_meta(as_wkb("LINESTRING (0 0, 1 1)")) wk_geometry_type_label(1:7) wk_geometry_type(c("point", "geometrycollection"))
wk_vector_meta(as_wkt("LINESTRING (0 0, 1 1)")) wk_meta(as_wkt("LINESTRING (0 0, 1 1)")) wk_meta(as_wkb("LINESTRING (0 0, 1 1)")) wk_geometry_type_label(1:7) wk_geometry_type(c("point", "geometrycollection"))
Orient polygon coordinates
wk_orient(handleable, ..., direction = wk_counterclockwise()) wk_orient_filter(handler, direction = wk_counterclockwise()) wk_clockwise() wk_counterclockwise()
wk_orient(handleable, ..., direction = wk_counterclockwise()) wk_orient_filter(handler, direction = wk_counterclockwise()) wk_clockwise() wk_counterclockwise()
handleable |
A geometry vector (e.g., |
... |
Passed to the |
direction |
The winding polygon winding direction |
handler |
A wk_handler object. |
handleable
with consistently oriented polygons, in direction
winding order.
wk_orient(wkt("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))")) wk_orient( wkt("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"), direction = wk_clockwise() )
wk_orient(wkt("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))")) wk_orient( wkt("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"), direction = wk_clockwise() )
Plot well-known geometry vectors
wk_plot( handleable, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", rule = "evenodd", add = FALSE ) ## Default S3 method: wk_plot( handleable, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", rule = "evenodd", add = FALSE ) ## S3 method for class 'wk_wkt' plot( x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", rule = "evenodd", add = FALSE ) ## S3 method for class 'wk_wkb' plot( x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", rule = "evenodd", add = FALSE ) ## S3 method for class 'wk_xy' plot(x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", add = FALSE) ## S3 method for class 'wk_rct' plot(x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", add = FALSE) ## S3 method for class 'wk_crc' plot(x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", add = FALSE)
wk_plot( handleable, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", rule = "evenodd", add = FALSE ) ## Default S3 method: wk_plot( handleable, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", rule = "evenodd", add = FALSE ) ## S3 method for class 'wk_wkt' plot( x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", rule = "evenodd", add = FALSE ) ## S3 method for class 'wk_wkb' plot( x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", rule = "evenodd", add = FALSE ) ## S3 method for class 'wk_xy' plot(x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", add = FALSE) ## S3 method for class 'wk_rct' plot(x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", add = FALSE) ## S3 method for class 'wk_crc' plot(x, ..., asp = 1, bbox = NULL, xlab = "", ylab = "", add = FALSE)
handleable |
A geometry vector (e.g., |
... |
Passed to plotting functions for features: |
asp , xlab , ylab
|
Passed to |
bbox |
The limits of the plot as a |
rule |
The rule to use for filling polygons (see |
add |
Should a new plot be created, or should |
x |
The input, invisibly.
plot(as_wkt("LINESTRING (0 0, 1 1)")) plot(as_wkb("LINESTRING (0 0, 1 1)"))
plot(as_wkt("LINESTRING (0 0, 1 1)")) plot(as_wkb("LINESTRING (0 0, 1 1)"))
The problems handler returns a character vector of parse
errors and can be used to validate input of any type
for which wk_handle()
is defined.
wk_problems(handleable, ...) wk_problems_handler()
wk_problems(handleable, ...) wk_problems_handler()
handleable |
A geometry vector (e.g., |
... |
Passed to the |
A character vector of parsing errors. NA
signifies
that there was no parsing error.
wk_problems(new_wk_wkt(c("POINT EMTPY", "POINT (20 30)"))) wk_handle( new_wk_wkt(c("POINT EMTPY", "POINT (20 30)")), wk_problems_handler() )
wk_problems(new_wk_wkt(c("POINT EMTPY", "POINT (20 30)"))) wk_handle( new_wk_wkt(c("POINT EMTPY", "POINT (20 30)")), wk_problems_handler() )
These fixtures are calculated from PROJ version 9.1.0 and the database built from its source. They are used internally to transform and inspect coordinate reference systems.
wk_proj_crs_view wk_proj_crs_json
wk_proj_crs_view wk_proj_crs_json
An object of class data.frame
with 13387 rows and 7 columns.
An object of class data.frame
with 13387 rows and 3 columns.
head(wk_proj_crs_view) colnames(wk_proj_crs_json)
head(wk_proj_crs_view) colnames(wk_proj_crs_json)
Set coordinate values
wk_set_z(handleable, z, ...) wk_set_m(handleable, m, ...) wk_drop_z(handleable, ...) wk_drop_m(handleable, ...) wk_trans_set(value, use_z = NA, use_m = NA)
wk_set_z(handleable, z, ...) wk_set_m(handleable, m, ...) wk_drop_z(handleable, ...) wk_drop_m(handleable, ...) wk_trans_set(value, use_z = NA, use_m = NA)
handleable |
A geometry vector (e.g., |
z , m
|
A vector of Z or M values applied feature-wise and recycled
along |
... |
Passed to the |
value |
An |
use_z , use_m
|
Used to declare the output type. Use |
wk_set_z(wkt("POINT (0 1)"), 2) wk_set_m(wkt("POINT (0 1)"), 2) wk_drop_z(wkt("POINT ZM (0 1 2 3)")) wk_drop_m(wkt("POINT ZM (0 1 2 3)"))
wk_set_z(wkt("POINT (0 1)"), 2) wk_set_m(wkt("POINT (0 1)"), 2) wk_drop_z(wkt("POINT ZM (0 1 2 3)")) wk_drop_m(wkt("POINT ZM (0 1 2 3)"))
Affine transformer
wk_trans_affine(trans_matrix) wk_affine_identity() wk_affine_rotate(rotation_deg) wk_affine_scale(scale_x = 1, scale_y = 1) wk_affine_translate(dx = 0, dy = 0) wk_affine_fit(src, dst) wk_affine_rescale(rct_in, rct_out) wk_affine_compose(...) wk_affine_invert(x)
wk_trans_affine(trans_matrix) wk_affine_identity() wk_affine_rotate(rotation_deg) wk_affine_scale(scale_x = 1, scale_y = 1) wk_affine_translate(dx = 0, dy = 0) wk_affine_fit(src, dst) wk_affine_rescale(rct_in, rct_out) wk_affine_compose(...) wk_affine_invert(x)
trans_matrix |
A 3x3 transformation matrix |
rotation_deg |
A rotation to apply in degrees counterclockwise. |
scale_x , scale_y
|
Scale factor to apply in the x and y directions, respectively |
dx , dy
|
Coordinate offsets in the x and y direction |
src , dst
|
Point vectors of control points used to estimate the affine mapping
(using |
rct_in , rct_out
|
The input and output bounds |
... |
Zero or more transforms in the order they should be applied. |
x |
A wk_trans implementation that replaces coordinate values using a vector of pre-calculated coordinates. This is used to perform generic transforms using R functions and system calls that are impossible or impractical to implement at the C level.
wk_trans_explicit(value, use_z = NA, use_m = NA)
wk_trans_explicit(value, use_z = NA, use_m = NA)
value |
An |
use_z , use_m
|
Used to declare the output type. Use |
wk_coords()
which has a replacement version "wk_coords<-
"
trans <- wk_trans_explicit(xy(1:5, 1:5)) wk_transform(rep(xy(0, 0), 5), trans)
trans <- wk_trans_explicit(xy(1:5, 1:5)) wk_transform(rep(xy(0, 0), 5), trans)
Generic transform class
wk_trans_inverse(trans, ...) as_wk_trans(x, ...) ## S3 method for class 'wk_trans' as_wk_trans(x, ...) new_wk_trans(trans_ptr, subclass = character())
wk_trans_inverse(trans, ...) as_wk_trans(x, ...) ## S3 method for class 'wk_trans' as_wk_trans(x, ...) new_wk_trans(trans_ptr, subclass = character())
trans |
An external pointer to a wk_trans object |
... |
Passed to S3 methods |
x |
An object to be converted to a transform. |
trans_ptr |
An external pointer to a wk_trans_t transform struct. |
subclass |
An optional subclass to apply to the pointer |
Apply coordinate transformations
wk_transform(handleable, trans, ...) wk_transform_filter(handler, trans)
wk_transform(handleable, trans, ...) wk_transform_filter(handler, trans)
handleable |
A geometry vector (e.g., |
trans |
An external pointer to a wk_trans object |
... |
Passed to the |
handler |
A wk_handler object. |
wk_transform(xy(0, 0), wk_affine_translate(2, 3))
wk_transform(xy(0, 0), wk_affine_translate(2, 3))
Translate geometry vectors
## S3 method for class 'sfc' wk_translate(handleable, to, ...) wk_translate(handleable, to, ...) ## Default S3 method: wk_translate(handleable, to, ...)
## S3 method for class 'sfc' wk_translate(handleable, to, ...) wk_translate(handleable, to, ...) ## Default S3 method: wk_translate(handleable, to, ...)
handleable |
A geometry vector (e.g., |
to |
A prototype object. |
... |
Passed to the |
These functions provide ways to extract individual coordinate values.
Whereas wk_vertices()
returns a vector of coordinates as in the same
format as the input, wk_coords()
returns a data frame with coordinates
as columns.
wk_vertices(handleable, ...) wk_coords(handleable, ...) wk_coords(handleable, use_z = NA, use_m = NA) <- value wk_vertex_filter(handler, add_details = FALSE)
wk_vertices(handleable, ...) wk_coords(handleable, ...) wk_coords(handleable, use_z = NA, use_m = NA) <- value wk_vertex_filter(handler, add_details = FALSE)
handleable |
A geometry vector (e.g., |
... |
Passed to the |
use_z , use_m
|
Used to declare the output type. Use |
value |
An |
handler |
A wk_handler object. |
add_details |
Use |
wk_coords<-
is the replacement-function version of 'wk_coords'.
Using the engine of wk_trans_explicit()
the coordinates of an object
can be transformed in a generic way using R functions as needed.
wk_vertices()
extracts vertices and returns the in the same format as
the handler
wk_coords()
returns a data frame with columns columns feature_id
(the index of the feature from whence it came), part_id
(an arbitrary
integer identifying the point, line, or polygon from whence it came),
ring_id
(an arbitrary integer identifying individual rings within
polygons), and one column per coordinate (x
, y
, and/or z
and/or m
).
wk_vertices(wkt("LINESTRING (0 0, 1 1)")) wk_coords(wkt("LINESTRING (0 0, 1 1)")) # wk_coords() replacement function x <- xy(1:5, 1:5) y <- as_wkt(x) wk_coords(y) <- cbind(5:1, 0:4) wk_coords(x) <- y[5:1] y x
wk_vertices(wkt("LINESTRING (0 0, 1 1)")) wk_coords(wkt("LINESTRING (0 0, 1 1)")) # wk_coords() replacement function x <- xy(1:5, 1:5) y <- as_wkt(x) wk_coords(y) <- cbind(5:1, 0:4) wk_coords(x) <- y[5:1] y x
This handler does nothing and returns NULL
. It is useful for
benchmarking readers and handlers and when using filters
that have side-effects (e.g., wk_debug()
). Note that this
handler stops on the first parse error; to see a list of parse
errors see the wk_problems()
handler.
wk_void(handleable, ...) wk_void_handler()
wk_void(handleable, ...) wk_void_handler()
handleable |
A geometry vector (e.g., |
... |
Passed to the |
NULL
wk_void(wkt("POINT (1 4)")) wk_handle(wkt("POINT (1 4)"), wk_void_handler())
wk_void(wkt("POINT (1 4)")) wk_handle(wkt("POINT (1 4)"), wk_void_handler())
When writing transformation functions, it is often useful to know which
handler should be used to create a (potentially modified) version
of an object. Some transformers (e.g., wk_vertices()
) modify
the geometry type of an object, in which case a generic writer is needed.
This defaults to wkb_writer()
because it is fast and can handle
all geometry types.
## S3 method for class 'sfc' wk_writer(handleable, ...) ## S3 method for class 'sf' wk_writer(handleable, ...) sfc_writer(promote_multi = FALSE) wkb_writer(buffer_size = 2048L, endian = NA_integer_) wkt_writer(precision = 16L, trim = TRUE) wk_writer(handleable, ..., generic = FALSE) ## Default S3 method: wk_writer(handleable, ...) ## S3 method for class 'wk_wkt' wk_writer(handleable, ..., precision = 16, trim = TRUE) ## S3 method for class 'wk_wkb' wk_writer(handleable, ...) ## S3 method for class 'wk_xy' wk_writer(handleable, ..., generic = FALSE) xy_writer()
## S3 method for class 'sfc' wk_writer(handleable, ...) ## S3 method for class 'sf' wk_writer(handleable, ...) sfc_writer(promote_multi = FALSE) wkb_writer(buffer_size = 2048L, endian = NA_integer_) wkt_writer(precision = 16L, trim = TRUE) wk_writer(handleable, ..., generic = FALSE) ## Default S3 method: wk_writer(handleable, ...) ## S3 method for class 'wk_wkt' wk_writer(handleable, ..., precision = 16, trim = TRUE) ## S3 method for class 'wk_wkb' wk_writer(handleable, ...) ## S3 method for class 'wk_xy' wk_writer(handleable, ..., generic = FALSE) xy_writer()
handleable |
A geometry vector (e.g., |
... |
Passed to the writer constructor. |
promote_multi |
Use TRUE to promote all simple geometries to a multi type when reading to sfc. This is useful to increase the likelihood that the sfc will contain a single geometry type. |
buffer_size |
Control the initial buffer size used when writing WKB. |
endian |
Use 1 for little endian, 0 for big endian, or NA for system endian. |
precision |
If |
trim |
Use |
generic |
Use |
A wk_handler.
Mark lists of raw vectors as well-known binary
wkb(x = list(), crs = wk_crs_auto(), geodesic = FALSE) parse_wkb(x, crs = wk_crs_auto(), geodesic = FALSE) wk_platform_endian() as_wkb(x, ...) ## Default S3 method: as_wkb(x, ...) ## S3 method for class 'character' as_wkb(x, ..., crs = NULL, geodesic = FALSE) ## S3 method for class 'wk_wkb' as_wkb(x, ...) ## S3 method for class 'blob' as_wkb(x, ..., crs = NULL, geodesic = FALSE) ## S3 method for class 'WKB' as_wkb(x, ..., crs = NULL, geodesic = FALSE)
wkb(x = list(), crs = wk_crs_auto(), geodesic = FALSE) parse_wkb(x, crs = wk_crs_auto(), geodesic = FALSE) wk_platform_endian() as_wkb(x, ...) ## Default S3 method: as_wkb(x, ...) ## S3 method for class 'character' as_wkb(x, ..., crs = NULL, geodesic = FALSE) ## S3 method for class 'wk_wkb' as_wkb(x, ...) ## S3 method for class 'blob' as_wkb(x, ..., crs = NULL, geodesic = FALSE) ## S3 method for class 'WKB' as_wkb(x, ..., crs = NULL, geodesic = FALSE)
x |
|
crs |
A value to be propagated as the CRS for this vector. |
geodesic |
|
... |
Unused |
as_wkb("POINT (20 10)")
as_wkb("POINT (20 10)")
Convert well-known binary to hex
wkb_to_hex(x)
wkb_to_hex(x)
x |
A |
A hex encoded wkb()
vector
x <- as_wkb(xyz(1:5, 6:10, 11:15)) wkb_to_hex(x)
x <- as_wkb(xyz(1:5, 6:10, 11:15)) wkb_to_hex(x)
These functions are deprecated and will be removed in a future version.
wkb_translate_wkt(wkb, ..., precision = 16, trim = TRUE) wkb_translate_wkb(wkb, ..., endian = NA_integer_) wkt_translate_wkt(wkt, ..., precision = 16, trim = TRUE) wkt_translate_wkb(wkt, ..., endian = NA_integer_)
wkb_translate_wkt(wkb, ..., precision = 16, trim = TRUE) wkb_translate_wkb(wkb, ..., endian = NA_integer_) wkt_translate_wkt(wkt, ..., precision = 16, trim = TRUE) wkt_translate_wkb(wkt, ..., endian = NA_integer_)
wkb |
A |
... |
Used to keep backward compatibility with previous versions of these functions. |
precision |
The rounding precision to use when writing (number of decimal places). |
trim |
Trim unnecessary zeroes in the output? |
endian |
Force the endian of the resulting WKB. |
wkt |
A character vector containing well-known text. |
Mark character vectors as well-known text
wkt(x = character(), crs = wk_crs_auto(), geodesic = FALSE) parse_wkt(x, crs = wk_crs_auto(), geodesic = FALSE) as_wkt(x, ...) ## Default S3 method: as_wkt(x, ...) ## S3 method for class 'character' as_wkt(x, ..., crs = NULL, geodesic = FALSE) ## S3 method for class 'wk_wkt' as_wkt(x, ...)
wkt(x = character(), crs = wk_crs_auto(), geodesic = FALSE) parse_wkt(x, crs = wk_crs_auto(), geodesic = FALSE) as_wkt(x, ...) ## Default S3 method: as_wkt(x, ...) ## S3 method for class 'character' as_wkt(x, ..., crs = NULL, geodesic = FALSE) ## S3 method for class 'wk_wkt' as_wkt(x, ...)
x |
A |
crs |
A value to be propagated as the CRS for this vector. |
geodesic |
|
... |
Unused |
wkt("POINT (20 10)")
wkt("POINT (20 10)")
Efficient point vectors
xy(x = double(), y = double(), crs = wk_crs_auto()) xyz(x = double(), y = double(), z = double(), crs = wk_crs_auto()) xym(x = double(), y = double(), m = double(), crs = wk_crs_auto()) xyzm( x = double(), y = double(), z = double(), m = double(), crs = wk_crs_auto() ) xy_dims(x) as_xy(x, ...) ## Default S3 method: as_xy(x, ..., dims = NULL) ## S3 method for class 'wk_xy' as_xy(x, ..., dims = NULL) ## S3 method for class 'matrix' as_xy(x, ..., crs = NULL) ## S3 method for class 'data.frame' as_xy(x, ..., dims = NULL, crs = NULL)
xy(x = double(), y = double(), crs = wk_crs_auto()) xyz(x = double(), y = double(), z = double(), crs = wk_crs_auto()) xym(x = double(), y = double(), m = double(), crs = wk_crs_auto()) xyzm( x = double(), y = double(), z = double(), m = double(), crs = wk_crs_auto() ) xy_dims(x) as_xy(x, ...) ## Default S3 method: as_xy(x, ..., dims = NULL) ## S3 method for class 'wk_xy' as_xy(x, ..., dims = NULL) ## S3 method for class 'matrix' as_xy(x, ..., crs = NULL) ## S3 method for class 'data.frame' as_xy(x, ..., dims = NULL, crs = NULL)
x , y , z , m
|
Coordinate values. |
crs |
A value to be propagated as the CRS for this vector. |
... |
Passed to methods. |
dims |
A set containing one or more of |
A vector of coordinate values.
xy(1:5, 1:5) xyz(1:5, 1:5, 10) xym(1:5, 1:5, 10) xyzm(1:5, 1:5, 10, 12) # NA, NA maps to a null/na feature; NaN, NaN maps to EMPTY as_wkt(xy(NaN, NaN)) as_wkt(xy(NA, NA))
xy(1:5, 1:5) xyz(1:5, 1:5, 10) xym(1:5, 1:5, 10) xyzm(1:5, 1:5, 10, 12) # NA, NA maps to a null/na feature; NaN, NaN maps to EMPTY as_wkt(xy(NaN, NaN)) as_wkt(xy(NA, NA))
XY vector extractors
xy_x(x) xy_y(x) xy_z(x) xy_m(x)
xy_x(x) xy_y(x) xy_z(x) xy_m(x)
x |
An |
Components of the xy()
vector or NULL if the dimension is missing
x <- xyz(1:5, 6:10, 11:15) xy_x(x) xy_y(x) xy_z(x) xy_m(x)
x <- xyz(1:5, 6:10, 11:15) xy_x(x) xy_y(x) xy_z(x) xy_m(x)