-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed as not planned
Closed as not planned
Copy link
Labels
internals 🔎messagesrequests for improvements to error, warning, or feedback messagesrequests for improvements to error, warning, or feedback messages
Description
We are observing this test failure:
── Error ('test-coord_sf.R:290'): sf_transform_xy() works ──────────────────────
Error in `proj_from_crs(from)`: no arguments in initialization list: GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
USAGE[
SCOPE["unknown"],
AREA["World"],
BBOX[-90,-180,90,180]],
ID["EPSG",4326]]
Backtrace:
▆
1. └─ggplot2::sf_transform_xy(data, 3347, 4326) at test-coord_sf.R:290:2
2. └─sf::sf_project(...)
3. └─sf (local) proj_from_crs(from)
Probably this is related to missing certain GDAL drivers. But I hope you agree the error message is not very helpful. I'm not sure if this is something on the ggplot2 or the sf side; I know sf offers some things we could use to escape here e.g. sf_extSoftVersion()
or is_driver_available()
:
Happy to offer more details as needed but I'm not sure what would help.
FWIW, the issue also causes some examples to fail:
Lines 125 to 162 in 519bc83
if (require(maps)) { | |
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests) | |
# Equivalent to crimes \%>\% tidyr::pivot_longer(Murder:Rape) | |
vars <- lapply(names(crimes)[-1], function(j) { | |
data.frame(state = crimes$state, variable = j, value = crimes[[j]]) | |
}) | |
crimes_long <- do.call("rbind", vars) | |
states_map <- map_data("state") | |
# without geospatial coordinate system, the resulting plot | |
# looks weird | |
ggplot(crimes, aes(map_id = state)) + | |
geom_map(aes(fill = Murder), map = states_map) + | |
expand_limits(x = states_map$long, y = states_map$lat) | |
# in combination with `coord_sf()` we get an appropriate result | |
ggplot(crimes, aes(map_id = state)) + | |
geom_map(aes(fill = Murder), map = states_map) + | |
# crs = 5070 is a Conus Albers projection for North America, | |
# see: https://epsg.io/5070 | |
# default_crs = 4326 tells coord_sf() that the input map data | |
# are in longitude-latitude format | |
coord_sf( | |
crs = 5070, default_crs = 4326, | |
xlim = c(-125, -70), ylim = c(25, 52) | |
) | |
ggplot(crimes_long, aes(map_id = state)) + | |
geom_map(aes(fill = value), map = states_map) + | |
coord_sf( | |
crs = 5070, default_crs = 4326, | |
xlim = c(-125, -70), ylim = c(25, 52) | |
) + | |
facet_wrap(~variable) | |
} |
ggplot2/man/sf_transform_xy.Rd
Lines 27 to 43 in 519bc83
\examples{ | |
if (requireNamespace("sf", quietly = TRUE)) { | |
# location of cities in NC by long (x) and lat (y) | |
data <- data.frame( | |
city = c("Charlotte", "Raleigh", "Greensboro"), | |
x = c(-80.843, -78.639, -79.792), | |
y = c(35.227, 35.772, 36.073) | |
) | |
# transform to projected coordinates | |
data_proj <- sf_transform_xy(data, 3347, 4326) | |
data_proj | |
# transform back | |
sf_transform_xy(data_proj, 4326, 3347) | |
} | |
} |
Metadata
Metadata
Assignees
Labels
internals 🔎messagesrequests for improvements to error, warning, or feedback messagesrequests for improvements to error, warning, or feedback messages