pkern_coords: Return coordinates of a grid of points in column-vectorized...

View source: R/pkern_index.R

pkern_coordsR Documentation

Return coordinates of a grid of points in column-vectorized order

Description

Expands a set of y and x grid line numbers in the column-vectorized order returned by pkern_grid.

Usage

pkern_coords(g, out = "matrix", corner = FALSE, quiet = FALSE)

Arguments

g

any object accepted by pkern_grid

out

character indicating return value type, either 'list', 'matrix', or 'sf'

corners

logical, indicates to only return the corner points

Details

This is similar to base::expand.grid but with the first dimension (y) descending instead of ascending.

out='sf' returns an sf simple features object containing points in the same order, with data (if any) copied from g$gval into column 'gval'. Note that prod(g$gdim) points are created, which can be slow for large grids.

Value

a matrix, list, or sf POINT collection, in column vectorized order

Examples

gdim = c(5,3)
g_example = pkern_grid(list(gdim=gdim, gres=c(0.5, 0.7), gval=seq(prod(gdim))))
pkern_coords(g_example)
pkern_coords(g_example, out='list')

# corner points
pkern_coords(g_example, corner=TRUE)
pkern_coords(g_example, corner=TRUE, out='list')

# sf output type
if( requireNamespace('sf') ) {

# make the points
sf_coords = pkern_coords(g_example, out='sf')

# data are copied to variable 'gval'
plot(sf_coords, pch=16)

}


deankoch/pkern documentation built on Oct. 26, 2023, 8:54 p.m.