\name{topology}

\docType{methods}

\alias{topology}

\alias{makeNodes}
\alias{mergeLines}
\alias{removeDupNodes}
\alias{emptyGeoms}
\alias{snap}

\alias{makeNodes,SpatVector-method}
\alias{mergeLines,SpatVector-method}
\alias{snap,SpatVector-method}
\alias{removeDupNodes,SpatVector-method}
\alias{emptyGeoms,SpatVector-method}

\title{ 
Vector topology methods
}

\description{

\code{makeNodes} create nodes on lines

\code{mergeLines} connect lines to form polygons

\code{removeDupNodes} removes duplicate nodes in geometries and optionally rounds the coordinates

\code{emptyGeoms} returns the indices of empty (null) geometries. \code{\link{is.na}} also checks if any of the coordinates is \code{NA}.

\code{snap} makes boundaries of geometries identical if they are very close to each other. The \code{tolerance} is expressed in the coordinate reference system's units: meters (or feet, etc.) for projected data, and \strong{degrees} for lon/lat data. To snap lon/lat geometries with a tolerance expressed in meters, project the data to a metric CRS first with \code{\link{project}}, snap, then project back. \code{\link{simplifyGeom}} uses the same convention.
}

\usage{
\S4method{mergeLines}{SpatVector}(x)
\S4method{snap}{SpatVector}(x, y=NULL, tolerance)
\S4method{removeDupNodes}{SpatVector}(x, digits = -1)
\S4method{makeNodes}{SpatVector}(x)
}

\arguments{
\item{x}{SpatVector of lines or polygons}
\item{y}{SpatVector of lines or polygons to snap to. If \code{NULL} snapping is to the other geometries in \code{x}}
\item{tolerance}{numeric. Snapping tolerance, expressed in the units of the CRS of \code{x} (i.e. meters or feet for projected data, \strong{degrees} for lon/lat data). One degree of latitude is approximately 111 km.}
\item{digits}{numeric. Number of digits used in rounding. Ignored if < 0}
} 

\value{
SpatVector
}


\seealso{\code{\link{sharedPaths}}, \code{\link{gaps}}, \code{\link{simplifyGeom}}, \code{\link{forceCCW}}, \code{\link{fillHoles}}}




\examples{
p1 <- as.polygons(ext(0,1,0,1))
p2 <- as.polygons(ext(1.1,2,0,1))

p <- rbind(p1, p2)

y <- snap(p, tol=.15)
plot(p, lwd=3, col="light gray")
lines(y, col="red", lwd=2)
}

\keyword{methods}
\keyword{spatial}

