inst/tinytest/test_utils.R

# load libs and data
suppressPackageStartupMessages(library(sf))
nc = st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

nc_sf = nc[1, ]
nc_sfc = st_geometry(nc_sf)
nc_sf_p = st_transform(nc_sf, "EPSG:3857")
nc_sfc_p = st_transform(nc_sfc, "EPSG:3857")
st_agr(nc_sf) = "constant"
ncp_sf = st_centroid(nc_sf)
ncp_sfc = st_geometry(ncp_sf)
ncp_sf_p = st_transform(ncp_sf, "EPSG:3857")
ncp_sfc_p = st_transform(ncp_sfc, "EPSG:3857")

ncl = st_cast(nc_sf, "MULTILINESTRING")

vec_b = c(182, 45)
vec_ok = c(10, 10)

other = "randown"

# zone_input() ----
expect_error(maposm:::zone_input(nc), 
             pattern = 'x must have 1 row or element.')
expect_error(maposm:::zone_input(vec_b))
expect_error(maposm:::zone_input(other), 
             pattern = 'x should be an sf or sfc object, or a couple of coordinates.')
expect_error(maposm:::zone_input(ncl))
expect_silent(maposm:::zone_input(nc_sf))
expect_silent(maposm:::zone_input(nc_sfc))
expect_silent(maposm:::zone_input(nc_sf_p))
expect_silent(maposm:::zone_input(nc_sfc_p))
expect_silent(maposm:::zone_input(ncp_sf, r = 100))
expect_silent(maposm:::zone_input(ncp_sfc, r = 100))
expect_silent(maposm:::zone_input(ncp_sf_p, r = 100))
expect_silent(maposm:::zone_input(ncp_sfc_p, r = 100))

# skip_dl() ----
expect_true(maposm:::skip_dl(x = c(-61.07, 14.605), r = 600))

# empty_sf() ----
expect_silent(maposm:::empty_sf(zone = nc_sf_p, type = "POINT"))
expect_silent({p = maposm:::empty_sf(zone = nc_sf_p, type = "POLYGON")})
expect_silent(maposm:::empty_sf(zone = nc_sf_p, type = "LINE"))
expect_equal(maposm:::empty_sf(x = nc_sf, zone = nc_sf_p, type = "POLYGON"), nc_sf)

# unify() ----
expect_equal(maposm:::unify(nc_sf_p, p), nc_sf_p)
expect_equal(maposm:::unify(p, p), p)
expect_equal(maposm:::unify(p, nc_sf_p), nc_sf_p)
expect_warning(maposm:::unify(nc_sf_p, nc_sf_p), 
               pattern = 'attribute variables are assumed to be spatially constant throughout all geometries' )

Try the maposm package in your browser

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

maposm documentation built on Sept. 17, 2026, 5:08 p.m.