constructs an sf of POLYGON objects

sf_polygon(obj = NULL, x = NULL, y = NULL, z = NULL, m = NULL,
  polygon_id = NULL, linestring_id = NULL, close = TRUE,
  keep = FALSE)

Arguments

obj

sorted matrix or data.frame

x

x geometry column

y

y geometry column

z

z geometry column

m

m geometry column

polygon_id

column of ids for polygons

linestring_id

column of ids for lines (within polygons)

close

logical indicating whether polygons should be closed. If TRUE, all polygons will be checked and force closed if possible

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.

Value

sf object of POLYGON 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 the first row of any columns not specified as a coordinate (x, y, z, m) or an id (e.g., linestring_id, polygon_id) of the input obj.

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 = 2 ) sf_polygon( m )
#> id geometry #> 1 1 0, 0, 0, 0, 0, 1, 1, 0
m <- matrix(c(0,0,0,0,0,1,0,1,1,1,2,2,1,2,3,1,3,4), ncol = 3, byrow = TRUE) sf_polygon( obj = m )
#> id geometry #> 1 1 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 2, 2, 3, 0, 0, 1, 1, 2, 3, 4, 0
sf_polygon( obj = m, polygon_id = 1 )
#> id geometry #> 1 0 0, 0, 1, 0, 0, 1, 1, 0 #> 2 1 2, 2, 3, 2, 2, 3, 4, 2
sf_polygon( obj = m, linestring_id = 1 )
#> id geometry #> 1 1 0, 0, 1, 0, 0, 1, 1, 0, 2, 2, 3, 2, 2, 3, 4, 2
sf_polygon( obj = m, linestring_id = 1, polygon_id = 1 )
#> id geometry #> 1 0 0, 0, 1, 0, 0, 1, 1, 0 #> 2 1 2, 2, 3, 2, 2, 3, 4, 2
sf_polygon( obj = m, x = 2, y = 3 )
#> id geometry #> 1 1 0, 0, 1, 2, 2, 3, 0, 0, 1, 1, 2, 3, 4, 0
sf_polygon( obj = m, x = 1, y = 2, z = 3 )
#> id geometry #> 1 1 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 2, 2, 3, 0, 0, 1, 1, 2, 3, 4, 0
sf_polygon( obj = m, x = 2, y = 3, linestring_id = 1, polygon_id = 1 )
#> id geometry #> 1 0 0, 0, 1, 0, 0, 1, 1, 0 #> 2 1 2, 2, 3, 2, 2, 3, 4, 2
df <- data.frame( ml_id = c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2) , l_id = c(1,1,1,2,2,2,3,3,3,1,1,1,2,2,2) , x = rnorm(15) , y = rnorm(15) , z = rnorm(15) , m = rnorm(15) ) sf_polygon( obj = df, x = "x", y = "y")
#> id #> 1 1 #> geometry #> 1 -0.20608719, 0.01917759, 0.02956075, 0.54982754, -2.27411486, 2.68255718, -0.36122126, 0.21335575, 1.07434588, -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, -0.20608719, 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.13167063
sf_polygon( obj = df, x = "x", y = "y", z = "z")
#> id #> 1 1 #> geometry #> 1 -0.20608719, 0.01917759, 0.02956075, 0.54982754, -2.27411486, 2.68255718, -0.36122126, 0.21335575, 1.07434588, -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, -0.20608719, 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.13167063, 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.74879127
sf_polygon( obj = df, x = "x", y = "y", z = "z", m = "m")
#> id #> 1 1 #> geometry #> 1 -0.20608719, 0.01917759, 0.02956075, 0.54982754, -2.27411486, 2.68255718, -0.36122126, 0.21335575, 1.07434588, -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, -0.20608719, 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.13167063, 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.74879127, 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.94634789
sf_polygon( obj = df, x = 2, y = 3)
#> id #> 1 1 #> geometry #> 1 1.00000000, 1.00000000, 1.00000000, 2.00000000, 2.00000000, 2.00000000, 3.00000000, 3.00000000, 3.00000000, 1.00000000, 1.00000000, 1.00000000, 2.00000000, 2.00000000, 2.00000000, 1.00000000, -0.20608719, 0.01917759, 0.02956075, 0.54982754, -2.27411486, 2.68255718, -0.36122126, 0.21335575, 1.07434588, -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, -0.20608719
sf_polygon( obj = df, x = 2, y = 3, z = 4)
#> id #> 1 1 #> geometry #> 1 1.00000000, 1.00000000, 1.00000000, 2.00000000, 2.00000000, 2.00000000, 3.00000000, 3.00000000, 3.00000000, 1.00000000, 1.00000000, 1.00000000, 2.00000000, 2.00000000, 2.00000000, 1.00000000, -0.20608719, 0.01917759, 0.02956075, 0.54982754, -2.27411486, 2.68255718, -0.36122126, 0.21335575, 1.07434588, -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, -0.20608719, 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.13167063
sf_polygon( obj = df, x = 2, y = 3, z = 4, m = 5)
#> id #> 1 1 #> geometry #> 1 1.00000000, 1.00000000, 1.00000000, 2.00000000, 2.00000000, 2.00000000, 3.00000000, 3.00000000, 3.00000000, 1.00000000, 1.00000000, 1.00000000, 2.00000000, 2.00000000, 2.00000000, 1.00000000, -0.20608719, 0.01917759, 0.02956075, 0.54982754, -2.27411486, 2.68255718, -0.36122126, 0.21335575, 1.07434588, -0.66508825, 1.11395242, -0.24589641, -1.17756331, -0.97585062, 1.06505732, -0.20608719, 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.13167063, 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.74879127
sf_polygon( obj = df, polygon_id = "ml_id", linestring_id = "l_id" )
#> ml_id #> 1 1 #> 2 2 #> geometry #> 1 -0.20608719, 0.01917759, 0.02956075, -0.20608719, 0.13167063, 0.48862881, -1.69945057, 0.13167063, 0.74879127, 0.55622433, -0.54825726, 0.74879127, 0.94634789, 1.31682636, -0.29664002, 0.94634789, 0.54982754, -2.27411486, 2.68255718, 0.54982754, -1.47073631, 0.28415034, 1.33732041, -1.47073631, 1.11053489, -2.61233433, -0.15569378, 1.11053489, -0.38721358, -0.78543266, -1.05673687, -0.38721358, -0.36122126, 0.21335575, 1.07434588, -0.36122126, 0.23669628, 1.31829338, 0.52390979, 0.23669628, 0.43388979, -0.38195111, 0.42418757, 0.43388979, -0.79554143, -1.75627543, -0.69053790, -0.79554143 #> 2 -0.66508825, 1.11395242, -0.24589641, -0.66508825, 0.60674805, -0.10993567, 0.17218172, 0.60674805, 1.06310200, 1.04871262, -0.03810289, 1.06310200, -0.55854199, -0.53666333, 0.22712713, -0.55854199, -1.17756331, -0.97585062, 1.06505732, -1.17756331, -0.09032729, 1.92434334, 1.29839276, -0.09032729, 0.48614892, 1.67288261, -0.35436116, 0.48614892, 0.97845492, -0.20888265, -1.39941046, 0.97845492
sf_polygon( obj = df, polygon_id = 1, linestring_id = 2 )
#> id #> 1 1 #> 2 2 #> geometry #> 1 -0.20608719, 0.01917759, 0.02956075, -0.20608719, 0.13167063, 0.48862881, -1.69945057, 0.13167063, 0.74879127, 0.55622433, -0.54825726, 0.74879127, 0.94634789, 1.31682636, -0.29664002, 0.94634789, 0.54982754, -2.27411486, 2.68255718, 0.54982754, -1.47073631, 0.28415034, 1.33732041, -1.47073631, 1.11053489, -2.61233433, -0.15569378, 1.11053489, -0.38721358, -0.78543266, -1.05673687, -0.38721358, -0.36122126, 0.21335575, 1.07434588, -0.36122126, 0.23669628, 1.31829338, 0.52390979, 0.23669628, 0.43388979, -0.38195111, 0.42418757, 0.43388979, -0.79554143, -1.75627543, -0.69053790, -0.79554143 #> 2 -0.66508825, 1.11395242, -0.24589641, -0.66508825, 0.60674805, -0.10993567, 0.17218172, 0.60674805, 1.06310200, 1.04871262, -0.03810289, 1.06310200, -0.55854199, -0.53666333, 0.22712713, -0.55854199, -1.17756331, -0.97585062, 1.06505732, -1.17756331, -0.09032729, 1.92434334, 1.29839276, -0.09032729, 0.48614892, 1.67288261, -0.35436116, 0.48614892, 0.97845492, -0.20888265, -1.39941046, 0.97845492