is_geovctr: Test for geovctrs

Description Usage Arguments Details Examples

View source: R/geovctr.R

Description

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.

Usage

 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, ...)

Arguments

x

A (possibly) geovctr

...

Passed to the constructor

result

The result of a transformation operation

Details

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:

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.

Examples

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)")))

paleolimbot/geovctrs documentation built on July 30, 2020, 3:41 p.m.