Description Usage Arguments Details Examples
A geovctr is a geometry-like collection of objects. In the geovctrs
package, wkt()
, wkb()
, geo_collection()
,
geo_xy()
, geo_rect()
, and geo_segment()
are all geovctrs.
Extension packages can either use these types or
implement the as_geovctr()
generic
to take advantage of a wide range of processing functions, including
coercion, plotting, and summary information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | is_geovctr(x)
as_geovctr(x, ...)
## S3 method for class 'character'
as_geovctr(x, ...)
## S3 method for class 'data.frame'
as_geovctr(x, ...)
restore_geovctr(x, result, ...)
## Default S3 method:
restore_geovctr(x, result, ...)
## S3 method for class 'data.frame'
restore_geovctr(x, result, ...)
expect_geovctr(x)
## S3 method for class 'sfc'
as_geovctr(x, ...)
## S3 method for class 'sf'
as_geovctr(x, ...)
## S3 method for class 'sfc'
restore_geovctr(x, result, ...)
## S3 method for class 'sf'
restore_geovctr(x, result, ...)
|
x |
A (possibly) geovctr |
... |
Passed to the constructor |
result |
The result of a transformation operation |
This package is intended to allow for a variety of in-memory
representations of geometry, as there are many examples where
simple geometries can be efficiently parameterized without
resorting to storing every coordinate of every vertex
(built-in examples include geo_xy()
, geo_segment()
, and
geo_rect()
). These types do, however, have unambiguous
representations as geometries, and thus should be able to be
used wherever a geometry is appropriate.
For an object to be a "geovctr", it must:
Be a vctr (vctrs::vec_is()
must be TRUE
). This ensures that it will
work with tibble::tibble()
and other tidyverse functions such as
tidyr::unnest()
and dplyr::group_by()
/ dplyr::mutate()
/
dplyr::summarise()
.
Have is_geovctr()
return TRUE
. This makes it work automatically with
functions like geo_bbox()
that have a default
implementation for something that can be coerced to wkt()
,
wkb()
, or wksxp()
.
Have the ability to be coerced to wkt()
, wkb()
, and wksxp()
using as_wkt()
, as_wkb()
, and as_wksxp()
.
These casts power the default implementations of
functions like geo_bbox()
. In addition, a vctrs::vec_cast()
method should be provided so that row-binding and other vector
operations work with functions that might return a simpler type.
Have the ability to be combined with wkt()
, wkb()
, and wksxp()
using vec_c()
in both directions. This helps support processing functions
that return a class to be combined with the output of other functions.
This might require a vctrs::vec_ptype()
implementation for
a class.
You can test these expectations for a given object using expect_geovctr()
.
A secondary class of object is one that could be interpreted as a geovctr,
but in most cases can't be. One example of this is a character vector,
which could be well-known text, but probably isn't. However, when the
user passes it to a function like geo_bbox()
, it
probably is well-known text. Similarly, a data.frame
or
tibble::tibble()
probably doesn't contain a geometry column,
but when passed to a function that operates on geometries,
it's likely that it does. The geovctrs package supports these
objects with the as_geovctr()
generic, which means you can
pass these objects anywhere you would pass a first-class
geometry vector.
1 2 3 4 5 6 | is_geovctr(wkt())
is_geovctr(NULL)
as_geovctr(wkt("POINT (30 10)"))
as_geovctr("POINT (30 10)")
as_geovctr(tibble::tibble(geometry = wkt("POINT (30 10)")))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.