constructs sfg MULTILINESTRING object

sfg_multilinestring(
  obj,
  x = NULL,
  y = NULL,
  z = NULL,
  m = NULL,
  linestring_id = NULL
)

Arguments

obj

matrix or data.frame

x

x geometry column

y

y geometry column

z

z geometry column

m

m geometry column

linestring_id

column of ids for lines

Value

sfg object of MULTILINESTRING geometry

Examples


sfg_multilinestring( matrix( 1:24, ncol = 2 ) )
#> [[1]]
#>       [,1] [,2]
#>  [1,]    1   13
#>  [2,]    2   14
#>  [3,]    3   15
#>  [4,]    4   16
#>  [5,]    5   17
#>  [6,]    6   18
#>  [7,]    7   19
#>  [8,]    8   20
#>  [9,]    9   21
#> [10,]   10   22
#> [11,]   11   23
#> [12,]   12   24
#> 
#> attr(,"class")
#> [1] "XY"              "MULTILINESTRING" "sfg"            
sfg_multilinestring( matrix( 1:24, ncol = 3 ) )
#> [[1]]
#>      [,1] [,2] [,3]
#> [1,]    1    9   17
#> [2,]    2   10   18
#> [3,]    3   11   19
#> [4,]    4   12   20
#> [5,]    5   13   21
#> [6,]    6   14   22
#> [7,]    7   15   23
#> [8,]    8   16   24
#> 
#> attr(,"class")
#> [1] "XYZ"             "MULTILINESTRING" "sfg"            
sfg_multilinestring( matrix( 1:24, ncol = 4 ) )
#> [[1]]
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    7   13   19
#> [2,]    2    8   14   20
#> [3,]    3    9   15   21
#> [4,]    4   10   16   22
#> [5,]    5   11   17   23
#> [6,]    6   12   18   24
#> 
#> attr(,"class")
#> [1] "XYZM"            "MULTILINESTRING" "sfg"            

## different lines
m <- cbind( matrix( 1:24, ncol = 2 ), c(rep(1, 6), rep(2, 6) ) )
sfg_multilinestring( obj = m, x = 1, y = 2, linestring_id = 3 )
#> [[1]]
#>      [,1] [,2]
#> [1,]    1   13
#> [2,]    2   14
#> [3,]    3   15
#> [4,]    4   16
#> [5,]    5   17
#> [6,]    6   18
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]    7   19
#> [2,]    8   20
#> [3,]    9   21
#> [4,]   10   22
#> [5,]   11   23
#> [6,]   12   24
#> 
#> attr(,"class")
#> [1] "XY"              "MULTILINESTRING" "sfg"            

## just specifying linestring_id will use all others as the geometries
sfg_multilinestring( obj = m, linestring_id = 3 )
#> [[1]]
#>      [,1] [,2]
#> [1,]    1   13
#> [2,]    2   14
#> [3,]    3   15
#> [4,]    4   16
#> [5,]    5   17
#> [6,]    6   18
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]    7   19
#> [2,]    8   20
#> [3,]    9   21
#> [4,]   10   22
#> [5,]   11   23
#> [6,]   12   24
#> 
#> attr(,"class")
#> [1] "XY"              "MULTILINESTRING" "sfg"            

df <- data.frame( x = 1:12, y = 1:12, z = 13:24, id = c(rep(1,6), rep(2,6)))
sfg_multilinestring( df, x = "x", y = "y" )
#> [[1]]
#>       [,1] [,2]
#>  [1,]    1    1
#>  [2,]    2    2
#>  [3,]    3    3
#>  [4,]    4    4
#>  [5,]    5    5
#>  [6,]    6    6
#>  [7,]    7    7
#>  [8,]    8    8
#>  [9,]    9    9
#> [10,]   10   10
#> [11,]   11   11
#> [12,]   12   12
#> 
#> attr(,"class")
#> [1] "XY"              "MULTILINESTRING" "sfg"            
sfg_multilinestring( df, x = "x", y = "y", linestring_id = "id" )
#> [[1]]
#>      [,1] [,2]
#> [1,]    1    1
#> [2,]    2    2
#> [3,]    3    3
#> [4,]    4    4
#> [5,]    5    5
#> [6,]    6    6
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]    7    7
#> [2,]    8    8
#> [3,]    9    9
#> [4,]   10   10
#> [5,]   11   11
#> [6,]   12   12
#> 
#> attr(,"class")
#> [1] "XY"              "MULTILINESTRING" "sfg"            

sfg_multilinestring( df, linestring_id = "id" )
#> [[1]]
#>      [,1] [,2] [,3]
#> [1,]    1    1   13
#> [2,]    2    2   14
#> [3,]    3    3   15
#> [4,]    4    4   16
#> [5,]    5    5   17
#> [6,]    6    6   18
#> 
#> [[2]]
#>      [,1] [,2] [,3]
#> [1,]    7    7   19
#> [2,]    8    8   20
#> [3,]    9    9   21
#> [4,]   10   10   22
#> [5,]   11   11   23
#> [6,]   12   12   24
#> 
#> attr(,"class")
#> [1] "XYZ"             "MULTILINESTRING" "sfg"