constructs sfc of LINESTRING objects

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

Arguments

obj

sorted 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 linestrings

Value

sfc object of LINESTRING 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.

Examples


x <- matrix( c(1:4), ncol = 2 )
sfc_linestring( x )
#> [[1]]
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
#> attr(,"class")
#> [1] "XY"         "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    3    2    4 
#> attr(,"class")
#> [1] "bbox"

x <- data.frame( id = 1:2, x = 1:2, y = 2:1 )
sfc_linestring( x )
#> [[1]]
#>      [,1] [,2] [,3]
#> [1,]    1    1    2
#> [2,]    2    2    1
#> attr(,"class")
#> [1] "XYZ"        "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    1    2    2 
#> attr(,"class")
#> [1] "bbox"
#> attr(,"z_range")
#> zmin zmax 
#>    1    2 
#> attr(,"class")
#> [1] "z_range"
sfc_linestring( x, x = "x", y = "y" )
#> [[1]]
#>      [,1] [,2]
#> [1,]    1    2
#> [2,]    2    1
#> attr(,"class")
#> [1] "XY"         "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    1    2    2 
#> attr(,"class")
#> [1] "bbox"
sfc_linestring( x, x = "y", y = "x" )
#> [[1]]
#>      [,1] [,2]
#> [1,]    2    1
#> [2,]    1    2
#> attr(,"class")
#> [1] "XY"         "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    1    2    2 
#> attr(,"class")
#> [1] "bbox"
sfc_linestring( x, linestring_id = "id", x = "x", y = "y")
#> [[1]]
#>      [,1] [,2]
#> [1,]    1    2
#> attr(,"class")
#> [1] "XY"         "LINESTRING" "sfg"       
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]    2    1
#> attr(,"class")
#> [1] "XY"         "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    1    2    2 
#> attr(,"class")
#> [1] "bbox"

df <- data.frame(
  id = c(1,1,1,1,2,2,2)
  , x = 1:7
  , y = 7:1
  , z = 14:8
  , m = 8:14
)

sfc_linestring(df, x = "x", y = "y", linestring_id = "id")
#> [[1]]
#>      [,1] [,2]
#> [1,]    1    7
#> [2,]    2    6
#> [3,]    3    5
#> [4,]    4    4
#> attr(,"class")
#> [1] "XY"         "LINESTRING" "sfg"       
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]    5    3
#> [2,]    6    2
#> [3,]    7    1
#> attr(,"class")
#> [1] "XY"         "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    1    7    7 
#> attr(,"class")
#> [1] "bbox"
sfc_linestring(df, x = "x", y = "y", z = "z", linestring_id = "id")
#> [[1]]
#>      [,1] [,2] [,3]
#> [1,]    1    7   14
#> [2,]    2    6   13
#> [3,]    3    5   12
#> [4,]    4    4   11
#> attr(,"class")
#> [1] "XYZ"        "LINESTRING" "sfg"       
#> 
#> [[2]]
#>      [,1] [,2] [,3]
#> [1,]    5    3   10
#> [2,]    6    2    9
#> [3,]    7    1    8
#> attr(,"class")
#> [1] "XYZ"        "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    1    7    7 
#> attr(,"class")
#> [1] "bbox"
#> attr(,"z_range")
#> zmin zmax 
#>    8   14 
#> attr(,"class")
#> [1] "z_range"
sfc_linestring(df, x = "x", y = "y", m = "m", linestring_id = "id")
#> [[1]]
#>      [,1] [,2] [,3]
#> [1,]    1    7    8
#> [2,]    2    6    9
#> [3,]    3    5   10
#> [4,]    4    4   11
#> attr(,"class")
#> [1] "XYM"        "LINESTRING" "sfg"       
#> 
#> [[2]]
#>      [,1] [,2] [,3]
#> [1,]    5    3   12
#> [2,]    6    2   13
#> [3,]    7    1   14
#> attr(,"class")
#> [1] "XYM"        "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    1    7    7 
#> attr(,"class")
#> [1] "bbox"
#> attr(,"m_range")
#> mmin mmax 
#>    8   14 
#> attr(,"class")
#> [1] "m_range"
sfc_linestring(df, x = "x", y = "y", z = "z", m = "m", linestring_id = "id")
#> [[1]]
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    7   14    8
#> [2,]    2    6   13    9
#> [3,]    3    5   12   10
#> [4,]    4    4   11   11
#> attr(,"class")
#> [1] "XYZM"       "LINESTRING" "sfg"       
#> 
#> [[2]]
#>      [,1] [,2] [,3] [,4]
#> [1,]    5    3   10   12
#> [2,]    6    2    9   13
#> [3,]    7    1    8   14
#> attr(,"class")
#> [1] "XYZM"       "LINESTRING" "sfg"       
#> 
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#> 
#> $wkt
#> [1] NA
#> 
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_LINESTRING" "sfc"           
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>    1    1    7    7 
#> attr(,"class")
#> [1] "bbox"
#> attr(,"z_range")
#> zmin zmax 
#>    8   14 
#> attr(,"class")
#> [1] "z_range"
#> attr(,"m_range")
#> mmin mmax 
#>    8   14 
#> attr(,"class")
#> [1] "m_range"