# NOT RUN {
## 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)
# }
Run the code above in your browser using DataLab