Skip to content

Commit

Permalink
new RC 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Nov 2, 2023
1 parent b44409f commit 6bd0a5f
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 39 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: fasterize
Title: Fast Polygon to Raster Conversion
Version: 1.0.4.9002
Version: 1.0.5
Authors@R: c(
person("Noam", "Ross", , "[email protected]",
role = c("aut"),
Expand All @@ -20,15 +20,15 @@ Description: Provides a drop-in replacement for rasterize() from the 'raster'
License: MIT + file LICENSE
URL: https://github.com/ecohealthalliance/fasterize
BugReports: https://github.com/ecohealthalliance/fasterize/issues
RoxygenNote: 7.2.1
SystemRequirements: C++11
RoxygenNote: 7.2.3
Suggests:
testthat,
microbenchmark,
knitr,
rmarkdown,
sf,
spelling
spelling,
geos
Depends:
R (>= 3.3.0)
Imports:
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# fasterize dev
# fasterize 1.0.5

* Now supporting any geometry or dataframe input supported by wk (wkb, wkt, geos, as well as sf).

* Namespaced documentation fixes thanks to CRAN.

* Removed raster raster() method, not needed (raster handles sf now to obtain the 6 numbers and a string).

Expand Down
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

fasterize <- function(sf, raster, field = NULL, fun = "last", background = NA_real_, by = NULL) {
.Call('_fasterize_fasterize', PACKAGE = 'fasterize', sf, raster, field, fun, background, by)
fasterize_cpp <- function(sf, raster, field = NULL, fun = "last", background = NA_real_, by = NULL) {
.Call('_fasterize_fasterize_cpp', PACKAGE = 'fasterize', sf, raster, field, fun, background, by)
}

21 changes: 14 additions & 7 deletions R/fasterize.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

make_sf <- function(x, attr = NULL) {
structure(list(geom = x), names = c("geom"), row.names = seq_len(length(x)), sf_column = "geom", class = c("sf", "data.frame" ))
}


#' Rasterize an sf object of polygons
#'
#' Rasterize set of polygons
Expand Down Expand Up @@ -57,10 +59,15 @@ fasterize <- function(sf, raster, field = NULL, fun = "last", background = NA_re
## ok so we get geometry from anything wk can handle
geom <- wk::wk_handle(sf, wk::sfc_writer())

make_sf <- function(x, attr = NULL) {
structure(list(geom = x), names = c("geom"), row.names = seq_len(length(geom)), sf_column = "geom", class = c("sf", "data.frame" ))

sf1 <- make_sf(geom)
if (inherits(sf, "data.frame") && !is.null(field)) {
sf1[[field]] <- sf[[field]]
}
if (inherits(sf, "data.frame") && !is.null(by)) {
sf1[[by]] <- sf[[by]]
}
sf <- make_sf(geom)
.Call('_fasterize_fasterize', PACKAGE = 'fasterize', sf, raster, field, fun, background, by)

fasterize_cpp(sf1, raster, field, fun, background, by)
}

9 changes: 8 additions & 1 deletion R/package.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@

#' @keywords internal
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL

#' Fast sf-to-raster conversion
#'
#' Fast sf-to-raster conversion
#'
#' @docType package
#' @name fasterize
#' @name fasterize-package
NULL

#' @useDynLib fasterize
Expand Down
10 changes: 3 additions & 7 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
## R CMD check results

0 errors | 0 warnings | 0 notes
# fasterize 1.0.5

* Submitted by new maintainer, Michael Sumner ([email protected]), change from Noam Ross ([email protected]) as advised by email.

* Fixes CRAN warnings on bitwise operator and unused LazyData.

* Fixes implicit type warnings found with clang.
* Fixes for roxygen namespace documentation and remove specific C++11 requirement.



Thanks!
13 changes: 13 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,39 @@ GEOS
IUCN
LazyData
MULTIPOLYGON
Namespaced
ORCID
PROJ
RStudio
RasterBrick
Rasterize
Rcpp
USAID
Wconversion
al
cpp
devtools
doi
ecohealthalliance
edgelist
edu
et
funder
gcc
geos
https
md
ohi
rasterize
rasterized
rasterizing
rasters
respository
terra
toolchain
ucdavis
uword
vetmed
wkb
wkt
www
38 changes: 38 additions & 0 deletions man/fasterize-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions man/fasterize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// fasterize
Rcpp::S4 fasterize(Rcpp::DataFrame& sf, Rcpp::S4& raster, Rcpp::Nullable<std::string> field, std::string fun, double background, Rcpp::Nullable<std::string> by);
RcppExport SEXP _fasterize_fasterize(SEXP sfSEXP, SEXP rasterSEXP, SEXP fieldSEXP, SEXP funSEXP, SEXP backgroundSEXP, SEXP bySEXP) {
// fasterize_cpp
Rcpp::S4 fasterize_cpp(Rcpp::DataFrame& sf, Rcpp::S4& raster, Rcpp::Nullable<std::string> field, std::string fun, double background, Rcpp::Nullable<std::string> by);
RcppExport SEXP _fasterize_fasterize_cpp(SEXP sfSEXP, SEXP rasterSEXP, SEXP fieldSEXP, SEXP funSEXP, SEXP backgroundSEXP, SEXP bySEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -23,13 +23,13 @@ BEGIN_RCPP
Rcpp::traits::input_parameter< std::string >::type fun(funSEXP);
Rcpp::traits::input_parameter< double >::type background(backgroundSEXP);
Rcpp::traits::input_parameter< Rcpp::Nullable<std::string> >::type by(bySEXP);
rcpp_result_gen = Rcpp::wrap(fasterize(sf, raster, field, fun, background, by));
rcpp_result_gen = Rcpp::wrap(fasterize_cpp(sf, raster, field, fun, background, by));
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_fasterize_fasterize", (DL_FUNC) &_fasterize_fasterize, 6},
{"_fasterize_fasterize_cpp", (DL_FUNC) &_fasterize_fasterize_cpp, 6},
{NULL, NULL, 0}
};

Expand Down
2 changes: 1 addition & 1 deletion src/fasterize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// [[Rcpp::depends(RcppArmadillo)]]

// [[Rcpp::export]]
Rcpp::S4 fasterize(Rcpp::DataFrame &sf,
Rcpp::S4 fasterize_cpp(Rcpp::DataFrame &sf,
Rcpp::S4 &raster,
Rcpp::Nullable<std::string> field = R_NilValue,
std::string fun = "last",
Expand Down
25 changes: 25 additions & 0 deletions tests/spelling.Rout.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> if(requireNamespace('spelling', quietly = TRUE))
+ spelling::spell_check_test(vignettes = TRUE, error = FALSE,
+ skip_on_cran = TRUE)
All Done!
>
> proc.time()
user system elapsed
0.372 0.039 0.408
30 changes: 25 additions & 5 deletions tests/testthat/test-01-inputcheck.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

context("input checks")
suppressPackageStartupMessages(library(sf))
library(geos)
p1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20))
hole <- rbind(c(-150,-20), c(-100,-10), c(-110,20), c(-150,-20))
p1 <- list(p1, hole)
Expand All @@ -10,18 +11,37 @@ pols <- st_sf(value = c(1,2,3),
geometry = st_sfc(lapply(list(p1, p2, p3), st_polygon)))
r1 <- raster(pols, res=1)

test_that("fasterize needs class sf", {
pols_err <- pols
class(pols_err) <- "data.frame"
expect_error(fasterize(pols_err, r1), "sf must be of class sf")
})
## we now accept any wk-handled class
# test_that("fasterize needs class sf", {
# pols_err <- pols
# class(pols_err) <- "data.frame"
# expect_error(fasterize(pols_err, r1), "sf must be of class sf")
# })

test_that("fasterize likes wkt/wkb/geos", {
expect_s4_class(fasterize(wk::as_wkt(pols$geometry), r1), "BasicRaster")
expect_s4_class(fasterize(wk::as_wkb(pols$geometry), r1), "BasicRaster")
expect_s4_class(fasterize(geos::as_geos_geometry(pols$geometry), r1), "BasicRaster")
i <- seq_along(pols$geometry)
expect_s4_class(fasterize(data.frame(a = i, g = wk::as_wkt(pols$geometry)), r1), "BasicRaster")
expect_s4_class(fasterize(data.frame(a = i, wk::as_wkb(pols$geometry)), r1), "BasicRaster")
expect_s4_class(fasterize(data.frame(a = i, geos::as_geos_geometry(pols$geometry)), r1), "BasicRaster")


})
test_that("fasterize needs polygons", {
lines <- st_sf(value = c(1,2,3),
geometry = st_sfc(lapply(list(p1, p2, p3),
function(x) st_linestring(x[[1]]))))
expect_error(fasterize(lines, r1),
"sf geometry must be POLYGON or MULTIPOLYGON")

lines_wkb <- data.frame(value = c(1,2,3),
geometry = wk::as_wkb(sf::st_cast(pols$geometry, "MULTILINESTRING")))

expect_error(fasterize(lines_wkb, r1),
"geometry must be POLYGON or MULTIPOLYGON")

})

test_that("field value name is in sf object", {
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-02-fasterize.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test_that("raster sf method works", {
expect_s4_class(r, 'RasterLayer')
})


test_that("fasterize works", {
r <- raster(pols, res = 1)
expect_error(f <- fasterize(pols, r, field = "value", fun="sum"), NA)
Expand Down Expand Up @@ -73,6 +74,6 @@ test_that("error thrown for malformed polygon", {
pols_err <- pols
pols_err$geometry[[2]][[1]] <- as.character(pols_err$geometry[[2]][[1]])
expect_error(f <- fasterize(pols_err, r, field = "value", fun="sum"),
"incompatible SEXP; only accepts lists and REALSXPs")
"REAL\\() can only be applied to a 'numeric', not a 'character'")

})
2 changes: 1 addition & 1 deletion tests/testthat/test-05-by.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ r1 <- raster(pols, res=1)

test_that("'by' argument works", {
expect_error(
rb <-fasterize(pols, r1, field="value", fun="sum", by ="by_1"),NA)
rb <-fasterize(pols, r1, field="value", fun="sum", by ="by_1"), NA)
expect_equal(names(rb), unique(pols$by_1))
expect_equal(ncol(rb@data@values), length(unique(pols$by_1)))
})
Expand Down

0 comments on commit 6bd0a5f

Please sign in to comment.