test_that("wk_transform() works", { geoms <- wkt( c( "POLYGON ((0 0, 0 1, 1 0, 0 0))", "POINT (0 0)", "POINT Z (0 0 0)", "POINT M (0 0 0)", "POINT ZM (0 0 0 0)", NA ) ) expect_identical( wk_transform(geoms, wk_affine_translate(1, 2)), wkt( c( "POLYGON ((1 2, 1 3, 2 2, 1 2))", "POINT (1 2)", "POINT Z (1 2 0)", "POINT M (1 2 0)", "POINT ZM (1 2 0 0)", NA ) ) ) # check error propagation expect_error(wk_transform(new_wk_wkt("POINT ENTPY"), wk_affine_identity()), "ENTPY") }) test_that("wk_transform_filter() errors when the recursion limit is too high", { make_really_recursive_geom <- function(n) { wkt(paste0( c(rep("GEOMETRYCOLLECTION (", n), "POINT (0 1)", rep(")", n)), collapse = "" )) } # errors in geometry_start expect_error( wk_handle( make_really_recursive_geom(32), wk_transform_filter(wk_void_handler(), wk_affine_identity()) ), "Too many recursive levels" ) }) test_that("wk_trans uses meta flags consistently", { # from paleolimbot/wk#216 # NOTE: using wk_trans_set() because it exposes use_z and use_m parameters # we could equivalently use wk_trans_explicit() expect_identical( wk_transform( xy(1, 1), wk_trans_set(xy(1, 1), use_z = TRUE) ), xyz(1, 1, NaN) ) expect_identical( wk_transform( xy(1, 1), wk_trans_set(xy(1, 1), use_m = TRUE) ), xym(1, 1, NaN) ) expect_identical( wk_transform( xy(1, 1), wk_trans_set(xy(1, 1), use_z = TRUE, use_m = TRUE) ), xyzm(1, 1, NaN, NaN) ) expect_identical( wk_transform( xym(1, 1, 1), wk_trans_set(xy(1, 1), use_z = TRUE) ), xyzm(1, 1, NaN, 1) ) expect_identical( wk_transform( xyz(1, 1, 1), wk_trans_set(xy(1, 1), use_m = TRUE) ), xyzm(1, 1, 1, NaN) ) expect_identical( wk_transform( xyzm(1, 1, 1, 1), wk_trans_set(xy(1, 1), use_z = TRUE) ), xyzm(1, 1, 1, 1) ) expect_identical( wk_transform( xyzm(1, 1, 1, 1), wk_trans_set(xy(1, 1), use_m = TRUE) ), xyzm(1, 1, 1, 1) ) expect_identical( wk_transform( xyzm(1, 1, 1, 1), wk_trans_set(xy(1, 1), use_z = TRUE, use_m = TRUE) ), xyzm(1, 1, 1, 1) ) })