constructs an sf of MULTILINESTRING objects

sf_multilinestring(
  obj = NULL,
  x = NULL,
  y = NULL,
  z = NULL,
  m = NULL,
  multilinestring_id = NULL,
  linestring_id = NULL,
  keep = FALSE,
  list_columns = NULL
)

Arguments

obj

sorted matrix or data.frame

x

x geometry column

y

y geometry column

z

z geometry column

m

m geometry column

multilinestring_id

column of ids for multilinestrings

linestring_id

column of ids for linestrings (within multilinestrings)

keep

logical indicating if the non-geometry and non-id columns should be kept. if TRUE you must supply the geometry and id columns, and only the first row of each geometry is kept. See Keeping Properties.

list_columns

vector of column names to turn into a list.

Value

sf object of MULTILINESTRING geometries

notes

sfheaders functions do not perform any validity checks on the geometries. Nor do they set Coordinate Reference Systems, EPSG, PROJ4 or precision attributes.

The data.frame and matrices you send into the sfheader functions must be ordered.

Keeping Properties

Setting keep = TRUE will retain any columns not specified as a coordinate (x, y, z, m) or an id (e.g., linestring_id, polygon_id) of the input obj.

You can use list_columns to specify which of the properties will be turned into a list, thus keeping all the values in the column. For columns not specified in list_columns, only the first row of the column is kept

The sf_* functions assume the input obj is a long data.frame / matrix, where any properties are repeated down the table for the same geometry.

Examples


m <- matrix(c(0,0,0,0,1,1), ncol = 3 )
sf_multilinestring( m )
#>   id         geometry
#> 1  1 0, 0, 0, 0, 1, 1

m <- matrix(c(0,0,0,0,0,1,0,1,1,1,2,2,1,2,3), ncol = 3, byrow = TRUE)
sf_multilinestring( obj = m )
#>   id                                    geometry
#> 1  1 0, 0, 0, 1, 1, 0, 0, 1, 2, 2, 0, 1, 1, 2, 3
sf_multilinestring( obj = m, multilinestring_id = 1 )
#>   id         geometry
#> 1  0 0, 0, 1, 0, 1, 1
#> 2  1       2, 2, 2, 3
sf_multilinestring( obj = m, linestring_id = 1 )
#>   id                     geometry
#> 1  1 0, 0, 1, 0, 1, 1, 2, 2, 2, 3

sf_multilinestring( obj = m, linestring_id = 1, multilinestring_id = 1 )
#>   id         geometry
#> 1  0 0, 0, 1, 0, 1, 1
#> 2  1       2, 2, 2, 3

sf_multilinestring( obj = m, x = 2, y = 3 )
#>   id                     geometry
#> 1  1 0, 0, 1, 2, 2, 0, 1, 1, 2, 3
sf_multilinestring( obj = m, x = 1, y = 2, z = 3 )
#>   id                                    geometry
#> 1  1 0, 0, 0, 1, 1, 0, 0, 1, 2, 2, 0, 1, 1, 2, 3
sf_multilinestring( obj = m, x = 2, y = 3, linestring_id = 1, multilinestring_id = 1 )
#>   id         geometry
#> 1  0 0, 0, 1, 0, 1, 1
#> 2  1       2, 2, 2, 3

df <- data.frame(
  ml_id = c(1,1,1,1,1,1,1,1,2,2,2,2,2)
  , l_id = c(1,1,1,2,2,3,3,3,1,1,1,2,2)
  , x = rnorm(13)
  , y = rnorm(13)
  , z = rnorm(13)
  , m = rnorm(13)
)

sf_multilinestring( obj = df, x = "x", y = "y")
#>   id
#> 1  1
#>                                                                                                                                                                                                                                                                                                                           geometry
#> 1 -0.11845380, -0.70156253, 1.12412292, 0.37429602, 1.61446468, 1.25908901, -1.04488829, 0.21135836, 0.73334343, 0.72955620, -0.20900603, -0.38516694, -0.43113168, -0.12050301, 0.67970583, 0.68267350, 0.86510713, -0.51003232, -0.17156571, 1.68243773, -1.30170864, 0.90042502, 2.24907115, 0.63216560, 1.92451440, 0.01867461
sf_multilinestring( obj = df, x = "x", y = "y", z = "z")
#>   id
#> 1  1
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                geometry
#> 1 -0.11845380, -0.70156253, 1.12412292, 0.37429602, 1.61446468, 1.25908901, -1.04488829, 0.21135836, 0.73334343, 0.72955620, -0.20900603, -0.38516694, -0.43113168, -0.12050301, 0.67970583, 0.68267350, 0.86510713, -0.51003232, -0.17156571, 1.68243773, -1.30170864, 0.90042502, 2.24907115, 0.63216560, 1.92451440, 0.01867461, 0.20473938, -0.95377671, -1.18377260, -0.96286689, 0.75064300, -1.01811538, -1.58608844, -0.20955933, -0.01092492, -2.85779234, -0.29850981, 0.07158526, 1.69689332
sf_multilinestring( obj = df, x = "x", y = "y", z = "z", m = "m")
#>   id
#> 1  1
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    geometry
#> 1 -0.11845380, -0.70156253, 1.12412292, 0.37429602, 1.61446468, 1.25908901, -1.04488829, 0.21135836, 0.73334343, 0.72955620, -0.20900603, -0.38516694, -0.43113168, -0.12050301, 0.67970583, 0.68267350, 0.86510713, -0.51003232, -0.17156571, 1.68243773, -1.30170864, 0.90042502, 2.24907115, 0.63216560, 1.92451440, 0.01867461, 0.20473938, -0.95377671, -1.18377260, -0.96286689, 0.75064300, -1.01811538, -1.58608844, -0.20955933, -0.01092492, -2.85779234, -0.29850981, 0.07158526, 1.69689332, 0.87582994, -0.47409377, 0.62025023, -1.02061225, 1.49759178, -0.23664778, 0.22182987, 0.01253167, -0.77337760, -0.03627684, -0.81707413, -0.10558793, -0.08450654

