crs_engine_fun: Transform coordinates using R functions

Description Usage Arguments Value Examples

View source: R/engine-fun.R

Description

Transform coordinates using R functions

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
crs_engine_fun(prepare = wk::wk_crs_proj_definition)

crs_engine_fun_define(engine, crs_to, crs_from, fun)

crs_engine_fun_get(engine, crs_to, crs_from)

crs_transform_fun(
  handleable,
  fun,
  strategy = wk::wk_chunk_strategy_coordinates(chunk_size = 65536)
)

## S3 method for class 'crs2crs_engine_fun'
crs_engine_get_wk_trans(engine, handleable, crs_to, crs_from, ...)

Arguments

prepare

A function that converts CRS objects to a canonical string definition. This reduces the number of function definitions that might otherwise be required to capture the transforms. The default is to use wk::wk_crs_proj_definition(), which returns the shortest possible definition of a CRS that can be used as a PROJ definition (usually something like "EPSG:32620"), falling back to a more verbose definition if an authority string is not found.

engine

A crs_engine_fun()

crs_to

Source and destination coordinate reference systems

crs_from

Source and destination coordinate reference systems

fun

A function that accepts the output of wk::wk_coords() and modifies the x, y, z, and/or m columns. These columns can also be added or removed to set or drop the dimensions of the output.

handleable

A geometry vector (e.g., wkb(), wkt(), xy(), rct(), or sf::st_sfc()) for which wk_handle() is defined.

strategy

A function of handleables and n_features such as that returned by wk_chunk_strategy_feature().

...

engine-specific transformation options

Value

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
engine <- crs_engine_fun()
engine <- crs_engine_fun_define(engine, "EPSG:3857", "OGC:CRS84", function(coords) {
  r <- 6378137
  coords$x <- coords$x * pi / 180 * r
  coords$y <- log(tan(pi / 4 + coords$y * pi / 180 / 2)) * r
  coords
})

crs_transform(
  wk::xy(-64, 45, crs = "OGC:CRS84"),
  "EPSG:3857",
  engine = engine
)

# can also use a function to apply a generic transform
crs_transform_fun(wk::xy(1, 2), function(coords) {
  coords$x <- coords$x * 2
  coords$y <- coords$y * 2
  coords
})

paleolimbot/crs2crs documentation built on Jan. 8, 2022, 6:25 a.m.