multilinestring: Make WKT multilinestring objects

Description Usage Arguments Details See Also Examples

View source: R/multilinestring.R

Description

Make WKT multilinestring objects

Usage

1
multilinestring(..., 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).

Details

There is no numeric input option for multilinestring. There is no way as of yet to make a nested multilinestring with data.frame input, but you can do so with list input. See examples.

See Also

Other R-objects: circularstring(), geometrycollection(), linestring(), 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
57
58
59
60
61
62
63
64
## empty multilinestring
multilinestring("empty")
# multilinestring("stuff")

# character string
x <- "MULTILINESTRING ((30 20, 45 40, 10 40), (15 5, 40 10, 10 20))"
multilinestring(x)

# data.frame
df <- data.frame(long = c(30, 45, 10), lat = c(20, 40, 40))
df2 <- data.frame(long = c(15, 40, 10), lat = c(5, 10, 20))
multilinestring(df, df2, fmt=0)
lint(multilinestring(df, df2, fmt=0))
wktview(multilinestring(df, df2), zoom=3)

# matrix
mat <- matrix(c(df$long, df$lat), ncol = 2)
mat2 <- matrix(c(df2$long, df2$lat), ncol = 2)
multilinestring(mat, mat2, fmt=0)

# list
x1 <- list(c(30, 20), c(45, 40), c(10, 40))
x2 <- list(c(15, 5), c(40, 10), c(10, 20))
multilinestring(x1, x2, fmt=2)

polys <- list(
  list(c(30, 20), c(45, 40), c(10, 40)),
  list(c(15, 5), c(40, 10), c(10, 20))
)
wktview(multilinestring(polys, fmt=2), zoom=3)

# 3D
## data.frame
df <- data.frame(long = c(30, 45, 10), lat = c(20, 40, 40), altitude = 1:3)
df2 <- data.frame(long = c(15, 40, 10), lat = c(5, 10, 20), altitude = 1:3)
multilinestring(df, df2, fmt=0)
multilinestring(df, df2, fmt=0, third = "m")
## matrix
mat <- matrix(unname(unlist(df)), ncol = 3)
mat2 <- matrix(unname(unlist(df2)), ncol = 3)
multilinestring(mat, mat2, fmt=0)
multilinestring(mat, mat2, fmt=0, third = "m")
## list
x1 <- list(c(30, 20, 1), c(45, 40, 1), c(10, 40, 1))
x2 <- list(c(15, 5, 0), c(40, 10, 3), c(10, 20, 4))
multilinestring(x1, x2, fmt=2)
multilinestring(x1, x2, fmt=2, third = "m")


# 4D
## data.frame
df <- data.frame(long = c(30, 45, 10), lat = c(20, 40, 40), 
  altitude = 1:3, weight = 4:6)
df2 <- data.frame(long = c(15, 40, 10), lat = c(5, 10, 20), 
  altitude = 1:3, weight = 4:6)
multilinestring(df, df2, fmt=0)
## matrix
mat <- matrix(unname(unlist(df)), ncol = 4)
mat2 <- matrix(unname(unlist(df2)), ncol = 4)
multilinestring(mat, mat2, fmt=0)
## list
x1 <- list(c(30, 20, 1, 40), c(45, 40, 1, 40), c(10, 40, 1, 40))
x2 <- list(c(15, 5, 0, 40), c(40, 10, 3, 40), c(10, 20, 4, 40))
multilinestring(x1, x2, fmt=2)

Example output

Attaching package: 'wellknown'

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

    polygon

[1] "MULTILINESTRING EMPTY"
[1] "MULTILINESTRING ((30 20, 45 40, 10 40), (15 5, 40 10, 10 20))"
[1] "MULTILINESTRING ((30 20, 45 40, 10 40), (15 5, 40 10, 10 20))"
[1] TRUE
[1] "MULTILINESTRING ((30 20, 45 40, 10 40), (15 5, 40 10, 10 20))"
[1] "MULTILINESTRING ((30.00 20.00, 45.00 40.00, 10.00 40.00), (15.00 5.00, 40.00 10.00, 10.00 20.00))"
[1] "MULTILINESTRING Z((30 20 1, 45 40 2, 10 40 3), (15 5 1, 40 10 2, 10 20 3))"
[1] "MULTILINESTRING M((30 20 1, 45 40 2, 10 40 3), (15 5 1, 40 10 2, 10 20 3))"
[1] "MULTILINESTRING Z((30 20 1, 45 40 2, 10 40 3), (15 5 1, 40 10 2, 10 20 3))"
[1] "MULTILINESTRING M((30 20 1, 45 40 2, 10 40 3), (15 5 1, 40 10 2, 10 20 3))"
[1] "MULTILINESTRING Z((30.00 20.00 1.00, 45.00 40.00 1.00, 10.00 40.00 1.00), (15.00 5.00 0.00, 40.00 10.00 3.00, 10.00 20.00 4.00))"
[1] "MULTILINESTRING M((30.00 20.00 1.00, 45.00 40.00 1.00, 10.00 40.00 1.00), (15.00 5.00 0.00, 40.00 10.00 3.00, 10.00 20.00 4.00))"
[1] "MULTILINESTRING ZM((30 20 1 4, 45 40 2 5, 10 40 3 6), (15 5 1 4, 40 10 2 5, 10 20 3 6))"
[1] "MULTILINESTRING ZM((30 20 1 4, 45 40 2 5, 10 40 3 6), (15 5 1 4, 40 10 2 5, 10 20 3 6))"
[1] "MULTILINESTRING ZM((30.00 20.00 1.00 40.00, 45.00 40.00 1.00 40.00, 10.00 40.00 1.00 40.00), (15.00 5.00 0.00 40.00, 40.00 10.00 3.00 40.00, 10.00 20.00 4.00 40.00))"

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