Skip to content

Commit

Permalink
wshed ch2
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed May 29, 2024
1 parent 79ad5b5 commit 8310595
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 48 deletions.
12 changes: 7 additions & 5 deletions R/watershed.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
# License GPL v3

setMethod("watershed", signature(x="SpatRaster"),
function(x, pourpoin, filename="", ...) {
opt <- spatOptions(filename, ...)
x@ptr <- x@ptr$watershed2(as.integer(offset-1), opt)
messages(x, "watershed2") ## EC 20210318
function(x, pourpoint, filename="", ...) {
opt <- spatOptions(filename, ...)
cell <- cellFromXY(x, pourpoint)
if (is.na(cell)) error("watershed", "pourpoint not on raster")
x@ptr <- x@ptr$watershed2(as.integer(cell-1), opt)
messages(x, "watershed") ## EC 20210318
}
)

Expand Down Expand Up @@ -35,7 +37,7 @@ setMethod("flowAccumulation", signature(x="SpatRaster"),
} else {
x@ptr <- x@ptr$flowAccu2_weight(weight@ptr, opt)
}
messages(x, "flowAccu2")
messages(x, "flowAccumulation")
}
)

Expand Down
49 changes: 23 additions & 26 deletions man/NIPD.Rd
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
\docType{methods}
\name{NIDP2}
\name{NIDP}

\alias{NIDP2}
\alias{NIDP2,SpatRaster-method}
\alias{NIDP}
\alias{NIDP,SpatRaster-method}


\title{Number of immediate adjacent cells flowing into each cell (Watershed Analysis)}
\title{Number of immediate adjacent cells flowing into each cell}

\description{
It computes the number of immediate adjacent cells flowing into each cell (Watershed Analysis)
Compute the number of immediate adjacent cells flowing into each cell
}

\usage{
\S4method{NIDP2}{SpatRaster}(p,filename="",...)
\S4method{NIDP}{SpatRaster}(x, filename="",...)
}

\arguments{
\item{p}{Flow Direction raster map, a \code{\link{SpatRaster-class}} object, see also \code{\link{terrain}}. }
\item{filename,...}{list. Options for writing files as in \code{\link{writeRaster}}}
\item{x}{SpatRaster with flow-direction. see \code{\link{terrain}}}
\item{filename}{character. Output filename}
\item{...}{additional arguments for writing files as in \code{\link{writeRaster}}}
}

\value{

A \code{\link{SpatRaster-class}} (raster) map containing the value for each cell.
SpatRaster
}

\details{
NDIP is computed to preliminarly to compute Flow Accumulation area in the algorithm proposed by Zhouo at al,2019.
NDIP is computed first to compute flow-accumulation with the algorithm by Zhou at al, 2019.
}


}

\seealso{\code{\link{flowAccu2}},\code{\link{flowAccu2_weight}}}
\author{

Emanuele Cordano (implementation of the algorithm within the package),Guiyun Zhou, Wenyan Dong and Hongqiang Wei
\references{
Zhou, G., Wei, H. & Fu, S. A fast and simple algorithm for calculating flow accumulation matrices from raster digital elevation. Front. Earth Sci. 13, 317326 (2019). https://doi.org/10.1007/s11707-018-0725-9
\url{https://link.springer.com/article/10.1007/s11707-018-0725-9}
}

\examples{


\seealso{\code{\link{flowAccumulation}}}

\author{Emanuele Cordano }

\examples{

elev1 <- array(NA,c(9,9))
elev2 <- elev1
dx <- 1
Expand All @@ -55,7 +60,7 @@ for (r in 1:nrow(elev1)) {
}


## Elevation Raster Maps
## Elevation Raster
elev1 <- rast(elev1)
elev2 <- rast(elev2)

Expand All @@ -65,7 +70,7 @@ t(array(elev2[],rev(dim(elev2)[1:2])))
plot(elev1)
plot(elev2)

## Flow Direction Raster Maps
## Flow Direction Raster
flowdir1<- terrain(elev1,v="flowdir")
flowdir2<- terrain(elev2,v="flowdir")

Expand All @@ -90,12 +95,4 @@ plot(nidp2)




\references{
Zhou, G., Wei, H. & Fu, S. A fast and simple algorithm for calculating flow accumulation matrices from raster digital elevation. Front. Earth Sci. 13, 317326 (2019). https://doi.org/10.1007/s11707-018-0725-9
\url{https://link.springer.com/article/10.1007/s11707-018-0725-9}
}



\keyword{spatial}
17 changes: 9 additions & 8 deletions man/pitfinder.Rd
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
\docType{methods}
\name{pitfinder2}
\name{pitfinder}

\alias{pitfinder2}
\alias{pitfinder2,SpatRaster-method}
\alias{pitfinder}
\alias{pitfinder,SpatRaster-method}


\title{Pit Finder in a Flow Dir Raster map for Watershed Extraction}
\title{Pit Finder in a Flow Dir SpatRaster for Watershed Extraction}

\description{
It extractions a watershed mask from a flow direction input raster point a pour-point cell.
find pits (depressions with no outlet )
}

\usage{
\S4method{pitfinder2}{SpatRaster}(p,filename="",...)
\S4method{pitfinder}{SpatRaster}(x,filename="",...)
}

\arguments{
\item{p}{Flow Direction raster map, a \code{\link{SpatRaster-class}} object, see also \code{\link{terrain}}. }
\item{filename,...}{list. Options for writing files as in \code{\link{writeRaster}}}
\item{p}{SpatRaster wih flow-direcion. See \code{\link{terrain}}}
\item{filename}{character. Output filename}
\item{...}{additional arguments for writing files as in \code{\link{writeRaster}}}
}

\value{
Expand Down
14 changes: 5 additions & 9 deletions man/watershed.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
\alias{watershed,SpatRaster-method}


\title{Catchment delineation }
\title{Catchment delineation}

\description{
delineate the area covered b a cachment given from a SpatRaster with flow direction a pour-point (watershed outlet).
delineate the area covered by a catchment from a SpatRaster with flow direction and a pour-point (catchment outlet).
}

\usage{
Expand All @@ -17,7 +17,7 @@ delineate the area covered b a cachment given from a SpatRaster with flow direct

\arguments{
\item{p}{SpatRaster with flow direction. See \code{\link{terrain}}. }
\item{pourpoint}{pour point location}
\item{pourpoint}{matrix or SpatVector with the pour point location}
\item{filename}{character. Output filename}
\item{...}{additional arguments for writing files as in \code{\link{writeRaster}}}
}
Expand All @@ -33,13 +33,9 @@ Ezio Crestaz, Emanuele Cordano, Roman Seliger
\examples{
elev <- rast(system.file('ex/elev_vinschgau.tif', package="terra"))
flowdir <- terrain(elev, "flowdir")
flowacc <- flowAccu2(flowdir)
## pour point at Naturns
#pp_lonlat <- vect(x=c(11.004167,46.65)),crs=4326)
#pp <- projec(pp_lonlat,crs=crs(flowacc))
#ipp <- cellFromXY(flowacc,st_coordinates(pp))
#poutr <- watershed((flowdir),as.integer(ipp))

pp <- cbind(653358.3, 5168222)
w <- watershed(flowdir, pp)
}

\keyword{spatial}

0 comments on commit 8310595

Please sign in to comment.