EVOLUTION-MANAGER
Edit File: coerce-methods.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: Methods to coerce simple features to Spatial* and...</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 as {sf}"><tr><td>as {sf}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Methods to coerce simple features to <code style="white-space: pre;">Spatial*</code> and <code>Spatial*DataFrame</code> objects</h2> <h3>Description</h3> <p><code><a href="coerce-methods.html">as_Spatial()</a></code> allows to convert <code>sf</code> and <code>sfc</code> to <code>Spatial*DataFrame</code> and <code style="white-space: pre;">Spatial*</code> for <code>sp</code> compatibility. You can also use <code>as(x, "Spatial")</code> To transform <code>sp</code> objects to <code>sf</code> and <code>sfc</code> with <code>as(x, "sf")</code>. </p> <h3>Usage</h3> <pre> as_Spatial(from, cast = TRUE, IDs = paste0("ID", seq_along(from))) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>from</code></td> <td> <p>object of class <code>sf</code>, <code>sfc_POINT</code>, <code>sfc_MULTIPOINT</code>, <code>sfc_LINESTRING</code>, <code>sfc_MULTILINESTRING</code>, <code>sfc_POLYGON</code>, or <code>sfc_MULTIPOLYGON</code>.</p> </td></tr> <tr valign="top"><td><code>cast</code></td> <td> <p>logical; if <code>TRUE</code>, <code><a href="st_cast.html">st_cast()</a></code> <code>from</code> before converting, so that e.g. <code>GEOMETRY</code> objects with a mix of <code>POLYGON</code> and <code>MULTIPOLYGON</code> are cast to <code>MULTIPOLYGON</code>.</p> </td></tr> <tr valign="top"><td><code>IDs</code></td> <td> <p>character vector with IDs for the <code style="white-space: pre;">Spatial*</code> geometries</p> </td></tr> </table> <h3>Details</h3> <p>Package <code>sp</code> supports three dimensions for <code>POINT</code> and <code>MULTIPOINT</code> (<code style="white-space: pre;">SpatialPoint*</code>). Other geometries must be two-dimensional (<code>XY</code>). Dimensions can be dropped using <code><a href="st_zm.html">st_zm()</a></code> with <code>what = "M"</code> or <code>what = "ZM"</code>. </p> <p>For converting simple features (i.e., <code>sf</code> objects) to their <code>Spatial</code> counterpart, use <code>as(obj, "Spatial")</code> </p> <h3>Value</h3> <p>geometry-only object deriving from <code>Spatial</code>, of the appropriate class </p> <h3>Examples</h3> <pre> nc <- st_read(system.file("shape/nc.shp", package="sf")) # convert to SpatialPolygonsDataFrame spdf <- as_Spatial(nc) # identical to spdf <- as(nc, "Spatial") # convert to SpatialPolygons as(st_geometry(nc), "Spatial") # back to sf as(spdf, "sf") </pre> <hr /><div style="text-align: center;">[Package <em>sf</em> version 0.9-5 <a href="00Index.html">Index</a>]</div> </body></html>