EVOLUTION-MANAGER
Edit File: geos_unary.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: Geometric unary operations on simple feature geometry sets</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 geos_unary {sf}"><tr><td>geos_unary {sf}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Geometric unary operations on simple feature geometry sets</h2> <h3>Description</h3> <p>Geometric unary operations on simple feature geometries. These are all generics, with methods for <code>sfg</code>, <code>sfc</code> and <code>sf</code> objects, returning an object of the same class. All operations work on a per-feature basis, ignoring all other features. </p> <h3>Usage</h3> <pre> st_buffer( x, dist, nQuadSegs = 30, endCapStyle = "ROUND", joinStyle = "ROUND", mitreLimit = 1, singleSide = FALSE, ... ) st_boundary(x) st_convex_hull(x) st_simplify(x, preserveTopology = FALSE, dTolerance = 0) st_triangulate(x, dTolerance = 0, bOnlyEdges = FALSE) st_voronoi(x, envelope, dTolerance = 0, bOnlyEdges = FALSE) st_polygonize(x) st_line_merge(x) st_centroid(x, ..., of_largest_polygon = FALSE) st_point_on_surface(x) st_reverse(x) st_node(x) st_segmentize(x, dfMaxLength, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>object of class <code>sfg</code>, <code>sfg</code> or <code>sf</code></p> </td></tr> <tr valign="top"><td><code>dist</code></td> <td> <p>numeric; buffer distance for all, or for each of the elements in <code>x</code>; in case <code>dist</code> is a <code>units</code> object, it should be convertible to <code>arc_degree</code> if <code>x</code> has geographic coordinates, and to <code>st_crs(x)$units</code> otherwise</p> </td></tr> <tr valign="top"><td><code>nQuadSegs</code></td> <td> <p>integer; number of segments per quadrant (fourth of a circle), for all or per-feature</p> </td></tr> <tr valign="top"><td><code>endCapStyle</code></td> <td> <p>character; style of line ends, one of 'ROUND', 'FLAT', 'SQUARE'</p> </td></tr> <tr valign="top"><td><code>joinStyle</code></td> <td> <p>character; style of line joins, one of 'ROUND', 'MITRE', 'BEVEL'</p> </td></tr> <tr valign="top"><td><code>mitreLimit</code></td> <td> <p>numeric; limit of extension for a join if <code>joinStyle</code> 'MITRE' is used (default 1.0, minimum 0.0)</p> </td></tr> <tr valign="top"><td><code>singleSide</code></td> <td> <p>logical; if <code>TRUE</code>, single-sided buffers are returned for linear geometries, in which case negative <code>dist</code> values give buffers on the right-hand side, positive on the left.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>ignored</p> </td></tr> <tr valign="top"><td><code>preserveTopology</code></td> <td> <p>logical; carry out topology preserving simplification? May be specified for each, or for all feature geometries. Note that topology is preserved only for single feature geometries, not for sets of them.</p> </td></tr> <tr valign="top"><td><code>dTolerance</code></td> <td> <p>numeric; tolerance parameter, specified for all or for each feature geometry.</p> </td></tr> <tr valign="top"><td><code>bOnlyEdges</code></td> <td> <p>logical; if TRUE, return lines, else return polygons</p> </td></tr> <tr valign="top"><td><code>envelope</code></td> <td> <p>object of class <code>sfc</code> or <code>sfg</code> containing a <code>POLYGON</code> with the envelope for a voronoi diagram; this only takes effect when it is larger than the default envelope, chosen when <code>envelope</code> is an empty polygon</p> </td></tr> <tr valign="top"><td><code>of_largest_polygon</code></td> <td> <p>logical; for <code>st_centroid</code>: if <code>TRUE</code>, return centroid of the largest (sub)polygon of a <code>MULTIPOLYGON</code> rather than of the whole <code>MULTIPOLYGON</code></p> </td></tr> <tr valign="top"><td><code>dfMaxLength</code></td> <td> <p>maximum length of a line segment. If <code>x</code> has geographical coordinates (long/lat), <code>dfMaxLength</code> is either a numeric expressed in meter, or an object of class <code>units</code> with length units <code>rad</code> or <code>degree</code>; segmentation in the long/lat case takes place along the great circle, using <a href="../../lwgeom/html/geod.html">st_geod_segmentize</a>.</p> </td></tr> </table> <h3>Details</h3> <p><code>st_buffer</code> computes a buffer around this geometry/each geometry. If any of <code>endCapStyle</code>, <code>joinStyle</code>, or <code>mitreLimit</code> are set to non-default values ('ROUND', 'ROUND', 1.0 respectively) then the underlying 'buffer with style' GEOS function is used. See <a href="https://postgis.net/docs/ST_Buffer.html">postgis.net/docs/ST_Buffer.html</a> for details. </p> <p><code>st_boundary</code> returns the boundary of a geometry </p> <p><code>st_convex_hull</code> creates the convex hull of a set of points </p> <p><code>st_simplify</code> simplifies lines by removing vertices </p> <p><code>st_triangulate</code> triangulates set of points (not constrained). <code>st_triangulate</code> requires GEOS version 3.4 or above </p> <p><code>st_voronoi</code> creates voronoi tesselation. <code>st_voronoi</code> requires GEOS version 3.5 or above </p> <p><code>st_polygonize</code> creates polygon from lines that form a closed ring. In case of <code>st_polygonize</code>, <code>x</code> must be an object of class <code>LINESTRING</code> or <code>MULTILINESTRING</code>, or an <code>sfc</code> geometry list-column object containing these </p> <p><code>st_line_merge</code> merges lines. In case of <code>st_line_merge</code>, <code>x</code> must be an object of class <code>MULTILINESTRING</code>, or an <code>sfc</code> geometry list-column object containing these </p> <p><code>st_centroid</code> gives the centroid of a geometry </p> <p><code>st_point_on_surface</code> returns a point guaranteed to be on the (multi)surface. </p> <p><code>st_reverse</code> reverses the nodes in a line </p> <p><code>st_node</code> adds nodes to linear geometries at intersections without a node, and only works on individual linear geometries </p> <p><code>st_segmentize</code> adds points to straight lines </p> <h3>Value</h3> <p>an object of the same class of <code>x</code>, with manipulated geometry. </p> <h3>Examples</h3> <pre> ## st_buffer, style options (taken from rgeos gBuffer) l1 = st_as_sfc("LINESTRING(0 0,1 5,4 5,5 2,8 2,9 4,4 6.5)") op = par(mfrow=c(2,3)) plot(st_buffer(l1, dist = 1, endCapStyle="ROUND"), reset = FALSE, main = "endCapStyle: ROUND") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, endCapStyle="FLAT"), reset = FALSE, main = "endCapStyle: FLAT") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, endCapStyle="SQUARE"), reset = FALSE, main = "endCapStyle: SQUARE") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs=1), reset = FALSE, main = "nQuadSegs: 1") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs=2), reset = FALSE, main = "nQuadSegs: 2") plot(l1,col='blue',add=TRUE) plot(st_buffer(l1, dist = 1, nQuadSegs= 5), reset = FALSE, main = "nQuadSegs: 5") plot(l1,col='blue',add=TRUE) par(op) l2 = st_as_sfc("LINESTRING(0 0,1 5,3 2)") op = par(mfrow = c(2, 3)) plot(st_buffer(l2, dist = 1, joinStyle="ROUND"), reset = FALSE, main = "joinStyle: ROUND") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle="MITRE"), reset = FALSE, main = "joinStyle: MITRE") plot(l2, col= 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle="BEVEL"), reset = FALSE, main = "joinStyle: BEVEL") plot(l2, col= 'blue', add=TRUE) plot(st_buffer(l2, dist = 1, joinStyle="MITRE" , mitreLimit=0.5), reset = FALSE, main = "mitreLimit: 0.5") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle="MITRE",mitreLimit=1), reset = FALSE, main = "mitreLimit: 1") plot(l2, col = 'blue', add = TRUE) plot(st_buffer(l2, dist = 1, joinStyle="MITRE",mitreLimit=3), reset = FALSE, main = "mitreLimit: 3") plot(l2, col = 'blue', add = TRUE) par(op) nc = st_read(system.file("shape/nc.shp", package="sf")) plot(st_convex_hull(nc)) plot(nc, border = grey(.5)) set.seed(1) x = st_multipoint(matrix(runif(10),,2)) box = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,1),c(0,0)))) if (sf_extSoftVersion()["GEOS"] >= "3.5.0") { v = st_sfc(st_voronoi(x, st_sfc(box))) plot(v, col = 0, border = 1, axes = TRUE) plot(box, add = TRUE, col = 0, border = 1) # a larger box is returned, as documented plot(x, add = TRUE, col = 'red', cex=2, pch=16) plot(st_intersection(st_cast(v), box)) # clip to smaller box plot(x, add = TRUE, col = 'red', cex=2, pch=16) # matching Voronoi polygons to data points: # https://github.com/r-spatial/sf/issues/1030 # generate 50 random unif points: n = 100 pts = st_as_sf(data.frame(matrix(runif(n), , 2), id = 1:(n/2)), coords = c("X1", "X2")) # compute Voronoi polygons: pols = st_collection_extract(st_voronoi(do.call(c, st_geometry(pts)))) # match them to points: pts$pols = pols[unlist(st_intersects(pts, pols))] plot(pts["id"], pch = 16) # ID is color plot(st_set_geometry(pts, "pols")["id"], xlim = c(0,1), ylim = c(0,1), reset = FALSE) plot(st_geometry(pts), add = TRUE) } mls = st_multilinestring(list(matrix(c(0,0,0,1,1,1,0,0),,2,byrow=TRUE))) st_polygonize(st_sfc(mls)) mls = st_multilinestring(list(rbind(c(0,0), c(1,1)), rbind(c(2,0), c(1,1)))) st_line_merge(st_sfc(mls)) plot(nc, axes = TRUE) plot(st_centroid(nc), add = TRUE, pch = 3) mp = st_combine(st_buffer(st_sfc(lapply(1:3, function(x) st_point(c(x,x)))), 0.2 * 1:3)) plot(mp) plot(st_centroid(mp), add = TRUE, col = 'red') # centroid of combined geometry plot(st_centroid(mp, of_largest_polygon = TRUE), add = TRUE, col = 'blue', pch = 3) plot(nc, axes = TRUE) plot(st_point_on_surface(nc), add = TRUE, pch = 3) if (sf_extSoftVersion()["GEOS"] >= "3.7.0") { st_reverse(st_linestring(rbind(c(1,1), c(2,2), c(3,3)))) } (l = st_linestring(rbind(c(0,0), c(1,1), c(0,1), c(1,0), c(0,0)))) st_polygonize(st_node(l)) st_node(st_multilinestring(list(rbind(c(0,0), c(1,1), c(0,1), c(1,0), c(0,0))))) sf = st_sf(a=1, geom=st_sfc(st_linestring(rbind(c(0,0),c(1,1)))), crs = 4326) seg = st_segmentize(sf, units::set_units(100, km)) seg = st_segmentize(sf, units::set_units(0.01, rad)) nrow(seg$geom[[1]]) </pre> <hr /><div style="text-align: center;">[Package <em>sf</em> version 0.9-5 <a href="00Index.html">Index</a>]</div> </body></html>