constructs sf of LINESTRING objects
sf_linestring(
obj = NULL,
x = NULL,
y = NULL,
z = NULL,
m = NULL,
linestring_id = NULL,
keep = FALSE,
list_columns = NULL
)
sorted matrix or data.frame
x geometry column
y geometry column
z geometry column
m geometry column
column of ids for linestrings
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.
vector of column names to turn into a list.
sf
object of LINESTRING geometries
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.
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.
x <- matrix( c(1:8), ncol = 2 )
sf_linestring( x )
#> id geometry
#> 1 1 1, 2, 3, 4, 5, 6, 7, 8
x <- cbind( x, c(1,1,2,2) )
sf_linestring( obj = x, x = 1, y = 2 )
#> id geometry
#> 1 1 1, 2, 3, 4, 5, 6, 7, 8
sf_linestring( obj = x, x = 1, y = 2, linestring_id = 3 )
#> id geometry
#> 1 1 1, 2, 5, 6
#> 2 2 3, 4, 7, 8
x <- data.frame( line_id = 1:2, x = 1:2, y = 2:1 )
sf_linestring( x )
#> id geometry
#> 1 1 1, 2, 1, 2, 2, 1
sf_linestring( x, x = "x", y = "y" )
#> id geometry
#> 1 1 1, 2, 2, 1
sf_linestring( x, x = "y", y = "x" )
#> id geometry
#> 1 1 2, 1, 1, 2
sf_linestring( x, linestring_id = "line_id", x = "x", y = "y")
#> line_id geometry
#> 1 1 1, 2
#> 2 2 2, 1
## keeping properties
x <- data.frame(
line_id = c(1,1,2,2)
, x = 1:4
, y = 4:1
, val = letters[1:4]
, stringsAsFactors = FALSE
)
## first-row of 'val' is kept
sf_linestring( x, x = "x", y = "y", keep = TRUE )
#> line_id val geometry
#> 1 1 a 1, 2, 3, 4, 4, 3, 2, 1
sf_linestring( x, linestring_id = "line_id", x = "x", y = "y", keep = TRUE )
#> line_id val geometry
#> 1 1 a 1, 2, 4, 3
#> 2 2 c 3, 4, 2, 1
## 'val' column converted to a list
sf_linestring( x, linestring_id = "id", x = "x", y = "y", keep = TRUE, list_columns = "val" )
#> line_id line_id val geometry
#> 1 1 1 a, b 1, 2, 4, 3
#> 2 2 2 c, d 3, 4, 2, 1