Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warping fails in tmap4 #1002

Open
Nowosad opened this issue Dec 25, 2024 · 2 comments
Open

warping fails in tmap4 #1002

Nowosad opened this issue Dec 25, 2024 · 2 comments
Labels
compat v3 to v4 transition

Comments

@Nowosad
Copy link
Member

Nowosad commented Dec 25, 2024

I know that the raster.warp argument is removed in tmap4. However, it seems not ideal that the current version of tmap cannot warp a raster that the previous version was able to do:

library(tmap)
data("land")

elev = land[4]
tm_shape(elev) +
  tm_raster()
#> [scale] tm_raster:() the data variable assigned to 'col' contains positive and negative values, so midpoint is set to 0. Set 'midpoint = NA' in 'fill.scale = tm_scale_intervals(<HERE>)' to use all visual values (e.g. colors)

# in tmap3 -- this would apply raster warping
tm_shape(elev, crs = "EPSG:8857") +
  tm_raster()
#> Warning: Unable to warp stars. Stars will be transformed now (which will take
#> some time).
#> [scale] tm_raster:() the data variable assigned to 'col' contains positive and negative values, so midpoint is set to 0. Set 'midpoint = NA' in 'fill.scale = tm_scale_intervals(<HERE>)' to use all visual values (e.g. colors)

# in tmap3 -- this would result in a curvilinear raster
tm_shape(elev, crs = "EPSG:8857", raster.warp = FALSE) +
  tm_raster()
#> Warning: Unable to warp stars. Stars will be transformed now (which will take
#> some time).
#> [scale] tm_raster:() the data variable assigned to 'col' contains positive and negative values, so midpoint is set to 0. Set 'midpoint = NA' in 'fill.scale = tm_scale_intervals(<HERE>)' to use all visual values (e.g. colors)

Related issue: #789

@Nowosad Nowosad added the compat v3 to v4 transition label Dec 25, 2024
mtennekes added a commit that referenced this issue Dec 27, 2024
@mtennekes
Copy link
Member

Yesterday, I've reset the crs of land to 4326. It also was that crs, but with a different specification.
Now it the warping works (although I'm not sure if that was the cause). So please check.

I don't recall the exact arguments why raster.wrap has been dropped (have to look up), but I guess it is superfluous because warping is always preferable, and as fallback, a transformation is applied.

@Nowosad
Copy link
Member Author

Nowosad commented Jan 4, 2025

The issue is still there. I would not have thought that sf::sf_use_s2 impacts st_warp, but it seems to be the case (see the reprex below).

@edzer -- is this expected?

library(tmap)
data("land")

elev = land[4]
tm_shape(elev) +
  tm_raster()

tm_shape(elev, crs = "EPSG:8857") +
  tm_raster()
#> Warning: Unable to warp stars. Stars will be transformed now (which will take
#> some time).

library(sf)
#> Linking to GEOS 3.12.2, GDAL 3.9.3, PROJ 9.4.1; sf_use_s2() is TRUE
library(stars)
#> Loading required package: abind

# works (to curvilinear)
elev2 = st_transform(elev, "EPSG:8857")

# fails
elev3 = st_warp(elev, crs = "EPSG:8857")
#> Error: argument dfMaxLength should be positive

# works
sf_use_s2(FALSE)
#> Spherical geometry (s2) switched off
elev3 = st_warp(elev, crs = "EPSG:8857")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat v3 to v4 transition
Projects
None yet
Development

No branches or pull requests

2 participants