sf_multilinestring( obj = df, x = 3, y = 4)
#>   id
#> 1  1
#>                                                                                                                                                                                                                                                                                                                           geometry
#> 1 -0.11845380, -0.70156253, 1.12412292, 0.37429602, 1.61446468, 1.25908901, -1.04488829, 0.21135836, 0.73334343, 0.72955620, -0.20900603, -0.38516694, -0.43113168, -0.12050301, 0.67970583, 0.68267350, 0.86510713, -0.51003232, -0.17156571, 1.68243773, -1.30170864, 0.90042502, 2.24907115, 0.63216560, 1.92451440, 0.01867461
sf_multilinestring( obj = df, x = 3, y = 4, z = 5)
#>   id
#> 1  1
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                geometry
#> 1 -0.11845380, -0.70156253, 1.12412292, 0.37429602, 1.61446468, 1.25908901, -1.04488829, 0.21135836, 0.73334343, 0.72955620, -0.20900603, -0.38516694, -0.43113168, -0.12050301, 0.67970583, 0.68267350, 0.86510713, -0.51003232, -0.17156571, 1.68243773, -1.30170864, 0.90042502, 2.24907115, 0.63216560, 1.92451440, 0.01867461, 0.20473938, -0.95377671, -1.18377260, -0.96286689, 0.75064300, -1.01811538, -1.58608844, -0.20955933, -0.01092492, -2.85779234, -0.29850981, 0.07158526, 1.69689332
sf_multilinestring( obj = df, x = 3, y = 4, z = 5, m = 6 )
#>   id
#> 1  1
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    geometry
#> 1 -0.11845380, -0.70156253, 1.12412292, 0.37429602, 1.61446468, 1.25908901, -1.04488829, 0.21135836, 0.73334343, 0.72955620, -0.20900603, -0.38516694, -0.43113168, -0.12050301, 0.67970583, 0.68267350, 0.86510713, -0.51003232, -0.17156571, 1.68243773, -1.30170864, 0.90042502, 2.24907115, 0.63216560, 1.92451440, 0.01867461, 0.20473938, -0.95377671, -1.18377260, -0.96286689, 0.75064300, -1.01811538, -1.58608844, -0.20955933, -0.01092492, -2.85779234, -0.29850981, 0.07158526, 1.69689332, 0.87582994, -0.47409377, 0.62025023, -1.02061225, 1.49759178, -0.23664778, 0.22182987, 0.01253167, -0.77337760, -0.03627684, -0.81707413, -0.10558793, -0.08450654

sf_multilinestring( obj = df, multilinestring_id = "ml_id", linestring_id = "l_id" )
#>   ml_id
#> 1     1
#> 2     2
#>                                                                                                                                                                                                                                                                                                                                                                                                         geometry
#> 1 -0.11845380, -0.70156253, 1.12412292, -0.12050301, 0.67970583, 0.68267350, 0.20473938, -0.95377671, -1.18377260, 0.87582994, -0.47409377, 0.62025023, 0.37429602, 1.61446468, 0.86510713, -0.51003232, -0.96286689, 0.75064300, -1.02061225, 1.49759178, 1.25908901, -1.04488829, 0.21135836, -0.17156571, 1.68243773, -1.30170864, -1.01811538, -1.58608844, -0.20955933, -0.23664778, 0.22182987, 0.01253167
#> 2                                                                                                                                                      0.73334343, 0.72955620, -0.20900603, 0.90042502, 2.24907115, 0.63216560, -0.01092492, -2.85779234, -0.29850981, -0.77337760, -0.03627684, -0.81707413, -0.38516694, -0.43113168, 1.92451440, 0.01867461, 0.07158526, 1.69689332, -0.10558793, -0.08450654
sf_multilinestring( obj = df, multilinestring_id = 1, linestring_id = 2 )
#>   id
#> 1  1
#> 2  2
#>                                                                                                                                                                                                                                                                                                                                                                                                         geometry
#> 1 -0.11845380, -0.70156253, 1.12412292, -0.12050301, 0.67970583, 0.68267350, 0.20473938, -0.95377671, -1.18377260, 0.87582994, -0.47409377, 0.62025023, 0.37429602, 1.61446468, 0.86510713, -0.51003232, -0.96286689, 0.75064300, -1.02061225, 1.49759178, 1.25908901, -1.04488829, 0.21135836, -0.17156571, 1.68243773, -1.30170864, -1.01811538, -1.58608844, -0.20955933, -0.23664778, 0.22182987, 0.01253167
#> 2                                                                                                                                                      0.73334343, 0.72955620, -0.20900603, 0.90042502, 2.24907115, 0.63216560, -0.01092492, -2.85779234, -0.29850981, -0.77337760, -0.03627684, -0.81707413, -0.38516694, -0.43113168, 1.92451440, 0.01867461, 0.07158526, 1.69689332, -0.10558793, -0.08450654