`distance_map()` does not preserve CRS when using polygonal boundaries.
library(mapMCDA)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
vertex_coords <- matrix(c(0,0, 10,0, 10,10, 0,10, 0,0), ncol = 2, byrow = TRUE)
bnd <- st_sfc(st_polygon(list(vertex_coords)), crs = st_crs(4326))
polyA <- st_polygon(list(cbind(c(1, 2, 2, 1, 1), c(1, 1, 2, 2, 1))))
polyB <- st_polygon(list(cbind(c(5, 6, 6, 5, 5), c(3, 3, 4, 4, 3))))
plg2 <- st_sfc(list(polyA, polyB), crs = st_crs(4326))
plg2_proj <- st_transform(plg2, crs = st_crs(7832))
bnd_proj <- st_transform(bnd, crs = st_crs(7832))
ans <- distance_map(plg2_proj, bnd_proj)
#> |---------|---------|---------|---------|=========================================
stopifnot(st_crs(ans) == st_crs(plg2_proj))
#> Error: st_crs(ans) == st_crs(plg2_proj) is not TRUE
st_crs(plg2_proj)
#> Coordinate Reference System:
#> User input: EPSG:7832
#> wkt:
#> VERTCRS["POM96 height",
#> VDATUM["Port Moresby 1996"],
#> CS[vertical,1],
#> AXIS["gravity-related height (H)",up,
#> LENGTHUNIT["metre",1]],
#> USAGE[
#> SCOPE["Engineering survey."],
#> AREA["Papua New Guinea - onshore - Gulf province east of 144°24'E, Central province and National Capital District."],
#> BBOX[-10.42,144.4,-6.67,149.67]],
#> ID["EPSG",7832]]
st_crs(ans)
#> Coordinate Reference System:
#> User input: WGS 84
#> wkt:
#> GEOGCRS["WGS 84",
#> DATUM["World Geodetic System 1984",
#> ELLIPSOID["WGS 84",6378137,298.257223563,
#> LENGTHUNIT["metre",1]],
#> ID["EPSG",6326]],
#> PRIMEM["Greenwich",0,
#> ANGLEUNIT["degree",0.0174532925199433],
#> ID["EPSG",8901]],
#> CS[ellipsoidal,2],
#> AXIS["longitude",east,
#> ORDER[1],
#> ANGLEUNIT["degree",0.0174532925199433,
#> ID["EPSG",9122]]],
#> AXIS["latitude",north,
#> ORDER[2],
#> ANGLEUNIT["degree",0.0174532925199433,
#> ID["EPSG",9122]]]]
Created on 2024-01-29 with reprex v2.1.0