multipolygon: Make WKT multipolygon objects

Description Usage Arguments Details See Also Examples

View source: R/multipolygon.R

Description

Make WKT multipolygon objects

Usage

1
multipolygon(..., 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 multipolygon. There is no way as of yet to make a nested multipolygon with data.frame input, but you can do so with list input. See examples.

See Also

Other R-objects: circularstring(), geometrycollection(), linestring(), multilinestring(), multipoint(), 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
65
66
67
68
69
70
71
72
73
74
75
76
## empty multipolygon
multipolygon("empty")
# multipolygon("stuff")

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

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

# list
multipolygon(list(c(30, 20), c(45, 40), c(10, 40), c(30, 20)),
  list(c(15, 5), c(40, 10), c(10, 20), c(5, 10), c(15, 5)), fmt=2)

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

## nested polygons
polys <- list(
  list(c(40, 40), c(20, 45), c(45, 30), c(40, 40)),
  list(
    list(c(20, 35), c(10, 30), c(10, 10), c(30, 5), c(45, 20), c(20, 35)),
    list(c(30, 20), c(20, 15), c(20, 25), c(30, 20))
  )
)
multipolygon(polys, fmt=0)
lint(multipolygon(polys, fmt=0))



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


# 4D
## data.frame
df <- data.frame(long = c(30, 45, 10, 30), lat = c(20, 40, 40, 20), 
  altitude = 1:4, weigjht = 20:23)
df2 <- data.frame(long = c(15, 40, 10, 5, 15), lat = c(5, 10, 20, 10, 5), 
  altitude = 1:5, weigjht = 200:204)
multipolygon(df, df2, fmt=0)
## matrix
mat <- matrix(unname(unlist(df)), ncol = 4)
mat2 <- matrix(unname(unlist(df2)), ncol = 4)
multipolygon(mat, mat2, fmt=0)
## list
l1 <- list(c(30, 20, 2, 1), c(45, 40, 2, 1), c(10, 40, 2, 1), c(30, 20, 2, 1))
l2 <- list(c(15, 5, 5, 1), c(40, 10, 5, 1), c(10, 20, 5, 1), c(5, 10, 5, 1), 
  c(15, 5, 5, 1))
multipolygon(l1, l2, fmt=2)

Example output

Attaching package: 'wellknown'

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

    polygon

[1] "MULTIPOLYGON EMPTY"
[1] "MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))"
[1] TRUE
[1] "MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))"
[1] "MULTIPOLYGON (((30.00 20.00, 45.00 40.00, 10.00 40.00, 30.00 20.00)), ((15.00 5.00, 40.00 10.00, 10.00 20.00, 5.00 10.00, 15.00 5.00)))"
[1] "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))"
[1] FALSE
[1] "MULTIPOLYGON Z(((30 20 1, 45 40 2, 10 40 3, 30 20 4)), ((15 5 1, 40 10 2, 10 20 3, 5 10 4, 15 5 5)))"
[1] "MULTIPOLYGON M(((30 20 1, 45 40 2, 10 40 3, 30 20 4)), ((15 5 1, 40 10 2, 10 20 3, 5 10 4, 15 5 5)))"
[1] "MULTIPOLYGON Z(((30 20 1, 45 40 2, 10 40 3, 30 20 4)), ((15 5 1, 40 10 2, 10 20 3, 5 10 4, 15 5 5)))"
[1] "MULTIPOLYGON M(((30 20 1, 45 40 2, 10 40 3, 30 20 4)), ((15 5 1, 40 10 2, 10 20 3, 5 10 4, 15 5 5)))"
[1] "MULTIPOLYGON Z(((30.00 20.00 2.00, 45.00 40.00 2.00, 10.00 40.00 2.00, 30.00 20.00 2.00)), ((15.00 5.00 5.00, 40.00 10.00 5.00, 10.00 20.00 5.00, 5.00 10.00 5.00, 15.00 5.00 5.00)))"
[1] "MULTIPOLYGON M(((30.00 20.00 2.00, 45.00 40.00 2.00, 10.00 40.00 2.00, 30.00 20.00 2.00)), ((15.00 5.00 5.00, 40.00 10.00 5.00, 10.00 20.00 5.00, 5.00 10.00 5.00, 15.00 5.00 5.00)))"
[1] "MULTIPOLYGON ZM(((30 20 1 20, 45 40 2 21, 10 40 3 22, 30 20 4 23)), ((15 5 1 200, 40 10 2 201, 10 20 3 202, 5 10 4 203, 15 5 5 204)))"
[1] "MULTIPOLYGON ZM(((30 20 1 20, 45 40 2 21, 10 40 3 22, 30 20 4 23)), ((15 5 1 200, 40 10 2 201, 10 20 3 202, 5 10 4 203, 15 5 5 204)))"
[1] "MULTIPOLYGON ZM(((30.00 20.00 2.00 1.00, 45.00 40.00 2.00 1.00, 10.00 40.00 2.00 1.00, 30.00 20.00 2.00 1.00)), ((15.00 5.00 5.00 1.00, 40.00 10.00 5.00 1.00, 10.00 20.00 5.00 1.00, 5.00 10.00 5.00 1.00, 15.00 5.00 5.00 1.00)))"

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