linestring: Make WKT linestring objects

View source: R/linestring.R

linestringR Documentation

Make WKT linestring objects

Description

Make WKT linestring objects

Usage

linestring(..., fmt = 16, third = "z")

Arguments

...

A GeoJSON-like object representing a Point, LineString, Polygon, MultiPolygon, etc.

fmt

Format string which indicates the number of digits to display after the decimal point when formatting coordinates. Max: 20

third

(character) Only applicable when there are three dimensions. If m, assign a M value for a measurement, and if z assign a Z value for three-dimenionsal system. Case is ignored. An M value represents a measurement, while a Z value usually represents altitude (but can be something like depth in a water based location).

See Also

Other R-objects: circularstring(), geometrycollection(), multilinestring(), multipoint(), multipolygon(), point(), polygon()

Examples

## empty linestring
linestring("empty")
# linestring("stuff")

## character string
linestring("LINESTRING (-116.4 45.2, -118.0 47.0)")

# numeric
## 2D
linestring(c(100.000, 0.000), c(101.000, 1.000), fmt=2)
linestring(c(100.0, 0.0), c(101.0, 1.0), c(120.0, 5.00), fmt=2)
## 3D
linestring(c(0.0, 0.0, 10.0), c(2.0, 1.0, 20.0),
           c(4.0, 2.0, 30.0), c(5.0, 4.0, 40.0), fmt=2)
## 4D
linestring(c(0.0, 0.0, 10.0, 5.0), c(2.0, 1.0, 20.0, 5.0),
           c(4.0, 2.0, 30.0, 5.0), c(5.0, 4.0, 40.0, 5.0), fmt=2)

# data.frame
df <- data.frame(lon=c(-116.4,-118), lat=c(45.2,47))
linestring(df, fmt=1)
df <- data.frame(lon=c(-116.4,-118,-120), lat=c(45.2,47,49))
linestring(df, fmt=1)
## 3D
df$altitude <- round(runif(NROW(df), 10, 50))
linestring(df, fmt=1)
linestring(df, fmt=1, third = "m")
## 4D
df$weight <- round(runif(NROW(df), 0, 1), 1)
linestring(df, fmt=1)


# matrix
mat <- matrix(c(-116.4,-118, 45.2, 47), ncol = 2)
linestring(mat, fmt=1)
mat2 <- matrix(c(-116.4, -118, -120, 45.2, 47, 49), ncol = 2)
linestring(mat2, fmt=1)
## 3D
mat <- matrix(c(df$long, df$lat, df$altitude), ncol = 3)
polygon(mat, fmt=2)
polygon(mat, fmt=2, third = "m")
## 4D
mat <- matrix(unname(unlist(df)), ncol = 4)
polygon(mat, fmt=2)

# list
linestring(list(c(100.000, 0.000), c(101.000, 1.000)), fmt=2)
## 3D
line <- list(c(100, 0, 1), c(101, 0, 1), c(101, 1, 1),
  c(100, 0, 1))
linestring(line, fmt=2)
linestring(line, fmt=2, third = "m")
## 4D
line <- list(c(100, 0, 1, 40), c(101, 0, 1, 44), c(101, 1, 1, 45),
  c(100, 0, 1, 49))
linestring(line, fmt=2)

ropensci/wellknown documentation built on April 8, 2023, 11:54 p.m.