From 19db58371dc37562a74f23830174da47c1e8b9b4 Mon Sep 17 00:00:00 2001 From: Robert+1-at-925791393128 Date: Thu, 18 Jul 2019 07:59:24 -0700 Subject: [PATCH] rc --- R/AAgeneric_functions.R | 1 + R/RcppExports.R | 4 ++-- R/freq.R | 4 ---- R/reclassify.R | 11 ++++++++-- src/RcppExports.cpp | 47 +++++++++++++++++++++-------------------- src/reclass.cpp | 7 +----- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/R/AAgeneric_functions.R b/R/AAgeneric_functions.R index bc1533fd..024a0bed 100644 --- a/R/AAgeneric_functions.R +++ b/R/AAgeneric_functions.R @@ -24,6 +24,7 @@ if (!isGeneric("extend")) {setGeneric("extend", function(x, y, ...) standardGene if (!isGeneric("extract")) { setGeneric("extract", function(x, y, ...) standardGeneric("extract"))} if (!isGeneric("flip")) { setGeneric("flip", function(x, direction, ...) standardGeneric("flip")) } if (!isGeneric("focal")) { setGeneric("focal", function(x, ...) standardGeneric("focal"))} +if (!isGeneric("freq")) {setGeneric("freq", function(x, ...) standardGeneric("freq"))} if (!isGeneric("geom")) { setGeneric("geom", function(x, ...) standardGeneric("geom"))} if (!isGeneric("gridDistance")) {setGeneric("gridDistance", function(x, ...) standardGeneric("gridDistance"))} if (!isGeneric("head")) { setGeneric("head", function(x, ...) standardGeneric("head"))} diff --git a/R/RcppExports.R b/R/RcppExports.R index fed7f6b1..d848f437 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -101,8 +101,8 @@ .Call(`_raster_dest_point`, xybd, lonlat, a, f) } -.reclassify <- function(d, rcl, dolowest, doright, NAonly, NAval) { - .Call(`_raster_reclassify`, d, rcl, dolowest, doright, NAonly, NAval) +.reclassify <- function(d, rcl, dolowest, doright, doleftright, NAonly, NAval) { + .Call(`_raster_reclassify`, d, rcl, dolowest, doright, doleftright, NAonly, NAval) } .terrain <- function(d, dim, res, unit, option, geo, gy) { diff --git a/R/freq.R b/R/freq.R index 04a36230..909bbea1 100644 --- a/R/freq.R +++ b/R/freq.R @@ -4,10 +4,6 @@ # Licence GPL v3 -if (!isGeneric("freq")) { - setGeneric("freq", function(x, ...) - standardGeneric("freq")) -} setMethod('freq', signature(x='RasterLayer'), diff --git a/R/reclassify.R b/R/reclassify.R index 4849ace9..8bf1acca 100644 --- a/R/reclassify.R +++ b/R/reclassify.R @@ -71,6 +71,12 @@ function(x, rcl, filename='', include.lowest=FALSE, right=TRUE, ...) { } names(out) <- names(x) include.lowest <- as.integer(include.lowest) + if (is.na(right)) { + leftright <- TRUE + right <- TRUE + } else { + leftright <- FALSE + } right <- as.integer(right) #hasNA <- as.integer(hasNA) onlyNA <- as.integer(onlyNA) @@ -80,8 +86,9 @@ function(x, rcl, filename='', include.lowest=FALSE, right=TRUE, ...) { rcl <- rcl[ , 2:3, drop=FALSE] } + if (canProcessInMemory(out)) { - out <- setValues(out, .reclassify(values(x), rcl, include.lowest, right, onlyNA, valNA)) + out <- setValues(out, .reclassify(values(x), rcl, include.lowest, right, leftright, onlyNA, valNA)) if ( filename != "" ) { out <- writeRaster(out, filename=filename, ...) } @@ -95,7 +102,7 @@ function(x, rcl, filename='', include.lowest=FALSE, right=TRUE, ...) { for (i in 1:tr$n) { vals <- getValues( x, row=tr$row[i], nrows=tr$nrows[i] ) - vals <- .reclassify(vals, rcl, include.lowest, right, onlyNA, valNA) + vals <- .reclassify(vals, rcl, include.lowest, right, leftright, onlyNA, valNA) if (nl > 1) { vals <- matrix(vals, ncol=nl) } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index a7b127b5..1bb744ad 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -244,25 +244,25 @@ BEGIN_RCPP END_RCPP } // aggregate_get -NumericMatrix aggregate_get(NumericMatrix d, NumericVector dims); +Rcpp::NumericMatrix aggregate_get(Rcpp::NumericMatrix d, Rcpp::NumericVector dims); RcppExport SEXP _raster_aggregate_get(SEXP dSEXP, SEXP dimsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< NumericMatrix >::type d(dSEXP); - Rcpp::traits::input_parameter< NumericVector >::type dims(dimsSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type d(dSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericVector >::type dims(dimsSEXP); rcpp_result_gen = Rcpp::wrap(aggregate_get(d, dims)); return rcpp_result_gen; END_RCPP } // aggregate_fun -NumericMatrix aggregate_fun(NumericMatrix d, NumericVector dims, bool narm, int fun); +Rcpp::NumericMatrix aggregate_fun(Rcpp::NumericMatrix d, Rcpp::NumericVector dims, bool narm, int fun); RcppExport SEXP _raster_aggregate_fun(SEXP dSEXP, SEXP dimsSEXP, SEXP narmSEXP, SEXP funSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< NumericMatrix >::type d(dSEXP); - Rcpp::traits::input_parameter< NumericVector >::type dims(dimsSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type d(dSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericVector >::type dims(dimsSEXP); Rcpp::traits::input_parameter< bool >::type narm(narmSEXP); Rcpp::traits::input_parameter< int >::type fun(funSEXP); rcpp_result_gen = Rcpp::wrap(aggregate_fun(d, dims, narm, fun)); @@ -270,25 +270,25 @@ BEGIN_RCPP END_RCPP } // get_area_polygon -NumericVector get_area_polygon(NumericMatrix d, bool lonlat); +Rcpp::NumericVector get_area_polygon(Rcpp::NumericMatrix d, bool lonlat); RcppExport SEXP _raster_get_area_polygon(SEXP dSEXP, SEXP lonlatSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< NumericMatrix >::type d(dSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type d(dSEXP); Rcpp::traits::input_parameter< bool >::type lonlat(lonlatSEXP); rcpp_result_gen = Rcpp::wrap(get_area_polygon(d, lonlat)); return rcpp_result_gen; END_RCPP } // point_distance -NumericVector point_distance(NumericMatrix p1, NumericMatrix p2, bool lonlat, double a, double f); +Rcpp::NumericVector point_distance(Rcpp::NumericMatrix p1, Rcpp::NumericMatrix p2, bool lonlat, double a, double f); RcppExport SEXP _raster_point_distance(SEXP p1SEXP, SEXP p2SEXP, SEXP lonlatSEXP, SEXP aSEXP, SEXP fSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< NumericMatrix >::type p1(p1SEXP); - Rcpp::traits::input_parameter< NumericMatrix >::type p2(p2SEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type p1(p1SEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type p2(p2SEXP); Rcpp::traits::input_parameter< bool >::type lonlat(lonlatSEXP); Rcpp::traits::input_parameter< double >::type a(aSEXP); Rcpp::traits::input_parameter< double >::type f(fSEXP); @@ -297,13 +297,13 @@ BEGIN_RCPP END_RCPP } // distanceToNearestPoint -NumericVector distanceToNearestPoint(NumericMatrix d, NumericMatrix p, bool lonlat, double a, double f); +Rcpp::NumericVector distanceToNearestPoint(Rcpp::NumericMatrix d, Rcpp::NumericMatrix p, bool lonlat, double a, double f); RcppExport SEXP _raster_distanceToNearestPoint(SEXP dSEXP, SEXP pSEXP, SEXP lonlatSEXP, SEXP aSEXP, SEXP fSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< NumericMatrix >::type d(dSEXP); - Rcpp::traits::input_parameter< NumericMatrix >::type p(pSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type d(dSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type p(pSEXP); Rcpp::traits::input_parameter< bool >::type lonlat(lonlatSEXP); Rcpp::traits::input_parameter< double >::type a(aSEXP); Rcpp::traits::input_parameter< double >::type f(fSEXP); @@ -312,13 +312,13 @@ BEGIN_RCPP END_RCPP } // directionToNearestPoint -NumericVector directionToNearestPoint(NumericMatrix d, NumericMatrix p, bool lonlat, bool degrees, bool from, double a, double f); +Rcpp::NumericVector directionToNearestPoint(Rcpp::NumericMatrix d, Rcpp::NumericMatrix p, bool lonlat, bool degrees, bool from, double a, double f); RcppExport SEXP _raster_directionToNearestPoint(SEXP dSEXP, SEXP pSEXP, SEXP lonlatSEXP, SEXP degreesSEXP, SEXP fromSEXP, SEXP aSEXP, SEXP fSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< NumericMatrix >::type d(dSEXP); - Rcpp::traits::input_parameter< NumericMatrix >::type p(pSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type d(dSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type p(pSEXP); Rcpp::traits::input_parameter< bool >::type lonlat(lonlatSEXP); Rcpp::traits::input_parameter< bool >::type degrees(degreesSEXP); Rcpp::traits::input_parameter< bool >::type from(fromSEXP); @@ -329,12 +329,12 @@ BEGIN_RCPP END_RCPP } // dest_point -NumericMatrix dest_point(NumericMatrix xybd, bool lonlat, double a, double f); +Rcpp::NumericMatrix dest_point(Rcpp::NumericMatrix xybd, bool lonlat, double a, double f); RcppExport SEXP _raster_dest_point(SEXP xybdSEXP, SEXP lonlatSEXP, SEXP aSEXP, SEXP fSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< NumericMatrix >::type xybd(xybdSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type xybd(xybdSEXP); Rcpp::traits::input_parameter< bool >::type lonlat(lonlatSEXP); Rcpp::traits::input_parameter< double >::type a(aSEXP); Rcpp::traits::input_parameter< double >::type f(fSEXP); @@ -343,8 +343,8 @@ BEGIN_RCPP END_RCPP } // reclassify -Rcpp::NumericVector reclassify(Rcpp::NumericVector d, Rcpp::NumericMatrix rcl, bool dolowest, bool doright, bool NAonly, double NAval); -RcppExport SEXP _raster_reclassify(SEXP dSEXP, SEXP rclSEXP, SEXP dolowestSEXP, SEXP dorightSEXP, SEXP NAonlySEXP, SEXP NAvalSEXP) { +Rcpp::NumericVector reclassify(Rcpp::NumericVector d, Rcpp::NumericMatrix rcl, bool dolowest, bool doright, bool doleftright, bool NAonly, double NAval); +RcppExport SEXP _raster_reclassify(SEXP dSEXP, SEXP rclSEXP, SEXP dolowestSEXP, SEXP dorightSEXP, SEXP doleftrightSEXP, SEXP NAonlySEXP, SEXP NAvalSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -352,9 +352,10 @@ BEGIN_RCPP Rcpp::traits::input_parameter< Rcpp::NumericMatrix >::type rcl(rclSEXP); Rcpp::traits::input_parameter< bool >::type dolowest(dolowestSEXP); Rcpp::traits::input_parameter< bool >::type doright(dorightSEXP); + Rcpp::traits::input_parameter< bool >::type doleftright(doleftrightSEXP); Rcpp::traits::input_parameter< bool >::type NAonly(NAonlySEXP); Rcpp::traits::input_parameter< double >::type NAval(NAvalSEXP); - rcpp_result_gen = Rcpp::wrap(reclassify(d, rcl, dolowest, doright, NAonly, NAval)); + rcpp_result_gen = Rcpp::wrap(reclassify(d, rcl, dolowest, doright, doleftright, NAonly, NAval)); return rcpp_result_gen; END_RCPP } @@ -458,7 +459,7 @@ static const R_CallMethodDef CallEntries[] = { {"_raster_distanceToNearestPoint", (DL_FUNC) &_raster_distanceToNearestPoint, 5}, {"_raster_directionToNearestPoint", (DL_FUNC) &_raster_directionToNearestPoint, 7}, {"_raster_dest_point", (DL_FUNC) &_raster_dest_point, 4}, - {"_raster_reclassify", (DL_FUNC) &_raster_reclassify, 6}, + {"_raster_reclassify", (DL_FUNC) &_raster_reclassify, 7}, {"_raster_do_terrains", (DL_FUNC) &_raster_do_terrains, 7}, {"_raster_doCellFromXY", (DL_FUNC) &_raster_doCellFromXY, 8}, {"_raster_doXYFromCell", (DL_FUNC) &_raster_doXYFromCell, 7}, diff --git a/src/reclass.cpp b/src/reclass.cpp index dbfb179b..1c7e5610 100644 --- a/src/reclass.cpp +++ b/src/reclass.cpp @@ -3,17 +3,12 @@ #include // [[Rcpp::export(name = ".reclassify")]] -Rcpp::NumericVector reclassify(Rcpp::NumericVector d, Rcpp::NumericMatrix rcl, bool dolowest, bool doright, bool NAonly, double NAval) { +Rcpp::NumericVector reclassify(Rcpp::NumericVector d, Rcpp::NumericMatrix rcl, bool dolowest, bool doright, bool doleftright, bool NAonly, double NAval) { double lowval, lowres; size_t a = rcl.nrow(); size_t nc = rcl.ncol(); size_t b = a * 2; - - bool doleftright = false; - if (std::isnan(doright)) { - doleftright = true; - } size_t n = d.size();