File: st_snap_to_grid.Rd

package info (click to toggle)
r-cran-lwgeom 0.2-14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,532 kB
  • sloc: ansic: 40,523; cpp: 439; sh: 14; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 934 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/snap_to_grid.R
\name{st_snap_to_grid}
\alias{st_snap_to_grid}
\title{Snap geometries to a grid}
\usage{
st_snap_to_grid(x, size, origin)
}
\arguments{
\item{x}{object with geometries to be snapped}

\item{size}{numeric or (length) units object; grid cell size in x-, y- (and possibly z- and m-) directions}

\item{origin}{numeric; origin of the grid}
}
\value{
object of the same class as \code{x}
}
\description{
Snap geometries to a grid
}
\examples{
# 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)
}
}