From 7cc6ed81287c0f447801b262c0cf300df134608b Mon Sep 17 00:00:00 2001 From: rhijmans Date: Thu, 9 Feb 2023 21:37:01 -0800 Subject: [PATCH] a --- src/rasterize.cpp | 51 +++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/rasterize.cpp b/src/rasterize.cpp index 7b8a37a3f..e68bacb81 100644 --- a/src/rasterize.cpp +++ b/src/rasterize.cpp @@ -66,16 +66,18 @@ SpatRaster SpatRaster::rasterizePoints(const std::vector&x, const std::v } if (!out.writeValues(v, out.bs.row[i], out.bs.nrows[i])) return out; } - } else if (fun == "sum") { + } else if (fun == "mean") { for (size_t i=0; i < out.bs.n; i++) { double cmin = out.bs.row[i] * nc; - double cmax = (out.bs.row[i]+out.bs.nrows[i]) * nc - 1; + double cmax = (out.bs.row[i]+out.bs.nrows[i]) * nc - 1; std::vector v(out.bs.nrows[i] * out.ncol(), 0); + std::vector cnt = v; for (size_t j=cellcnt; j&x, const std::v } if (background != 0) { for (size_t j=0; j 0) { + v[j] /= cnt[j]; + } + } + } + if (!out.writeValues(v, out.bs.row[i], out.bs.nrows[i])) return out; } - } else if (fun == "mean") { + } else if (fun == "sum") { for (size_t i=0; i < out.bs.n; i++) { double cmin = out.bs.row[i] * nc; double cmax = (out.bs.row[i]+out.bs.nrows[i]) * nc - 1; - std::vector v(out.bs.nrows[i] * out.ncol(), 0); - std::vector cnt = v; + std::vector v(out.bs.nrows[i] * out.ncol(), background); + std::vector newcell(out.bs.nrows[i] * out.ncol(), true); for (size_t j=cellcnt; j 0) { - v[j] /= cnt[j]; - } - } - if (background != 0) { - for (size_t j=0; j&x, const std::v double cmin = out.bs.row[i] * nc; double cmax = (out.bs.row[i]+out.bs.nrows[i]) * nc - 1; std::vector v(out.bs.nrows[i] * out.ncol(), background); - std::vector newcell(out.bs.nrows[i] * out.ncol(), true);; + std::vector newcell(out.bs.nrows[i] * out.ncol(), true); for (size_t j=cellcnt; j&x, const std::v double cmin = out.bs.row[i] * nc; double cmax = (out.bs.row[i]+out.bs.nrows[i]) * nc - 1; std::vector v(out.bs.nrows[i] * out.ncol(), background); - std::vector newcell(out.bs.nrows[i] * out.ncol(), true);; + std::vector newcell(out.bs.nrows[i] * out.ncol(), true); for (size_t j=cellcnt; j&x, const std::v double cmin = out.bs.row[i] * nc; double cmax = (out.bs.row[i]+out.bs.nrows[i]) * nc - 1; std::vector v(out.bs.nrows[i] * out.ncol(), background); - std::vector newcell(out.bs.nrows[i] * out.ncol(), true);; + std::vector newcell(out.bs.nrows[i] * out.ncol(), true); for (size_t j=cellcnt; j