### Example: st_startpoint() and st_endpoint() on lines Source: https://r-spatial.github.io/lwgeom/reference/st_startpoint.html Example from the documentation showing how to use st_startpoint() and st_endpoint() on single and multi-line geometries. The output includes the geometry set summaries and point coordinates. ```r library(sf) m = matrix(c(0, 1, 2, 0, 1, 4), ncol = 2) l = st_sfc(st_linestring(m)) lwgeom::st_startpoint(l) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 0 ymax: 0 #> CRS: NA #> POINT (0 0) lwgeom::st_endpoint(l) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 2 ymin: 4 xmax: 2 ymax: 4 #> CRS: NA #> POINT (2 4) l2 = st_sfc(st_linestring(m), st_linestring(m[3:1, ])) lwgeom::st_startpoint(l2) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 4 #> CRS: NA #> POINT (0 0) #> POINT (2 4) lwgeom::st_endpoint(l2) #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 4 #> CRS: NA #> POINT (2 4) #> POINT (0 0) ``` -------------------------------- ### st_split example with multilinestring and point Source: https://r-spatial.github.io/lwgeom/reference/st_split.html Example from the documentation showing how to split a multilinestring with a point. The output is a geometry collection containing the resulting linestrings. The example uses the sf package and demonstrates the expected output format. ```r library(sf) l = st_as_sfc('MULTILINESTRING((10 10, 190 190), (15 15, 30 30, 100 90))') pt = st_sfc(st_point(c(30,30))) st_split(l, pt) #> Geometry set for 1 feature #> Geometry type: GEOMETRYCOLLECTION #> Dimension: XY #> Bounding box: xmin: 10 ymin: 10 xmax: 190 ymax: 190 #> CRS: NA #> GEOMETRYCOLLECTION (LINESTRING (10 10, 30 30), ... ``` -------------------------------- ### st_subdivide example with nc dataset Source: https://r-spatial.github.io/lwgeom/reference/st_subdivide.html Example that loads the sf package, loads the North Carolina demo dataset, subdivides it with max_vertices = 10, and plots the first resulting geometry. Requires the sf package and the nc dataset. ```r library(sf) demo(nc, ask = FALSE, echo = FALSE) x = st_subdivide(nc, 10) plot(x[1]) ``` -------------------------------- ### st_transform_proj examples with sfc, sf, and sfg Source: https://r-spatial.github.io/lwgeom/reference/st_transform_proj.html Example from the documentation showing st_transform_proj on an sfc object with two points, then on an sf object loaded from the North Carolina shapefile, and finally on an sfg point with explicit proj4string. The output includes geometry summaries and a warning about deprecated +init=epsg syntax. ```r library(sf) p1 = st_point(c(7,52)) p2 = st_point(c(-30,20)) sfc = st_sfc(p1, p2, crs = 4326) sfc #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -30 ymin: 20 xmax: 7 ymax: 52 #> Geodetic CRS: WGS 84 #> POINT (7 52) #> POINT (-30 20) st_transform_proj(sfc, "+proj=wintri") #> Geometry set for 2 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -3270597 ymin: 2238779 xmax: 665843 ymax: 5789966 #> Projected CRS: +proj=wintri #> POINT (665843 5789966) #> POINT (-3270597 2238779) library(sf) nc = st_read(system.file("shape/nc.shp", package="sf")) #> Reading layer `nc' from data source #> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 st_transform_proj(nc[1,], "+proj=wintri+over") #> Simple feature collection with 1 feature and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -6776742 ymin: 4191789 xmax: -6736178 ymax: 4233236 #> Projected CRS: +proj=wintri+over #> AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 NWBIR74 #> 1 0.114 1.442 1825 1825 Ashe 37009 37009 5 1091 1 10 #> BIR79 SID79 NWBIR79 geometry #> 1 1364 0 19 MULTIPOLYGON (((-6760648 41... st_transform_proj(structure(p1, proj4string = "+init=epsg:4326"), "+init=epsg:3857") #> Warning: GDAL Message 1: +init=epsg:XXXX syntax is deprecated. It might return a CRS with a non-EPSG compliant axis order. #> POINT (779236.4 6800125) ``` -------------------------------- ### st_linesubstring examples Source: https://r-spatial.github.io/lwgeom/reference/st_linesubstring.html Example from the documentation. Creates a linestring with two segments, then extracts substrings. The first call without tolerance warns about geodesic behavior. The second call without tolerance returns a three-point linestring. The third call with tolerance 0.001 snaps the start to the second node, returning a two-point linestring. ```r library(sf) lines = st_sfc(st_linestring(rbind(c(0,0), c(1,2), c(2,0))), crs = 4326) spl = st_linesubstring(lines, 0.2, 0.8) # should warn #> Warning: st_linesubstring does not follow a geodesic; you may want to use st_geod_segmentize first plot(st_geometry(lines), col = 'red', lwd = 3) plot(spl, col = 'black', lwd = 3, add = TRUE) st_linesubstring(lines, 0.49999, 0.8) # three points #> Warning: st_linesubstring does not follow a geodesic; you may want to use st_geod_segmentize first #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 0.99998 ymin: 0.8 xmax: 1.6 ymax: 2 #> Geodetic CRS: WGS 84 #> LINESTRING (0.99998 1.99996, 1 2, 1.6 0.8) st_linesubstring(lines, 0.49999, 0.8, 0.001) # two points: snap start to second node #> Warning: st_linesubstring does not follow a geodesic; you may want to use st_geod_segmentize first #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 0.8 xmax: 1.6 ymax: 2 #> Geodetic CRS: WGS 84 #> LINESTRING (1 2, 1.6 0.8) ``` -------------------------------- ### Examples of st_geohash and st_geom_from_geohash Source: https://r-spatial.github.io/lwgeom/reference/st_geohash.html Examples from the documentation showing how to compute geohashes with st_geohash and convert them back with st_geom_from_geohash. The first two calls show precision 2 and 10 results; raw=TRUE returns a bounding-box matrix; the remaining calls show polygon output with default precision, precision 4, and precision 10. The example temporarily sets options(digits=20) for printing and restores it with options(o). ```r library(sf) lwgeom::st_geohash(st_sfc(st_point(c(1.5,3.5)), st_point(c(0,90))), 2) #> [1] "s0" "up" lwgeom::st_geohash(st_sfc(st_point(c(1.5,3.5)), st_point(c(0,90))), 10) #> [1] "s095fjhkbx" "upbpbpbpbp" st_geom_from_geohash(c('9qqj7nmxncgyy4d0dbxqz0', 'up'), raw = TRUE) #> xmin ymin xmax ymax #> [1,] -115.1728 36.11465 -115.1728 36.11465 #> [2,] 0.0000 84.37500 11.2500 90.00000 o = options(digits = 20) # for printing purposes st_geom_from_geohash(c('9qqj7nmxncgyy4d0dbxqz0', 'u1hzz631zyd63zwsd7zt')) #> Geometry set for 2 features #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -115.172816 ymin: 36.114646 xmax: 7.00000000000014 ymax: 52.0000000000001 #> Geodetic CRS: WGS 84 (CRS84) #> POLYGON ((-115.17281600000001163 36.11464599999... #> POLYGON ((6.9999999999998152589 51.999999999999... st_geom_from_geohash('9qqj7nmxncgyy4d0dbxqz0', 4) #> Geometry set for 1 feature #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -115.3125 ymin: 36.03515625 xmax: -114.9609375 ymax: 36.2109375 #> Geodetic CRS: WGS 84 (CRS84) #> POLYGON ((-115.3125 36.03515625, -114.9609375 3... st_geom_from_geohash('9qqj7nmxncgyy4d0dbxqz0', 10) #> Geometry set for 1 feature #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: -115.17282128334 ymin: 36.1146408319473 xmax: -115.172810554504 ymax: 36.1146461963654 #> Geodetic CRS: WGS 84 (CRS84) #> POLYGON ((-115.1728212833404541 36.114640831947... options(o) ``` -------------------------------- ### st_force_polygon_cw examples with sf, sfc, and single geometry Source: https://r-spatial.github.io/lwgeom/reference/st_force_polygon_cw.html Examples showing how to use st_force_polygon_cw on an sf object, an sfc object, and a single geometry. The output demonstrates that the function reorders ring coordinates to enforce clockwise orientation for outer rings. ```r library(sf) polys <- st_sf(cw = c(FALSE, TRUE), st_as_sfc(c('POLYGON ((0 0, 1 0, 1 1, 0 0))', 'POLYGON ((1 1, 2 2, 2 1, 1 1))'))) st_force_polygon_cw(polys) #> Simple feature collection with 2 features and 1 field #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> cw #> 1 FALSE #> 2 TRUE #> st_as_sfc.c..POLYGON...0.0..1.0..1.1..0.0......POLYGON...1.1..2.2..2.1..1.1..... #> 1 POLYGON ((0 0, 1 1, 1 0, 0 0)) #> 2 POLYGON ((1 1, 2 2, 2 1, 1 1)) st_force_polygon_cw(st_geometry(polys)) #> Geometry set for 2 features #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> POLYGON ((0 0, 1 1, 1 0, 0 0)) #> POLYGON ((1 1, 2 2, 2 1, 1 1)) st_force_polygon_cw(st_geometry(polys)[[1]]) #> POLYGON ((0 0, 1 1, 1 0, 0 0)) ``` -------------------------------- ### Example of st_astext and st_asewkt Source: https://r-spatial.github.io/lwgeom/reference/st_astext.html Example showing st_astext and st_asewkt on a point with CRS 4326 and 3 digits. st_astext returns "POINT(1 2.303)"; st_asewkt returns "SRID=4326;POINT(1 2.303)". ```r library(sf) pt <- st_sfc(st_point(c(1.0002,2.3030303)), crs = 4326) st_astext(pt, 3) #> [1] "POINT(1 2.303)" st_asewkt(pt, 3) #> [1] "SRID=4326;POINT(1 2.303)" ``` -------------------------------- ### st_wrap_x example with sf and nc dataset Source: https://r-spatial.github.io/lwgeom/reference/st_wrap_x.html Loads the sf package and the North Carolina demo dataset, then applies st_wrap_x to split at x = -78 and move by 10, plotting the result. ```r library(sf) demo(nc, ask = FALSE, echo = FALSE) x = st_wrap_x(nc, -78, 10) plot(x[1]) ``` -------------------------------- ### Example: compute and plot minimum bounding circles Source: https://r-spatial.github.io/lwgeom/reference/bounding_circle.html Example from the documentation. It creates two multipoints, computes their minimum bounding circles, and plots them on non-Windows platforms. It then reads the North Carolina shapefile, unions its geometry, and plots the bounding circle of the state. The output includes a warning that `st_minimum_rotated_rectangle` does not work correctly for longitude/latitude data. ```r library(sf) #> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE #> #> Attaching package: ‘sf’ #> The following objects are masked from ‘package:lwgeom’: #> #> st_minimum_bounding_circle, st_perimeter x = st_multipoint(matrix(c(0,1,0,1),2,2)) y = st_multipoint(matrix(c(0,0,1,0,1,1),3,2)) mbcx = st_minimum_bounding_circle(x) mbcy = st_minimum_bounding_circle(y) if (.Platform$OS.type != "windows") { plot(mbcx, axes=TRUE); plot(x, add=TRUE) plot(mbcy, axes=TRUE); plot(y, add=TRUE) } nc = st_read(system.file("nc.gpkg", package="sf")) #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 state = st_union(st_geometry(nc)) if (.Platform$OS.type != "windows") { plot(st_minimum_bounding_circle(state), asp=1) plot(state, add=TRUE) } #> Warning: st_minimum_rotated_rectangle does not work correctly for longitude/latitude data ``` -------------------------------- ### Example: st_geod_area, st_geod_length, st_geod_segmentize, st_geod_covers, st_geod_distance Source: https://r-spatial.github.io/lwgeom/reference/geod.html Complete example from the documentation. It loads the sf package, reads the North Carolina dataset, and demonstrates area, length, segmentize, covers, and distance calculations. Note that st_area will error when the area spans the equator with older proj.4 versions, and longitude coordinates are rescaled to [-180,180). ```r library(sf) nc = st_read(system.file("gpkg/nc.gpkg", package="sf")) #> Reading layer `nc.gpkg' from data source #> `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG' #> Simple feature collection with 100 features and 14 fields #> Geometry type: MULTIPOLYGON #> Dimension: XY #> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> Geodetic CRS: NAD27 st_geod_area(nc[1:3,]) #> Units: [m^2] #> [1] 1137388604 611077263 1423489919 # st_area(nc[1:3,]) l = st_sfc(st_linestring(rbind(c(7,52), c(8,53))), crs = 4326) st_geod_length(l) #> 130359.3 [m] library(units) #> udunits database from /usr/share/xml/udunits/udunits2.xml pol = st_polygon(list(rbind(c(0,0), c(0,60), c(60,60), c(0,0)))) x = st_sfc(pol, crs = 4326) seg = st_geod_segmentize(x[1], set_units(10, km)) plot(seg, graticule = TRUE, axes = TRUE) pole = st_polygon(list(rbind(c(0,80), c(120,80), c(240,80), c(0,80)))) pt = st_point(c(0,90)) x = st_sfc(pole, pt, crs = 4326) st_geod_covers(x[c(1,1,1)], x[c(2,2,2,2)]) #> Sparse geometry binary predicate list of length 3, where the predicate #> was `covers' #> 1: 1, 2, 3, 4 #> 2: 1, 2, 3, 4 #> 3: 1, 2, 3, 4 pole = st_polygon(list(rbind(c(0,80), c(120,80), c(240,80), c(0,80)))) pt = st_point(c(30,70)) x = st_sfc(pole, pt, crs = 4326) st_geod_distance(x, x) #> Units: [m] #> [,1] [,2] #> [1,] 0 1378923 #> [2,] 1378923 0 ``` -------------------------------- ### st_snap_to_grid example: snap and plot Source: https://r-spatial.github.io/lwgeom/reference/st_snap_to_grid.html Loads an sf object, transforms it to EPSG:3395, snaps it to a 5000 m grid, and plots the original and snapped geometries for visual comparison. The try() wrapper handles potential errors from snapping. ```r # obtain data library(sf) x = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE)[1, ] |> st_geometry() |> st_transform(3395) # snap to a grid of 5000 m err = try(y <- st_snap_to_grid(x, 5000)) # plot data for visual comparison if (!inherits(err, "try-error")) { opar = par(mfrow = c(1, 2)) plot(x, main = "orginal data") plot(y, main = "snapped to 5000 m") par(opar) } ``` -------------------------------- ### st_startpoint(x) Source: https://r-spatial.github.io/lwgeom/reference/st_startpoint.html Function to extract the start point from a line geometry. ```APIDOC ## st_startpoint(x) ### Description Returns the start point of a line geometry. ### Usage ```r st_startpoint(x) ``` ### Arguments - **x** (line of class `sf`, `sfc` or `sfg`) - Required - The line geometry from which to extract the start point. ### Value An `sf` object representing the start point. ### Details See https://postgis.net/docs/ST_StartPoint.html. ### Examples ```r library(sf) m = matrix(c(0, 1, 2, 0, 1, 4), ncol = 2) l = st_sfc(st_linestring(m)) lwgeom::st_startpoint(l) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 0 ymax: 0 #> CRS: NA #> POINT (0 0) ``` ``` -------------------------------- ### Example: Compute azimuth between two points Source: https://r-spatial.github.io/lwgeom/reference/st_geod_azimuth.html Creates two points with longitude/latitude coordinates and computes the azimuth between them using `st_geod_azimuth`. The output is approximately 0.5410385 radians. ```R library(sf) p = st_sfc(st_point(c(7,52)), st_point(c(8,53)), crs = 4326) st_geod_azimuth(p) #> 0.5410385 [rad] ``` -------------------------------- ### Example: Check polygon orientation with st_is_polygon_cw Source: https://r-spatial.github.io/lwgeom/reference/st_is_polygon_cw.html Creates an sf object with two polygons and checks their orientation. The function returns FALSE for the first polygon (counter-clockwise) and TRUE for the second (clockwise). Also works on the geometry column and a single geometry. ```R library(sf) polys <- st_sf(cw = c(FALSE, TRUE), st_as_sfc(c('POLYGON ((0 0, 1 0, 1 1, 0 0))', 'POLYGON ((1 1, 2 2, 2 1, 1 1))'))) st_is_polygon_cw(polys) #> [1] FALSE TRUE st_is_polygon_cw(st_geometry(polys)) #> [1] FALSE TRUE st_is_polygon_cw(st_geometry(polys)[[1]]) #> [1] FALSE ``` -------------------------------- ### Usage: st_startpoint() and st_endpoint() Source: https://r-spatial.github.io/lwgeom/reference/st_startpoint.html Usage section for the st_startpoint and st_endpoint functions. Both take a line object of class sf, sfc, or sfg. ```r st_startpoint(x) st_endpoint(x) ``` -------------------------------- ### st_snap_to_grid usage Source: https://r-spatial.github.io/lwgeom/reference/st_snap_to_grid.html Shows the function signature for st_snap_to_grid. The arguments are x (object with geometries), size (grid cell size), and origin (grid origin). ```r st_snap_to_grid(x, size, origin) ``` -------------------------------- ### Usage of st_minimum_bounding_circle and st_minimum_bounding_radius Source: https://r-spatial.github.io/lwgeom/reference/bounding_circle.html Usage signature for the two functions. `st_minimum_bounding_circle` takes an optional `nQuadSegs` argument (default 30) passed to `st_buffer`; `st_minimum_bounding_radius` takes only `x`. Both accept objects of class `sfg`, `sfc`, or `sf`. ```r st_minimum_bounding_circle(x, nQuadSegs = 30) st_minimum_bounding_radius(x) ``` -------------------------------- ### st_as_sfc.TWKB: Convert TWKB raw vector to sfc object Source: https://r-spatial.github.io/lwgeom/reference/st_as_sfc.TWKB.html The first block shows the S3 method signature for st_as_sfc on TWKB objects. The second block creates a TWKB object from raw bytes, loads the sf package for the generic, and calls st_as_sfc, producing a LINESTRING geometry with the given coordinates. ```r # S3 method for class 'TWKB' st_as_sfc(x, ...) ``` ```r l = structure(list(as.raw(c(0x02, 0x00, 0x02, 0x02, 0x02, 0x08, 0x08))), class = "TWKB") library(sf) # load generic st_as_sfc(l) #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 5 ymax: 5 #> CRS: NA #> LINESTRING (1 1, 5 5) ``` -------------------------------- ### st_minimum_bounding_radius(x) Source: https://r-spatial.github.io/lwgeom/reference/bounding_circle.html Computes the center and radius of the minimum bounding circle for the input spatial object. Returns a geometry containing the centers and a column with the corresponding radii. ```APIDOC ## st_minimum_bounding_radius(x) ### Description Computes the center and radius of the minimum bounding circle. ### Usage st_minimum_bounding_radius(x) ### Arguments - **x** (sfg, sfc, or sf) - Required - The spatial object for which to compute the minimum bounding radius. ### Value A geometry with the minimum bounding circle centers and a column with the corresponding radii. ### Details Uses the `lwgeom_calculate_mbc` method and returns the centers (as a geometry) and the respective radii (as a column). ``` -------------------------------- ### st_wrap_x Source: https://r-spatial.github.io/lwgeom/reference/st_wrap_x.html Splits input geometries by a vertical line and moves components falling on one side of that line by a fixed amount. ```APIDOC ## st_wrap_x ### Description Splits input geometries by a vertical line and moves components falling on one side of that line by a fixed amount. ### Usage ```r st_wrap_x(x, wrap, move) ``` ### Arguments - **x** - object with geometries to be split - **wrap** - x value of split line - **move** - amount by which geometries falling to the left of the line should be translated to the right ### Value object of the same class as `x` ### Examples ```r library(sf) demo(nc, ask = FALSE, echo = FALSE) x = st_wrap_x(nc, -78, 10) plot(x[1]) ``` ``` -------------------------------- ### st_wrap_x usage signature Source: https://r-spatial.github.io/lwgeom/reference/st_wrap_x.html Shows the function signature for st_wrap_x, which takes an object with geometries, the x value of the split line, and the amount to move geometries to the left of the line. ```r st_wrap_x(x, wrap, move) ``` -------------------------------- ### st_snap_to_grid Source: https://r-spatial.github.io/lwgeom/reference/st_snap_to_grid.html Snaps geometries to a grid with a specified cell size and origin. The function returns an object of the same class as the input, with geometries adjusted to the grid. ```APIDOC ## st_snap_to_grid ### Description Snaps geometries to a grid with a specified cell size and origin. ### Usage ```r st_snap_to_grid(x, size, origin) ``` ### Arguments - **x** - object with geometries to be snapped - **size** - numeric or (length) units object; grid cell size in x-, y- (and possibly z- and m-) directions - **origin** - numeric; origin of the grid ### Value Object of the same class as `x`. ### Examples ```r # obtain data library(sf) x = st_read(system.file("gpkg/nc.gpkg", package="sf"), quiet = TRUE)[1, ] |> st_geometry() |> st_transform(3395) # snap to a grid of 5000 m err = try(y <- st_snap_to_grid(x, 5000)) # plot data for visual comparison if (!inherits(err, "try-error")) { opar = par(mfrow = c(1, 2)) plot(x, main = "orginal data") plot(y, main = "snapped to 5000 m") par(opar) } ``` ``` -------------------------------- ### st_minimum_bounding_circle(x, nQuadSegs = 30) Source: https://r-spatial.github.io/lwgeom/reference/bounding_circle.html Computes the minimum bounding circle for an input spatial object (sfg, sfc, or sf). The circle is returned as the same class as the input. The nQuadSegs parameter controls the number of segments per quadrant used to approximate the circle. ```APIDOC ## st_minimum_bounding_circle ### Description Computes the minimum bounding circle for a spatial object. ### Usage st_minimum_bounding_circle(x, nQuadSegs = 30) ### Arguments - **x** (sfg, sfc, or sf) - Required - Object of class `sfg`, `sfc` or `sf`. - **nQuadSegs** (numeric) - Optional - Number of segments per quadrant passed to `st_buffer`. Defaults to 30. ### Value Object of the same class as the input `x`. ### Details Uses the `lwgeom_calculate_mbc` method, also used by the PostGIS command `ST_MinimumBoundingCircle`. ### Examples ```r library(sf) x = st_multipoint(matrix(c(0,1,0,1),2,2)) mbcx = st_minimum_bounding_circle(x) ``` -------------------------------- ### Cite lwgeom package with BibTeX entry Source: https://r-spatial.github.io/lwgeom/authors.html Use this BibTeX entry to cite the lwgeom R package in academic publications. It is generated from the DESCRIPTION file and includes the package title, author, year, version, and URL. ```bibtex @Manual{, title = {lwgeom: Bindings to Selected 'liblwgeom' Functions for Simple Features}, author = {Edzer Pebesma}, year = {2026}, note = {R package version 0.2-16}, url = {https://r-spatial.github.io/lwgeom/}, } ``` -------------------------------- ### Usage of liblwgeom geodetic functions Source: https://r-spatial.github.io/lwgeom/reference/geod.html Shows the function signatures for the geodetic functions. Note that st_geod_distance is used by st_distance and should not be used directly. ```r st_geod_area(x) st_geod_length(x) st_geod_segmentize(x, max_seg_length) st_geod_covers(x, y, sparse = TRUE) st_geod_covered_by(x, y, sparse = TRUE) st_geod_distance(x, y, tolerance = 0, sparse = FALSE) ``` -------------------------------- ### st_geod_covers(x, y, sparse = TRUE) Source: https://r-spatial.github.io/lwgeom/reference/geod.html Determines whether geometries in x cover geometries in y. Returns a sparse or dense logical matrix. ```APIDOC ## st_geod_covers(x, y, sparse = TRUE) ### Description Determines whether geometries in x cover geometries in y. ### Usage st_geod_covers(x, y, sparse = TRUE) ### Arguments - **x** (sf/sfc/sfg) - Required - Object of class `sf`, `sfc`, or `sfg`. - **y** (sf/sfc/sfg) - Required - Object of class `sf`, `sfc`, or `sfg`. - **sparse** (logical) - Optional - If `TRUE`, return a sparse matrix (object of class `sgbp`), otherwise, return a dense logical matrix. Default is `TRUE`. ### Examples ```r library(sf) pole = st_polygon(list(rbind(c(0,80), c(120,80), c(240,80), c(0,80)))) pt = st_point(c(0,90)) x = st_sfc(pole, pt, crs = 4326) st_geod_covers(x[c(1,1,1)], x[c(2,2,2,2)]) # Sparse geometry binary predicate list of length 3, where the predicate # was `covers' # 1: 1, 2, 3, 4 # 2: 1, 2, 3, 4 # 3: 1, 2, 3, 4 ``` ``` -------------------------------- ### Usage: st_geod_azimuth(x, y = NULL) Source: https://r-spatial.github.io/lwgeom/reference/st_geod_azimuth.html Function signature for `st_geod_azimuth`. It takes an object of class `sf`, `sfc`, or `sfg` as `x`, and optionally a second object `y` of the same classes or NULL. ```R st_geod_azimuth(x, y = NULL) ``` -------------------------------- ### st_linesubstring usage Source: https://r-spatial.github.io/lwgeom/reference/st_linesubstring.html Usage signature for st_linesubstring. Arguments: x (object of class sfc, sf, or sfg), from and to (relative distances in [0,1]), tolerance (snap to line node), and ... (ignored). Returns an object of class sfc. ```r st_linesubstring(x, from, to, tolerance, ...) ``` -------------------------------- ### st_subdivide(x, max_vertices) Source: https://r-spatial.github.io/lwgeom/reference/st_subdivide.html Subdivides geometries into smaller parts with a maximum number of vertices. ```APIDOC ## st_subdivide(x, max_vertices) ### Description Returns a collection of geometries resulting by subdividing a geometry. ### Usage ```r st_subdivide(x, max_vertices) ``` ### Arguments - **x** - object with geometries to be subdivided - **max_vertices** - integer; maximum size of the subgeometries (at least 8) ### Value object of the same class as `x` ### Examples ```r library(sf) demo(nc, ask = FALSE, echo = FALSE) x = st_subdivide(nc, 10) plot(x[1]) ``` ``` -------------------------------- ### st_subdivide usage Source: https://r-spatial.github.io/lwgeom/reference/st_subdivide.html Usage signature for the st_subdivide function. x is the geometry object to subdivide, and max_vertices is an integer specifying the maximum number of vertices per subgeometry (must be at least 8). ```r st_subdivide(x, max_vertices) ``` -------------------------------- ### Usage of st_astext and st_asewkt Source: https://r-spatial.github.io/lwgeom/reference/st_astext.html Usage signature for st_astext and st_asewkt. st_astext returns WKT of a simple feature geometry or CRS; st_asewkt returns WKT with SRID metadata. The EWKT argument controls whether PostGIS Enhanced WKT (including SRID) is used. ```r st_astext(x, digits = getOption("digits"), ..., EWKT = FALSE) st_asewkt(x, digits = options("digits")) ``` -------------------------------- ### Usage of st_geohash and st_geom_from_geohash Source: https://r-spatial.github.io/lwgeom/reference/st_geohash.html Usage signature for the two geohash functions in the lwgeom package. st_geohash computes a geohash from coordinates; st_geom_from_geohash converts a geohash back to a bounding-box polygon or matrix. ```r st_geohash(x, precision = 0) st_geom_from_geohash( hash, precision = -1, crs = st_crs("OGC:CRS84"), raw = FALSE ) ``` -------------------------------- ### st_geod_distance(x, y, tolerance = 0, sparse = FALSE) Source: https://r-spatial.github.io/lwgeom/reference/geod.html Computes the geodetic distance between geometries in x and y. Returns a dense or sparse matrix of distances. ```APIDOC ## st_geod_distance(x, y, tolerance = 0, sparse = FALSE) ### Description Computes the geodetic distance between geometries in x and y. ### Usage st_geod_distance(x, y, tolerance = 0, sparse = FALSE) ### Arguments - **x** (sf/sfc/sfg) - Required - Object of class `sf`, `sfc`, or `sfg`. - **y** (sf/sfc/sfg) - Required - Object of class `sf`, `sfc`, or `sfg`. - **tolerance** (double/units) - Optional - If positive, the first distance less than `tolerance` is returned, rather than the true distance. Default is 0. - **sparse** (logical) - Optional - If `TRUE`, return a sparse matrix (object of class `sgbp`), otherwise, return a dense logical matrix. Default is `FALSE`. ### Examples ```r library(sf) pole = st_polygon(list(rbind(c(0,80), c(120,80), c(240,80), c(0,80)))) pt = st_point(c(30,70)) x = st_sfc(pole, pt, crs = 4326) st_geod_distance(x, x) # Units: [m] # [,1] [,2] # [1,] 0 1378923 # [2,] 1378923 0 ``` ``` -------------------------------- ### st_transform_proj(x, crs, ...) Source: https://r-spatial.github.io/lwgeom/reference/st_transform_proj.html Transforms or converts coordinates of simple features directly with Proj.4, bypassing GDAL. Supports sf, sfc, and sfg objects. ```APIDOC ## st_transform_proj(x, crs, ...) ### Description Transform or convert coordinates of simple features directly with Proj.4, bypassing GDAL. This function provides an alternative to `st_transform` for cases where the source CRS is not accepted by GDAL or when direct PROJ usage is preferred. ### Usage ```r st_transform_proj(x, crs, ...) # S3 method for class 'sfc' st_transform_proj(x, crs, ...) # S3 method for class 'sf' st_transform_proj(x, crs, ...) # S3 method for class 'sfg' st_transform_proj(x, crs, ...) ``` ### Arguments - **x** (object of class `sf`, `sfc`, or `sfg`) - Required - The simple feature object whose coordinates are to be transformed. - **crs** (character) - Required - Target CRS as a proj4string. If a length 2 character vector, it specifies source and target CRS respectively. - **...** - Optional - Ignored. ### Details Transforms coordinates of object to new projection using PROJ directly rather than the GDAL API used by `st_transform`. If `crs` is a single CRS, it forms the target CRS, and the source CRS is obtained as `st_crs(x)`. Since this presumes that the source CRS is accepted by GDAL (which is not always the case), a second option is to specify the source and target CRS as two proj4strings in argument `crs`. In the latter case, `st_crs(x)` is ignored and may well be `NA`. The `st_transform_proj` method for `sfg` objects assumes that the CRS of the object is available as an attribute of that name. ### Examples ```r library(sf) p1 = st_point(c(7,52)) p2 = st_point(c(-30,20)) sfc = st_sfc(p1, p2, crs = 4326) st_transform_proj(sfc, "+proj=wintri") library(sf) nc = st_read(system.file("shape/nc.shp", package="sf")) st_transform_proj(nc[1,], "+proj=wintri +over") st_transform_proj(structure(p1, proj4string = "+init=epsg:4326"), "+init=epsg:3857") ``` ``` -------------------------------- ### st_endpoint(x) Source: https://r-spatial.github.io/lwgeom/reference/st_startpoint.html Function to extract the end point from a line geometry. ```APIDOC ## st_endpoint(x) ### Description Returns the end point of a line geometry. ### Usage ```r st_endpoint(x) ``` ### Arguments - **x** (line of class `sf`, `sfc` or `sfg`) - Required - The line geometry from which to extract the end point. ### Value An `sf` object representing the end point. ### Details See https://postgis.net/docs/ST_EndPoint.html. ### Examples ```r library(sf) m = matrix(c(0, 1, 2, 0, 1, 4), ncol = 2) l = st_sfc(st_linestring(m)) lwgeom::st_endpoint(l) #> Geometry set for 1 feature #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 2 ymin: 4 xmax: 2 ymax: 4 #> CRS: NA #> POINT (2 4) ``` ``` -------------------------------- ### st_as_sfc.TWKB Source: https://r-spatial.github.io/lwgeom/reference/st_as_sfc.TWKB.html S3 method for class 'TWKB' that converts a TWKB object (list of raw vectors) into an sfc object. The method is used by the sf package to read TWKB geometries. ```APIDOC ## st_as_sfc.TWKB ### Description S3 method for class 'TWKB' that converts a TWKB object (list of raw vectors) into an sfc object. The method is used by the sf package to read TWKB geometries. ### Usage ```r # S3 method for class 'TWKB' st_as_sfc(x, ...) ``` ### Arguments - **x** (list) - Required - A list with raw vectors, of class `TWKB`. - **...** - Optional - Ignored. ### Value An `sfc` object representing the geometry set. ### Examples ```r l = structure(list(as.raw(c(0x02, 0x00, 0x02, 0x02, 0x02, 0x08, 0x08))), class = "TWKB") library(sf) # load generic st_as_sfc(l) #> Geometry set for 1 feature #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 5 ymax: 5 #> CRS: NA #> LINESTRING (1 1, 5 5) ``` ### See Also https://github.com/TWKB/Specification/blob/master/twkb.md ``` -------------------------------- ### st_geod_covered_by(x, y, sparse = TRUE) Source: https://r-spatial.github.io/lwgeom/reference/geod.html Determines whether geometries in x are covered by geometries in y. Returns a sparse or dense logical matrix. ```APIDOC ## st_geod_covered_by(x, y, sparse = TRUE) ### Description Determines whether geometries in x are covered by geometries in y. ### Usage st_geod_covered_by(x, y, sparse = TRUE) ### Arguments - **x** (sf/sfc/sfg) - Required - Object of class `sf`, `sfc`, or `sfg`. - **y** (sf/sfc/sfg) - Required - Object of class `sf`, `sfc`, or `sfg`. - **sparse** (logical) - Optional - If `TRUE`, return a sparse matrix (object of class `sgbp`), otherwise, return a dense logical matrix. Default is `TRUE`. ### Note This function is used by st_distance, do not use it directly. ``` -------------------------------- ### st_split(x, y) Source: https://r-spatial.github.io/lwgeom/reference/st_split.html Splits a geometry or set of geometries by a blade (another geometry). Returns a collection of geometries resulting from the split. ```APIDOC ## st_split(x, y) ### Description Return a collection of geometries resulting by splitting a geometry. ### Usage ```r st_split(x, y) ``` ### Arguments - **x** - object with geometries to be splitted - **y** - object split with (blade); if `y` contains more than one feature geometry, the geometries are st_combine'd ### Value object of the same class as `x` ### Examples ```r library(sf) l = st_as_sfc('MULTILINESTRING((10 10, 190 190), (15 15, 30 30, 100 90))') pt = st_sfc(st_point(c(30,30))) st_split(l, pt) #> Geometry set for 1 feature #> Geometry type: GEOMETRYCOLLECTION #> Dimension: XY #> Bounding box: xmin: 10 ymin: 10 xmax: 190 ymax: 190 #> CRS: NA #> GEOMETRYCOLLECTION (LINESTRING (10 10, 30 30), ... ``` ``` -------------------------------- ### st_force_polygon_cw usage signature Source: https://r-spatial.github.io/lwgeom/reference/st_force_polygon_cw.html The function signature for st_force_polygon_cw, which takes an object with polygon geometries and returns an object of the same class. ```r st_force_polygon_cw(x) ```