Learn R Programming

sf (version 0.1-1)

ST_as.sf: convert foreign object to an sf object

Description

convert foreign object to an sf object

Usage

ST_as.sf(x, ...)
"ST_as.sf"(x, ..., relation_to_geometry = NA_character_)
"ST_as.sf"(x, ...)

Arguments

x
object to be converted into an object class sf
...
further arguments
relation_to_geometry
character vector; see details section of ST_sf

Examples

Run this code
pt1 = ST_Point(c(0,1))
pt2 = ST_Point(c(1,1))
ST_sfc(list(pt1, pt2))
d = data.frame(a = 1:2)
d$geom = ST_sfc(list(pt1, pt2))
df = ST_as.sf(d)
d$geom2 = ST_sfc(list(pt1, pt2))
ST_as.sf(df) # should warn
library(sp)
x = rbind(c(-1,-1), c(1,-1), c(1,1), c(-1,1), c(-1,-1))
x1 = 0.1 * x + 0.1
x2 = 0.1 * x + 0.4
x3 = 0.1 * x + 0.7
y = x + 3
y1 = x1 + 3
y2 = x2 + 3
y3 = x3 + 3
p = Polygons(list( Polygon(x[5:1,]), Polygon(x2), Polygon(y2), Polygon(x3), 
   Polygon(y[5:1,]), Polygon(y1), Polygon(x1), Polygon(y3)), "ID1")
if (require("rgeos")) {
  r = createSPComment(SpatialPolygons(list(p)))
  comment(r)
  comment(r@polygons[[1]])
  scan(text = comment(r@polygons[[1]]), quiet = TRUE)
  library(sf)
  a = ST_as.sf(r)
  summary(a)
}
demo(meuse, ask = FALSE, echo = FALSE)
summary(ST_as.sf(meuse))
summary(ST_as.sf(meuse.grid))
summary(ST_as.sf(meuse.area))
summary(ST_as.sf(meuse.riv))
summary(ST_as.sf(as(meuse.riv, "SpatialLines")))
pol.grd = as(meuse.grid, "SpatialPolygonsDataFrame")
summary(ST_as.sf(pol.grd))
summary(ST_as.sf(as(pol.grd, "SpatialLinesDataFrame")))

Run the code above in your browser using DataLab