Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 25, 2024
1 parent 98ab451 commit e4d5eb8
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 83 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
- `autocor` improved handling of NA cells for global Moran computation [#1992](https://github.com/rspatial/terra/issues/1592) by Nicholas Berryman
- `shade` is more memory-safe. [#1452](https://github.com/rspatial/terra/issues/1452) by Francis van Oordt and Chris English


## enhancements

- `plot<SpatVector>` now uses the same default viridis color palette as `plot<SpatRaster>` [#1670](https://github.com/rspatial/terra/issues/1670) by Márcia Barbosa
- `relate` now accepts relation="equals" [#1672](https://github.com/rspatial/terra/issues/1672) by Krzysztof Dyba
- `init` accepts additional arguments for function "fun"
- better handling of the 32 connection limiations set by the HDF4 library [#1481](https://github.com/rspatial/terra/issues/1481) by Dimitri Falk
- When using RStudio a once per session warning is given when using draw, sel or click [#1063](https://github.com/rspatial/terra/issues/1063) by Sergei Kharchenko
- `distance<SpatRaster>` from lon and lat lines/polygons computes distance to the edges instead of the nodes [#1462](https://github.com/rspatial/terra/issues/1462) by Derek Friend

## new

Expand Down
20 changes: 10 additions & 10 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,28 @@ dir_rad <- function(lon1, lat1, lon2, lat2) {
.Call(`_terra_dir_rad`, lon1, lat1, lon2, lat2)
}

dist2track <- function(lon1, lat1, lon2, lat2, plon, plat, sign) {
.Call(`_terra_dist2track`, lon1, lat1, lon2, lat2, plon, plat, sign)
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) {
.Call(`_terra_dist2track_cosine_rad`, lon1, lat1, lon2, lat2, plon, plat, sign)
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) {
.Call(`_terra_alongTrackDistance`, lon1, lat1, lon2, lat2, plon, plat)
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) {
.Call(`_terra_alongTrackDistance_rad`, lon1, lat1, lon2, lat2, plon, plat)
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) {
.Call(`_terra_dist2segment_cosine_rad`, 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) {
Expand Down
16 changes: 12 additions & 4 deletions R/panel.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ setMethod("panel", signature(x="SpatRaster"),
if (is.null(range)) {
if (all(hasMinMax(x))) {
range <- range(minmax(x, FALSE))
if (any(is.nan(range) | is.infinite(range))) {
r <- as.matrix(spatSample(x, maxcell, method="regular", as.raster=FALSE, warn=FALSE))
r[is.infinite(r)] <- NA
range <- range(r, na.rm=TRUE)
}
} else {
x <- spatSample(x, maxcell, method="regular", as.raster=TRUE, warn=FALSE)
range <- range(minmax(x, TRUE))
r <- as.matrix(spatSample(x, maxcell, method="regular", as.raster=FALSE, warn=FALSE))
r[is.infinite(r)] <- NA
range <- range(r, na.rm=TRUE)
}
}
if (diff(range) > 0) {
Expand All @@ -84,17 +90,19 @@ setMethod("panel", signature(x="SpatRaster"),
if (is.null(plg$size)) plg$size <- max(1, nrnc[1] * 0.66)
if (is.null(plg$cex)) plg$cex <- 1.25
plg$yshift <- (nrnc[1] %% 2 == 0)

for (i in 1:nl) {
pax$side <- c(bottom[i], left[i])
if (categorical) {
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, plg=plg, type="classes", ...)
loc.main=loc.main, halo=TRUE, 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, plg=plg, type=ptype, ...)
loc.main=loc.main, halo=TRUE, plg=plg, type=ptype, ...)
}
}
}
)

7 changes: 1 addition & 6 deletions R/plot_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ hexcols <- function(out) {
}


.as.raster.continuous <- function(out, x, type, Z=NULL) {

if (is.null(Z)) {
Z <- as.matrix(x, wide=TRUE)
Z[is.nan(Z) | is.infinite(Z)] <- NA
}
.as.raster.continuous <- function(out, x, type) {

Z <- as.matrix(x, wide=TRUE)
Z[is.nan(Z) | is.infinite(Z)] <- NA
Expand Down
45 changes: 25 additions & 20 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ BEGIN_RCPP
END_RCPP
}
// dist2track
double dist2track(double lon1, double lat1, double lon2, double lat2, double plon, double plat, bool sign);
RcppExport SEXP _terra_dist2track(SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP plonSEXP, SEXP platSEXP, SEXP signSEXP) {
double dist2track(double lon1, double lat1, double lon2, double lat2, double plon, double plat, bool sign, double r);
RcppExport SEXP _terra_dist2track(SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP plonSEXP, SEXP platSEXP, SEXP signSEXP, SEXP rSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -437,13 +437,14 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< double >::type plon(plonSEXP);
Rcpp::traits::input_parameter< double >::type plat(platSEXP);
Rcpp::traits::input_parameter< bool >::type sign(signSEXP);
rcpp_result_gen = Rcpp::wrap(dist2track(lon1, lat1, lon2, lat2, plon, plat, sign));
Rcpp::traits::input_parameter< double >::type r(rSEXP);
rcpp_result_gen = Rcpp::wrap(dist2track(lon1, lat1, lon2, lat2, plon, plat, sign, r));
return rcpp_result_gen;
END_RCPP
}
// dist2track_cosine_rad
double dist2track_cosine_rad(double lon1, double lat1, double lon2, double lat2, double plon, double plat, bool sign);
RcppExport SEXP _terra_dist2track_cosine_rad(SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP plonSEXP, SEXP platSEXP, SEXP signSEXP) {
double dist2track_cosine_rad(double lon1, double lat1, double lon2, double lat2, double plon, double plat, bool sign, double r);
RcppExport SEXP _terra_dist2track_cosine_rad(SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP plonSEXP, SEXP platSEXP, SEXP signSEXP, SEXP rSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -454,13 +455,14 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< double >::type plon(plonSEXP);
Rcpp::traits::input_parameter< double >::type plat(platSEXP);
Rcpp::traits::input_parameter< bool >::type sign(signSEXP);
rcpp_result_gen = Rcpp::wrap(dist2track_cosine_rad(lon1, lat1, lon2, lat2, plon, plat, sign));
Rcpp::traits::input_parameter< double >::type r(rSEXP);
rcpp_result_gen = Rcpp::wrap(dist2track_cosine_rad(lon1, lat1, lon2, lat2, plon, plat, sign, r));
return rcpp_result_gen;
END_RCPP
}
// alongTrackDistance
double alongTrackDistance(double lon1, double lat1, double lon2, double lat2, double plon, double plat);
RcppExport SEXP _terra_alongTrackDistance(SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP plonSEXP, SEXP platSEXP) {
double alongTrackDistance(double lon1, double lat1, double lon2, double lat2, double plon, double plat, double r);
RcppExport SEXP _terra_alongTrackDistance(SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP plonSEXP, SEXP platSEXP, SEXP rSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -470,13 +472,14 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< double >::type lat2(lat2SEXP);
Rcpp::traits::input_parameter< double >::type plon(plonSEXP);
Rcpp::traits::input_parameter< double >::type plat(platSEXP);
rcpp_result_gen = Rcpp::wrap(alongTrackDistance(lon1, lat1, lon2, lat2, plon, plat));
Rcpp::traits::input_parameter< double >::type r(rSEXP);
rcpp_result_gen = Rcpp::wrap(alongTrackDistance(lon1, lat1, lon2, lat2, plon, plat, r));
return rcpp_result_gen;
END_RCPP
}
// alongTrackDistance_rad
double alongTrackDistance_rad(double lon1, double lat1, double lon2, double lat2, double plon, double plat);
RcppExport SEXP _terra_alongTrackDistance_rad(SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP plonSEXP, SEXP platSEXP) {
double alongTrackDistance_rad(double lon1, double lat1, double lon2, double lat2, double plon, double plat, double r);
RcppExport SEXP _terra_alongTrackDistance_rad(SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP plonSEXP, SEXP platSEXP, SEXP rSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -486,7 +489,8 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< double >::type lat2(lat2SEXP);
Rcpp::traits::input_parameter< double >::type plon(plonSEXP);
Rcpp::traits::input_parameter< double >::type plat(platSEXP);
rcpp_result_gen = Rcpp::wrap(alongTrackDistance_rad(lon1, lat1, lon2, lat2, plon, plat));
Rcpp::traits::input_parameter< double >::type r(rSEXP);
rcpp_result_gen = Rcpp::wrap(alongTrackDistance_rad(lon1, lat1, lon2, lat2, plon, plat, r));
return rcpp_result_gen;
END_RCPP
}
Expand All @@ -507,8 +511,8 @@ BEGIN_RCPP
END_RCPP
}
// dist2segment_cosine_rad
double dist2segment_cosine_rad(double plon, double plat, double lon1, double lat1, double lon2, double lat2);
RcppExport SEXP _terra_dist2segment_cosine_rad(SEXP plonSEXP, SEXP platSEXP, SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP) {
double dist2segment_cosine_rad(double plon, double plat, double lon1, double lat1, double lon2, double lat2, double r);
RcppExport SEXP _terra_dist2segment_cosine_rad(SEXP plonSEXP, SEXP platSEXP, SEXP lon1SEXP, SEXP lat1SEXP, SEXP lon2SEXP, SEXP lat2SEXP, SEXP rSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -518,7 +522,8 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< double >::type lat1(lat1SEXP);
Rcpp::traits::input_parameter< double >::type lon2(lon2SEXP);
Rcpp::traits::input_parameter< double >::type lat2(lat2SEXP);
rcpp_result_gen = Rcpp::wrap(dist2segment_cosine_rad(plon, plat, lon1, lat1, lon2, lat2));
Rcpp::traits::input_parameter< double >::type r(rSEXP);
rcpp_result_gen = Rcpp::wrap(dist2segment_cosine_rad(plon, plat, lon1, lat1, lon2, lat2, r));
return rcpp_result_gen;
END_RCPP
}
Expand Down Expand Up @@ -595,12 +600,12 @@ static const R_CallMethodDef CallEntries[] = {
{"_terra_dest_lonlat", (DL_FUNC) &_terra_dest_lonlat, 7},
{"_terra_dir_lonlat", (DL_FUNC) &_terra_dir_lonlat, 4},
{"_terra_dir_rad", (DL_FUNC) &_terra_dir_rad, 4},
{"_terra_dist2track", (DL_FUNC) &_terra_dist2track, 7},
{"_terra_dist2track_cosine_rad", (DL_FUNC) &_terra_dist2track_cosine_rad, 7},
{"_terra_alongTrackDistance", (DL_FUNC) &_terra_alongTrackDistance, 6},
{"_terra_alongTrackDistance_rad", (DL_FUNC) &_terra_alongTrackDistance_rad, 6},
{"_terra_dist2track", (DL_FUNC) &_terra_dist2track, 8},
{"_terra_dist2track_cosine_rad", (DL_FUNC) &_terra_dist2track_cosine_rad, 8},
{"_terra_alongTrackDistance", (DL_FUNC) &_terra_alongTrackDistance, 7},
{"_terra_alongTrackDistance_rad", (DL_FUNC) &_terra_alongTrackDistance_rad, 7},
{"_terra_dist2segment", (DL_FUNC) &_terra_dist2segment, 6},
{"_terra_dist2segment_cosine_rad", (DL_FUNC) &_terra_dist2segment_cosine_rad, 6},
{"_terra_dist2segment_cosine_rad", (DL_FUNC) &_terra_dist2segment_cosine_rad, 7},
{"_terra_dist2segmentPoint", (DL_FUNC) &_terra_dist2segmentPoint, 8},
{"_terra_intermediate", (DL_FUNC) &_terra_intermediate, 6},
{"_rcpp_module_boot_spat", (DL_FUNC) &_rcpp_module_boot_spat, 0},
Expand Down
1 change: 1 addition & 0 deletions src/RcppModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ RCPP_MODULE(spat){
.method("intersect", &SpatVector::intersect)
.method("delaunay", &SpatVector::delaunay)
.method("voronoi", &SpatVector::voronoi)
.method("voronoi_sphere", &SpatVector::voronoi_sphere)
.method("hull", &SpatVector::hull)

.method("width", &SpatVector::width)
Expand Down
6 changes: 3 additions & 3 deletions src/distRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,14 +1013,14 @@ std::vector<double> SpatVector::distance(SpatVector x, bool pairwise, std::strin

if (lonlat) {
if (xtype == "points") {
return linedistLonLat(x);
return linedistLonLat(x, unit);
} else if (gtype == "points") {
return x.linedistLonLat(*this);
return x.linedistLonLat(*this, unit);
} else {
// not good enough
// need fixing
SpatVector tmp = x.as_points(false, true);
return x.linedistLonLat(tmp);
return x.linedistLonLat(tmp, unit);
}
}

Expand Down
Loading

0 comments on commit e4d5eb8

Please sign in to comment.