linestring: Make WKT linestring objects

Description Usage Arguments See Also Examples

View source: R/linestring.R

Description

Make WKT linestring objects

Usage

1
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

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## 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)

Example output

Attaching package: 'wellknown'

The following object is masked from 'package:graphics':

    polygon

[1] "LINESTRING EMPTY"
[1] "LINESTRING (-116.4 45.2, -118.0 47.0)"
[1] "LINESTRING (100.00 0.00, 101.00 1.00)"
[1] "LINESTRING (100.00 0.00, 101.00 1.00, 120.00 5.00)"
[1] "LINESTRING Z(0.00 0.00 10.00, 2.00 1.00 20.00, 4.00 2.00 30.00, 5.00 4.00 40.00)"
[1] "LINESTRING ZM(0.00 0.00 10.00 5.00, 2.00 1.00 20.00 5.00, 4.00 2.00 30.00 5.00, 5.00 4.00 40.00 5.00)"
[1] "LINESTRING (-116.4 45.2, -118.0 47.0)"
[1] "LINESTRING (-116.4 45.2, -118.0 47.0, -120.0 49.0)"
[1] "LINESTRING Z(-116.4 45.2 46.0, -118.0 47.0 41.0, -120.0 49.0 41.0)"
[1] "LINESTRING M(-116.4 45.2 46.0, -118.0 47.0 41.0, -120.0 49.0 41.0)"
[1] "LINESTRING ZM(-116.4 45.2 46.0 0.2, -118.0 47.0 41.0 0.0, -120.0 49.0 41.0 0.3)"
[1] "LINESTRING (-116.4 45.2, -118.0 47.0)"
[1] "LINESTRING (-116.4 45.2, -118.0 47.0, -120.0 49.0)"
[1] "POLYGON Z((45.20 49.00 41.00, 47.00 46.00 41.00))"
[1] "POLYGON M((45.20 49.00 41.00, 47.00 46.00 41.00))"
[1] "POLYGON ZM((-116.40 45.20 46.00 0.20, -118.00 47.00 41.00 0.00, -120.00 49.00 41.00 0.30))"
[1] "LINESTRING (100.00 0.00, 101.00 1.00)"
[1] "LINESTRING Z(100.00 0.00 1.00, 101.00 0.00 1.00, 101.00 1.00 1.00, 100.00 0.00 1.00)"
[1] "LINESTRING M(100.00 0.00 1.00, 101.00 0.00 1.00, 101.00 1.00 1.00, 100.00 0.00 1.00)"
[1] "LINESTRING ZM(100.00 0.00 1.00 40.00, 101.00 0.00 1.00 44.00, 101.00 1.00 1.00 45.00, 100.00 0.00 1.00 49.00)"

wellknown documentation built on May 26, 2021, 1:06 a.m.