sf (version 0.2-8)

geos: Geometric operations on (pairs of) simple feature geometries

Description

Geometric operations on (pairs of) simple feature geometries

Usage

st_is_valid(x)
st_dimension(x, NA_if_empty = TRUE)
st_area(x)
st_length(x, dist_fun = geosphere::distGeo)
st_is_simple(x)
st_distance(x, y, dist_fun)
st_relate(x, y)
st_intersects(x, y, sparse = TRUE)
st_disjoint(x, y, sparse = TRUE)
st_touches(x, y, sparse = TRUE)
st_crosses(x, y, sparse = TRUE)
st_within(x, y, sparse = TRUE)
st_contains(x, y, sparse = TRUE)
st_overlaps(x, y, sparse = TRUE)
st_equals(x, y, sparse = TRUE)
st_covers(x, y, sparse = TRUE)
st_covered_by(x, y, sparse = TRUE)
st_equals_exact(x, y, par, sparse = TRUE)
st_buffer(x, dist, nQuadSegs = 30)
st_boundary(x)
st_convex_hull(x)
st_simplify(x, preserveTopology = FALSE, dTolerance = 0)
st_triangulate(x, dTolerance = 0, bOnlyEdges = FALSE)
st_polygonize(mlst)
st_linemerge(mlst)
st_centroid(x)
st_segmentize(x, dfMaxLength, ..., warn = TRUE)
st_combine(x)
st_intersection(x, y)
st_union(x, y)
st_difference(x, y)
st_sym_difference(x, y)
st_line_sample(x, n, density, type = "regular")

Arguments

x
first simple feature (sf) or simple feature geometry (sfc) collection
NA_if_empty
logical; if TRUE, return NA for empty geometries
dist_fun
function to be used for great circle distances; for unprojected (long/lat) data, this should be a distance function of package geosphere, or compatible to that; it defaults to distGeo in that case; for other data metric lengths are computed.
y
second simple feature (sf) or simple feature geometry (sfc) collection
sparse
logical; should a sparse matrix be returned (TRUE) or a dense matrix?
par
numeric; parameter used for "equals_exact" (margin) and "is_within_distance"
dist
buffer distance
nQuadSegs
integer; number of segments per quadrant (fourth of a circle)
preserveTopology
logical; carry out topology preserving simplification?
dTolerance
numeric; tolerance parameter
bOnlyEdges
logical; if TRUE, return lines, else return polygons
mlst
object of class MULTILINESTRING or geometry list-column containing these
dfMaxLength
numeric; max length of a line segment
...
ignored
warn
logical; generate a warning in case of long/lat data
n
integer; number of points to choose per geometry; if missing, n will be computed as round(density * st_length(geom)).
density
numeric; density (points per distance unit) of the sampling, possibly a vector of length equal to the number of features (otherwise recycled).
type
character; indicate the sampling type, either "regular" or "random"

Value

matrix (sparse or dense); if dense: of type character for relate, numeric for distance, and logical for all others; matrix has dimension x by y; if sparse (only possible for those who return logical in case of dense): return list of length length(x) with indices of the TRUE values for matching y.st_dimension returns 0 for points, 1 for lines, 2 for surfaces and by default NA for empty geometries.st_area returns the area of a geometry, in the coordinate reference system used; in case x is in degrees longitude/latitude, areaPolygon is used for area calculation.st_length returns the length of a LINESTRING or MULTILINESTRING geometry, using the coordinate reference system used; if the coordinate reference system of x was set, the returned value has a unit of measurement.st_is_simple and st_is_valid return a logical vectorst_distance returns a dense numeric matrix of dimension length(x) by length(y)st_relate returns a dense character matrix; element [i,j] has nine characters, refering to the DE9-IM relationship between x[i] and y[j], encoded as IxIy,IxBy,IxEy,BxIy,BxBy,BxEy,ExIy,ExBy,ExEy where I refers to interior, B to boundary, and E to exterior, and e.g. BxIy the dimensionality of the intersection of the the boundary of x[i] and the interior of y[j], which is one of 0,1,2,F, digits denoting dimensionality, F denoting not intersecting.st_intersects ... st_equals_exact return a sparse or dense logical matrix with rows and columns corresponding to the number of geometries (or rows) in x and y, respectivelyst_buffer ... st_segmentize return an sfc object with the same number of geometries as in xst_union(x) unions geometries. Unioning a set of overlapping polygons has the effect of merging the areas (i.e. the same effect as iteratively unioning all individual polygons together). Unioning a set of LineStrings has the effect of fully noding and dissolving the input linework. In this context "fully noded" means that there will be a node or endpoint in the output for every endpoint or line segment crossing in the input. "Dissolved" means that any duplicate (e.g. coincident) line segments or portions of line segments will be reduced to a single line segment in the output. Unioning a set of Points has the effect of merging al identical points (producing a set with no duplicates). If y0 in a call to st_union is not missing, each of the geometries in x are unioned to the combination of y0.

Details

function dist_fun should follow the pattern of the distance functions in package geosphere: the first two arguments should be 2-column point matrices, the third the semi major axis (radius, in m), the third the ellipsoid flattening.

requires GEOS version 3.4 or above

st_combine combines geometries without resolving borders. st_combine(nc)

Examples

Run this code
x = st_sfc(
	st_point(0:1), 
	st_linestring(rbind(c(0,0),c(1,1))), 
	st_polygon(list(rbind(c(0,0),c(1,0),c(0,1),c(0,0)))),
	st_multipoint(),
	st_linestring(),
	st_geometrycollection())
st_dimension(x)
st_dimension(x, FALSE)
p1 = st_point(c(0,0))
p2 = st_point(c(2,2))
pol1 = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,1),c(0,0)))) - 0.5
pol2 = pol1 + 1
pol3 = pol1 + 2
st_relate(st_sfc(p1,p2), st_sfc(pol1, pol2, pol3))
nc = st_read(system.file("shape/nc.shp", package="sf"))
plot(st_convex_hull(nc))
plot(nc, border = grey(.5))
mls = st_multilinestring(list(matrix(c(0,0,0,1,1,1,0,0),,2,byrow=TRUE)))
st_polygonize(mls)
mls = st_multilinestring(list(rbind(c(0,0), c(1,1)), rbind(c(2,0), c(1,1))))
st_linemerge(mls)
plot(nc, axes = TRUE)
plot(st_centroid(nc), add = TRUE, pch = 3)
plot(st_union(nc))
ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1))),
	st_linestring(rbind(c(0,0),c(10,0))))
st_line_sample(ls, density = 1)
ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1))),
  st_linestring(rbind(c(0,0),c(.1,0))), crs = 4326) 
try(st_line_sample(ls, density = 1/1000)) # error
st_line_sample(st_transform(ls, 3857), n = 5) # five points for each line
st_line_sample(st_transform(ls, 3857), n = c(1, 3)) # one and three points
st_line_sample(st_transform(ls, 3857), density = 1/1000) # one per km
st_line_sample(st_transform(ls, 3857), density = c(1/1000, 1/10000)) # one per km, one per 10 km

Run the code above in your browser using DataLab