tmap icon indicating copy to clipboard operation
tmap copied to clipboard

Horizontal graticules in an orthographic projection

Open rasmerla opened this issue 4 years ago • 2 comments

I'm working on orthographic projections of earth, but encounter unwanted horizontal lines when the map centre is beyond 45° east or west (depends also on the north/south angle). image

Reproducible code:

library(sf)
library(tmap)
sf::sf_use_s2(FALSE)

globe_grid_problem <- function(lat, lon) {
  # Define the orthographic projection
  # Choose lat_0 with -90 <= lat_0 <= 90 and lon_0 with -180 <= lon_0 <= 180
  ortho <- paste0('+proj=ortho +lat_0=',
      lat,
      ' +lon_0=',
      lon,
      ' +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs'
      )

  # Tog get something to plot, make a cirkle around the mid point:
  plot_point <- st_point(c(lon, lat)) %>%
    st_sfc(crs=4326) %>% # Project to WGS84
    st_as_sf() %>% 
    st_transform(crs = ortho) %>% # Transform to the custom projection
    st_buffer(6371000) # buffer to cover the world.

  #qtm(plot_point, projection = ortho)
  # Plot
  tm_shape(plot_point, projection = ortho) +
    tm_polygons(col = "grey") +
    tm_graticules() %>%
    return()
}

globe_grid_problem(45,45) # Works fine
globe_grid_problem(45,-160) # Does not work fine

P.S. Graticules do not work at all if s2 is TRUE. Should I report this?

rasmerla avatar Oct 11 '21 15:10 rasmerla

Good question. To be honest, fixing these graticules in tmap3 has low priority.

However, I'd plan to implement orthogonal maps in tmap4, along with the graticules. See also https://github.com/r-tmap/tmap/issues/457 and https://github.com/r-tmap/tmap/issues/564

mtennekes avatar Nov 01 '21 18:11 mtennekes

Re P.S. it worked on my machine with s2 enabled, so probably an update will fix that for you.

mtennekes avatar Nov 01 '21 18:11 mtennekes

The discussion can be continued at https://github.com/r-tmap/tmap/issues/457.

Nowosad avatar Sep 18 '23 08:09 Nowosad