trackline: Create segmented line from points' sequence

tracklineR Documentation

Create segmented line from points' sequence

Description

Connect sequence of points (locations) by direct lines (tracks)

Usage

trackline(obj, by=NULL, connect=c("united", "consequent"), gentle=FALSE)

Arguments

obj

Simple feature (package sf) or Spatial abstract class (package sp) with POINTS spatial geometry.

by

Either field name or NULL. If specified, then value "united" is applied for argument connect, returned spatial object is splitted regarding values of by with linked single-column attribute table with specified field. Default is NULL.

connect

Structure of output segments; either sequence of single segments ("consequent") or single multi-segment ("united").

gentle

Logical. Value TRUE directs repetition of binded columns of data table. Value FALSE omits duplicated column values. Default is FALSE.

Details

Function generates n-1 segments from n input points. Data (attribute table) is trasfered to output object with excluding of first row.

gentle=TRUE may be useful to keep geterogenic data structure for spatial binding (spatial_bind).

Value

Simple feature (package sf) or Spatial abstract class (package sp) with LINESTRING spatial geometry.

Author(s)

Nikita Platonov platonov@sevin.ru

Examples

session_grid(NULL)
n <- 15
lon <- rev(sort(runif(n,min=40,max=60)))
lat <- sort(runif(n,min=30,max=50))
pt <- data.frame(lon=lon,lat=lat,value=seq(n))
if (requireNamespace("sp")) {
   sp::coordinates(pt) <- c("lon","lat")
   sp::proj4string(pt) <- "EPSG:4326"
} else {
   pt <- sf::st_as_sf(pt,coords=c("lon","lat"),crs="WGS84")
}
ct <- ursa_colortable(colorize(pt$value))
tr <- trackline(pt,connect="consequent")
#opW <- options(warn=0)
session_grid(pt,expand=1.1)
compose_open(2)
panel_new()
panel_plot(pt,col=ct)
panel_decor()
panel_new()
panel_plot(tr,col=ct,lwd=3)
panel_decor()
compose_legend(ct,unit="step number")
compose_close()

ursa documentation built on Sept. 30, 2024, 9:35 a.m.