constructs an sf of MULTILINESTRING objects
Usage
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.
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.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, 0.13167063, 0.48862881, -1.69945057, -1.47073631, 0.28415034, 1.33732041, 0.23669628, 1.31829338, 0.52390979, 0.60674805, -0.10993567, 0.17218172, -0.09032729, 1.92434334, 1.29839276, 0.74879127, 0.55622433, -0.54825726, 1.11053489, -2.61233433
sf_multilinestring( obj = df, x = "x", y = "y", z = "z")
#> id
#> 1 1
#> geometry
#> 1 -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, 0.13167063, 0.48862881, -1.69945057, -1.47073631, 0.28415034, 1.33732041, 0.23669628, 1.31829338, 0.52390979, 0.60674805, -0.10993567, 0.17218172, -0.09032729, 1.92434334, 1.29839276, 0.74879127, 0.55622433, -0.54825726, 1.11053489, -2.61233433, -0.15569378, 0.43388979, -0.38195111, 0.42418757, 1.06310200, 1.04871262, -0.03810289, 0.48614892, 1.67288261, -0.35436116, 0.94634789, 1.31682636, -0.29664002
sf_multilinestring( obj = df, x = "x", y = "y", z = "z", m = "m")
#> id
#> 1 1
#> geometry
#> 1 -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, 0.13167063, 0.48862881, -1.69945057, -1.47073631, 0.28415034, 1.33732041, 0.23669628, 1.31829338, 0.52390979, 0.60674805, -0.10993567, 0.17218172, -0.09032729, 1.92434334, 1.29839276, 0.74879127, 0.55622433, -0.54825726, 1.11053489, -2.61233433, -0.15569378, 0.43388979, -0.38195111, 0.42418757, 1.06310200, 1.04871262, -0.03810289, 0.48614892, 1.67288261, -0.35436116, 0.94634789, 1.31682636, -0.29664002, -0.38721358, -0.78543266, -1.05673687, -0.79554143, -1.75627543, -0.69053790, -0.55854199, -0.53666333, 0.22712713, 0.97845492, -0.20888265, -1.39941046, 0.25853729
sf_multilinestring( obj = df, x = 3, y = 4)
#> id
#> 1 1
#> geometry
#> 1 -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, 0.13167063, 0.48862881, -1.69945057, -1.47073631, 0.28415034, 1.33732041, 0.23669628, 1.31829338, 0.52390979, 0.60674805, -0.10993567, 0.17218172, -0.09032729, 1.92434334, 1.29839276, 0.74879127, 0.55622433, -0.54825726, 1.11053489, -2.61233433
sf_multilinestring( obj = df, x = 3, y = 4, z = 5)
#> id
#> 1 1
#> geometry
#> 1 -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, 0.13167063, 0.48862881, -1.69945057, -1.47073631, 0.28415034, 1.33732041, 0.23669628, 1.31829338, 0.52390979, 0.60674805, -0.10993567, 0.17218172, -0.09032729, 1.92434334, 1.29839276, 0.74879127, 0.55622433, -0.54825726, 1.11053489, -2.61233433, -0.15569378, 0.43388979, -0.38195111, 0.42418757, 1.06310200, 1.04871262, -0.03810289, 0.48614892, 1.67288261, -0.35436116, 0.94634789, 1.31682636, -0.29664002
sf_multilinestring( obj = df, x = 3, y = 4, z = 5, m = 6 )
#> id
#> 1 1
#> geometry
#> 1 -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, 0.13167063, 0.48862881, -1.69945057, -1.47073631, 0.28415034, 1.33732041, 0.23669628, 1.31829338, 0.52390979, 0.60674805, -0.10993567, 0.17218172, -0.09032729, 1.92434334, 1.29839276, 0.74879127, 0.55622433, -0.54825726, 1.11053489, -2.61233433, -0.15569378, 0.43388979, -0.38195111, 0.42418757, 1.06310200, 1.04871262, -0.03810289, 0.48614892, 1.67288261, -0.35436116, 0.94634789, 1.31682636, -0.29664002, -0.38721358, -0.78543266, -1.05673687, -0.79554143, -1.75627543, -0.69053790, -0.55854199, -0.53666333, 0.22712713, 0.97845492, -0.20888265, -1.39941046, 0.25853729
sf_multilinestring( obj = df, multilinestring_id = "ml_id", linestring_id = "l_id" )
#> ml_id
#> 1 1
#> 2 2
#> geometry
#> 1 -0.66508825, 1.11395242, -0.24589641, 1.31829338, 0.52390979, 0.60674805, -0.15569378, 0.43388979, -0.38195111, -0.38721358, -0.78543266, -1.05673687, -1.17756331, -0.97585062, -0.10993567, 0.17218172, 0.42418757, 1.06310200, -0.79554143, -1.75627543, 1.06505732, 0.13167063, 0.48862881, -0.09032729, 1.92434334, 1.29839276, 1.04871262, -0.03810289, 0.48614892, -0.69053790, -0.55854199, -0.53666333
#> 2 -1.6994506, -1.4707363, 0.2841503, 0.7487913, 0.5562243, -0.5482573, 1.6728826, -0.3543612, 0.9463479, 0.2271271, 0.9784549, -0.2088827, 1.3373204, 0.2366963, 1.1105349, -2.6123343, 1.3168264, -0.2966400, -1.3994105, 0.2585373
sf_multilinestring( obj = df, multilinestring_id = 1, linestring_id = 2 )
#> id
#> 1 1
#> 2 2
#> geometry
#> 1 -0.66508825, 1.11395242, -0.24589641, 1.31829338, 0.52390979, 0.60674805, -0.15569378, 0.43388979, -0.38195111, -0.38721358, -0.78543266, -1.05673687, -1.17756331, -0.97585062, -0.10993567, 0.17218172, 0.42418757, 1.06310200, -0.79554143, -1.75627543, 1.06505732, 0.13167063, 0.48862881, -0.09032729, 1.92434334, 1.29839276, 1.04871262, -0.03810289, 0.48614892, -0.69053790, -0.55854199, -0.53666333
#> 2 -1.6994506, -1.4707363, 0.2841503, 0.7487913, 0.5562243, -0.5482573, 1.6728826, -0.3543612, 0.9463479, 0.2271271, 0.9784549, -0.2088827, 1.3373204, 0.2366963, 1.1105349, -2.6123343, 1.3168264, -0.2966400, -1.3994105, 0.2585373