Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 26, 2024
1 parent d9d90c3 commit e0aeea9
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 479 deletions.
52 changes: 2 additions & 50 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,56 +117,8 @@ rgb2hex <- function(x) {
.Call(`_terra_uniqueSymmetricRows`, x, y)
}

dist_lonlat <- function(lon1, lat1, lon2, lat2) {
.Call(`_terra_dist_lonlat`, lon1, lat1, lon2, lat2)
}

dist_cosine <- function(lon1, lat1, lon2, lat2, r = 6378137) {
.Call(`_terra_dist_cosine`, lon1, lat1, lon2, lat2, r)
}

dist_cosine_rad <- function(lon1, lat1, lon2, lat2, r = 6378137) {
.Call(`_terra_dist_cosine_rad`, lon1, lat1, lon2, lat2, r)
}

dest_lonlat <- function(slon, slat, sazi, dist, dlon, dlat, dazi) {
invisible(.Call(`_terra_dest_lonlat`, slon, slat, sazi, dist, dlon, dlat, dazi))
}

dir_lonlat <- function(lon1, lat1, lon2, lat2) {
.Call(`_terra_dir_lonlat`, lon1, lat1, lon2, lat2)
}

dir_rad <- function(lon1, lat1, lon2, lat2) {
.Call(`_terra_dir_rad`, lon1, lat1, lon2, lat2)
}

dist2track <- function(lon1, lat1, lon2, lat2, plon, plat, sign, r = 6378137) {
.Call(`_terra_dist2track`, lon1, lat1, lon2, lat2, plon, plat, sign, r)
}

dist2track_cosine_rad <- function(lon1, lat1, lon2, lat2, plon, plat, sign, r = 6378137) {
.Call(`_terra_dist2track_cosine_rad`, lon1, lat1, lon2, lat2, plon, plat, sign, r)
}

alongTrackDistance <- function(lon1, lat1, lon2, lat2, plon, plat, r = 6378137) {
.Call(`_terra_alongTrackDistance`, lon1, lat1, lon2, lat2, plon, plat, r)
}

alongTrackDistance_rad <- function(lon1, lat1, lon2, lat2, plon, plat, r = 6378137) {
.Call(`_terra_alongTrackDistance_rad`, lon1, lat1, lon2, lat2, plon, plat, r)
}

dist2segment <- function(plon, plat, lon1, lat1, lon2, lat2) {
.Call(`_terra_dist2segment`, plon, plat, lon1, lat1, lon2, lat2)
}

dist2segment_cosine_rad <- function(plon, plat, lon1, lat1, lon2, lat2, r = 6378137) {
.Call(`_terra_dist2segment_cosine_rad`, plon, plat, lon1, lat1, lon2, lat2, r)
}

