tests/testthat/test-expand.R

test_that("Expand factor", {
  img <- system.file("img/UK_flag.png", package = "rasterpic")
  x <- sf::st_read(system.file("gpkg/austria.gpkg", package = "rasterpic"),
    quiet = TRUE
  )

  x0 <- rasterpic_img(x, img, expand = 0)
  x_5 <- rasterpic_img(x, img, expand = 0.5)
  x1 <- rasterpic_img(x, img, expand = 1)

  # Asp ratios
  expect_equal(asp_ratio(x0), asp_ratio(x_5))
  expect_equal(asp_ratio(x0), asp_ratio(x1))

  # Check bboxes
  bbox_x <- as.double(sf::st_bbox(x))
  bbox_x0 <- unname(as.vector(terra::ext(x0)))
  expect_equal(bbox_x[c(2, 4)], bbox_x0[c(3, 4)])
  expect_true(bbox_x[1] > bbox_x0[1])
  expect_true(bbox_x[3] < bbox_x0[2])

  bbox_x_5 <- unname(as.vector(terra::ext(x_5)))
  expect_true(
    all(
      c(
        bbox_x[c(1, 3)] > bbox_x_5[c(1, 3)],
        bbox_x[c(2, 4)] < bbox_x_5[c(2, 4)]
      )
    )
  )

  bbox_x1 <- unname(as.vector(terra::ext(x1)))
  expect_true(
    all(
      c(
        bbox_x_5[c(1, 3)] > bbox_x1[c(1, 3)],
        bbox_x_5[c(2, 4)] < bbox_x1[c(2, 4)]
      )
    )
  )
})

Try the rasterpic package in your browser

Any scripts or data that you put into this service are public.

rasterpic documentation built on Sept. 8, 2023, 5:54 p.m.