EVOLUTION-MANAGER
Edit File: st_as_sf.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Convert foreign object to an sf object</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for st_as_sf {sf}"><tr><td>st_as_sf {sf}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Convert foreign object to an sf object</h2> <h3>Description</h3> <p>Convert foreign object to an sf object </p> <h3>Usage</h3> <pre> st_as_sf(x, ...) ## S3 method for class 'data.frame' st_as_sf( x, ..., agr = NA_agr_, coords, wkt, dim = "XYZ", remove = TRUE, na.fail = TRUE, sf_column_name = NULL ) ## S3 method for class 'sf' st_as_sf(x, ...) ## S3 method for class 'sfc' st_as_sf(x, ...) ## S3 method for class 'Spatial' st_as_sf(x, ...) ## S3 method for class 'map' st_as_sf(x, ..., fill = TRUE, group = TRUE) ## S3 method for class 'ppp' st_as_sf(x, ...) ## S3 method for class 'psp' st_as_sf(x, ...) ## S3 method for class 'lpp' st_as_sf(x, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>object to be converted into an object class <code>sf</code></p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>passed on to <a href="sf.html">st_sf</a>, might included named arguments <code>crs</code> or <code>precision</code></p> </td></tr> <tr valign="top"><td><code>agr</code></td> <td> <p>character vector; see details section of <a href="sf.html">st_sf</a></p> </td></tr> <tr valign="top"><td><code>coords</code></td> <td> <p>in case of point data: names or numbers of the numeric columns holding coordinates</p> </td></tr> <tr valign="top"><td><code>wkt</code></td> <td> <p>name or number of the character column that holds WKT encoded geometries</p> </td></tr> <tr valign="top"><td><code>dim</code></td> <td> <p>passed on to <a href="st.html">st_point</a> (only when argument coords is given)</p> </td></tr> <tr valign="top"><td><code>remove</code></td> <td> <p>logical; when coords or wkt is given, remove these columns from data.frame?</p> </td></tr> <tr valign="top"><td><code>na.fail</code></td> <td> <p>logical; if <code>TRUE</code>, raise an error if coordinates contain missing values</p> </td></tr> <tr valign="top"><td><code>sf_column_name</code></td> <td> <p>character; name of the active list-column with simple feature geometries; in case there is more than one and <code>sf_column_name</code> is <code>NULL</code>, the first one is taken.</p> </td></tr> <tr valign="top"><td><code>fill</code></td> <td> <p>logical; the value for <code>fill</code> that was used in the call to <a href="../../maps/html/map.html">map</a>.</p> </td></tr> <tr valign="top"><td><code>group</code></td> <td> <p>logical; if <code>TRUE</code>, group id labels from <a href="../../maps/html/map.html">map</a> by their prefix before <code>:</code></p> </td></tr> </table> <h3>Details</h3> <p>setting argument <code>wkt</code> annihilates the use of argument <code>coords</code>. If <code>x</code> contains a column called "geometry", <code>coords</code> will result in overwriting of this column by the <a href="sfc.html">sfc</a> geometry list-column. Setting <code>wkt</code> will replace this column with the geometry list-column, unless <code>remove_coordinates</code> is <code>FALSE</code>. </p> <h3>Examples</h3> <pre> pt1 = st_point(c(0,1)) pt2 = st_point(c(1,1)) st_sfc(pt1, pt2) d = data.frame(a = 1:2) d$geom = st_sfc(pt1, pt2) df = st_as_sf(d) d$geom = c("POINT(0 0)", "POINT(0 1)") df = st_as_sf(d, wkt = "geom") d$geom2 = st_sfc(pt1, pt2) st_as_sf(d) # should warn data(meuse, package = "sp") meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant") meuse_sf[1:3,] summary(meuse_sf) 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 y3 = x3 + 3 m = matrix(c(3, 0), 5, 2, byrow = TRUE) z = x + m z1 = x1 + m z2 = x2 + m z3 = x3 + m p1 = Polygons(list( Polygon(x[5:1,]), Polygon(x2), Polygon(x3), Polygon(y[5:1,]), Polygon(y1), Polygon(x1), Polygon(y3)), "ID1") p2 = Polygons(list( Polygon(z[5:1,]), Polygon(z2), Polygon(z3), Polygon(z1)), "ID2") if (require("rgeos")) { r = createSPComment(SpatialPolygons(list(p1,p2))) 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"))) if (require(spatstat)) { g = st_as_sf(gorillas) # select only the points: g[st_is(g, "POINT"),] } if (require(spatstat)) { data(chicago) plot(st_as_sf(chicago)["label"]) plot(st_as_sf(chicago)[-1,"label"]) } </pre> <hr /><div style="text-align: center;">[Package <em>sf</em> version 0.9-5 <a href="00Index.html">Index</a>]</div> </body></html>