dist2segmentPoint <- function(plon, plat, lon1, lat1, lon2, lat2, ilon, ilat) {
.Call(`_terra_dist2segmentPoint`, plon, plat, lon1, lat1, lon2, lat2, ilon, ilat)
dist2segmentPoint_geo <- function(plon, plat, lon1, lat1, lon2, lat2, ilon, ilat) {
.Call(`_terra_dist2segmentPoint_geo`, plon, plat, lon1, lat1, lon2, lat2, ilon, ilat)
}

intermediate <- function(lon1, lat1, lon2, lat2, n, distance) {
Expand Down
14 changes: 7 additions & 7 deletions R/distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ setMethod("gridDist", signature(x="SpatRaster"),


setMethod("distance", signature(x="SpatRaster", y="SpatVector"),
function(x, y, unit="m", rasterize=FALSE, method="haversine", filename="", ...) {
function(x, y, unit="m", rasterize=FALSE, method="cosine", filename="", ...) {
opt <- spatOptions(filename, ...)
unit <- as.character(unit[1])

Expand All @@ -85,7 +85,7 @@ setMethod("distance", signature(x="SpatRaster", y="SpatVector"),


setMethod("distance", signature(x="SpatRaster", y="sf"),
function(x, y, unit="m", rasterize=FALSE, method="haversine", filename="", ...) {
function(x, y, unit="m", rasterize=FALSE, method="cosine", filename="", ...) {
distance(x, vect(y), unit=unit, rasterize=rasterize, method=method, filename=filename, ...)
}
)
Expand Down Expand Up @@ -113,7 +113,7 @@ mat2wide <- function(m, sym=TRUE, keep=NULL) {
}

setMethod("distance", signature(x="SpatVector", y="ANY"),
function(x, y, sequential=FALSE, pairs=FALSE, symmetrical=TRUE, unit="m", method="geo") {
function(x, y, sequential=FALSE, pairs=FALSE, symmetrical=TRUE, unit="m", method="cosine") {
if (!missing(y)) {
error("distance", "If 'x' is a SpatVector, 'y' should be a SpatVector or missing")
}
Expand Down Expand Up @@ -144,7 +144,7 @@ setMethod("distance", signature(x="SpatVector", y="ANY"),


setMethod("distance", signature(x="SpatVector", y="SpatVector"),
function(x, y, pairwise=FALSE, unit="m", method = "geo") {
function(x, y, pairwise=FALSE, unit="m", method = "cosine") {
unit <- as.character(unit[1])
d <- x@pntr$distance_other(y@pntr, pairwise, unit, method)
messages(x, "distance")
Expand Down Expand Up @@ -205,15 +205,15 @@ setMethod("distance", signature(x="matrix", y="missing"),

setMethod("distance", signature(x="data.frame", y="missing"),
function(x, y, lonlat=NULL, sequential=FALSE, pairs=FALSE, symmetrical=TRUE, unit="m", method="geo") {
distance(as.matrix(x), lonlat=lonlat, sequential=sequential, pairs=pairs, symmetrical=symmetrical, unit=unit, method="geo")
distance(as.matrix(x), lonlat=lonlat, sequential=sequential, pairs=pairs, symmetrical=symmetrical, unit=unit, method=method)
}
)


setMethod("direction", signature(x="SpatRaster"),
function(x, from=FALSE, degrees=FALSE, filename="", ...) {
function(x, from=FALSE, degrees=FALSE, method="cosine", filename="", ...) {
opt <- spatOptions(filename, ...)
x@pntr <- x@pntr$rastDirection(from[1], degrees[1], NA, NA, opt)
x@pntr <- x@pntr$rastDirection(from[1], degrees[1], NA, NA, method, opt)
messages(x, "direction")
}
)
Expand Down
2 changes: 1 addition & 1 deletion R/ncdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ write_tags <- function(tags, nc, varid, prefix="TAG_") {
}
write_tags(metags(y), ncobj, ncvars[[i]], "")
}
if (progress) utils::close(pb)
if (progress) close(pb)

ncdf4::ncatt_put(ncobj, 0, "Conventions", "CF-1.4", prec="text")
pkgversion <- drop(read.dcf(file=system.file("DESCRIPTION", package="terra"), fields=c("Version")))
Expand Down
6 changes: 3 additions & 3 deletions R/panel.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

setMethod("panel", signature(x="SpatRaster"),
function(x, main, loc.main="topleft", nc, nr, maxnl=16, maxcell=500000,
box=FALSE, pax=list(), plg=list(), range=NULL, ...) {
box=FALSE, pax=list(), plg=list(), range=NULL, halo=TRUE, ...) {

dots <- list(...)
if (!is.null(dots$type)) {
Expand Down Expand Up @@ -97,10 +97,10 @@ setMethod("panel", signature(x="SpatRaster"),
y <- x[[i]]
levels(y) <- lv
plot(y, 1, main=main[i], mar=mar, legend=legend[i], pax=pax, box=box,
loc.main=loc.main, halo=TRUE, plg=plg, type="classes", ...)
loc.main=loc.main, halo=halo, plg=plg, type="classes", ...)
} else {
plot(x, i, main=main[i], mar=mar, legend=legend[i], range=range, pax=pax, box=box,
loc.main=loc.main, halo=TRUE, plg=plg, type=ptype, ...)
loc.main=loc.main, halo=halo, plg=plg, type=ptype, ...)
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions man/direction.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ The direction (azimuth) to or from the nearest cell that is not \code{NA}. The d
}

\usage{
\S4method{direction}{SpatRaster}(x, from=FALSE, degrees=FALSE, filename="", ...)
\S4method{direction}{SpatRaster}(x, from=FALSE, degrees=FALSE, method="cosine", filename="", ...)
}

\arguments{
\item{x}{SpatRaster}
\item{filename}{Character. Output filename (optional)}
\item{degrees}{Logical. If \code{FALSE} (the default) the unit of direction is radians.}
\item{from}{Logical. Default is \code{FALSE}. If \code{TRUE}, the direction from (instead of to) the nearest cell that is not \code{NA} is returned}
\item{degrees}{Logical. If \code{FALSE} (the default) the unit of direction is radians.}
\item{method}{character. Should be "geo", or "cosine". With "geo" the most precise but slower geodesic method of Karney (2003) is used. The "cosine" method is faster but less precise}
\item{filename}{Character. Output filename (optional)}
\item{...}{Additional arguments as for \code{\link{writeRaster}}}
}

Expand Down
8 changes: 4 additions & 4 deletions man/distance.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ If \code{y} is missing, the distance between each points in \code{x} with all ot
\usage{
\S4method{distance}{SpatRaster,missing}(x, y, target=NA, exclude=NULL, unit="m", method="haversine", filename="", ...)

\S4method{distance}{SpatRaster,SpatVector}(x, y, unit="m", rasterize=FALSE, method="haversine", filename="", ...)
\S4method{distance}{SpatRaster,SpatVector}(x, y, unit="m", rasterize=FALSE, method="cosine", filename="", ...)

\S4method{distance}{SpatVector,ANY}(x, y, sequential=FALSE, pairs=FALSE, symmetrical=TRUE, unit="m", method="geo")
\S4method{distance}{SpatVector,ANY}(x, y, sequential=FALSE, pairs=FALSE, symmetrical=TRUE, unit="m", method="cosine")

\S4method{distance}{SpatVector,SpatVector}(x, y, pairwise=FALSE, unit="m", method="geo")
\S4method{distance}{SpatVector,SpatVector}(x, y, pairwise=FALSE, unit="m", method="cosine")

\S4method{distance}{matrix,matrix}(x, y, lonlat, pairwise=FALSE, unit="m", method="geo")

Expand All @@ -66,7 +66,7 @@ If \code{y} is missing, the distance between each points in \code{x} with all ot
\item{target}{numeric. The value of the cells for which distances to cells that are not \code{NA} should be computed}
\item{exclude}{numeric. The value of the cells that should not be considered for computing distances}
\item{unit}{character. Can be either "m" or "km"}
\item{method}{character. One of "geo", "haversine", "cosine". With "geo" the most precise but slower method of Karney (2003) is used. The other two methods are faster but less precise}
\item{method}{character. One of "geo", "cosine" or "haversine" (the latter cannot be used for distances to lines or polygons). With "geo" the most precise but slower method of Karney (2003) is used. The other two methods are faster but less precise}
\item{rasterize}{logical. If \code{TRUE} distance is computed from the cells covered by the geometries after rasterization. This can be much faster in some cases}
\item{filename}{character. Output filename}
\item{...}{additional arguments for writing files as in \code{\link{writeRaster}}}
Expand Down
3 changes: 2 additions & 1 deletion man/panel.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Show multiple maps that share a single legend.

\usage{
\S4method{panel}{SpatRaster}(x, main, loc.main="topleft", nc, nr, maxnl=16,
maxcell=500000, box=FALSE, pax=list(), plg=list(), range=NULL, ...)
maxcell=500000, box=FALSE, pax=list(), plg=list(), range=NULL, halo=TRUE, ...)
}

\arguments{
Expand All @@ -28,6 +28,7 @@ Show multiple maps that share a single legend.
\item{plg}{see \code{\link{plot}}}
\item{pax}{see \code{\link{plot}}}
\item{range}{numeric. minimum and maximum values to be used for the continuous legend }
\item{halo}{logical. Use a halo around main (the title)?}
\item{...}{arguments passed to \code{plot("SpatRaster", "numeric")} and additional graphical arguments}
}

Expand Down
Loading

0 comments on commit e0aeea9

Please sign in to comment.