2

I'm trying to create an R Shiny map using the leaflet package to display input layers in the Plate Carree projection rather than the default Spherical Mercator projection. I've input OSM and WMS tile layers in EPSG 4326 but the OSM and other layers do not overlay (see attached image).

Based on the setView coordinates the OSM map would seem to be correct, and the problem lies with the NASA GIBS data layers?

enter image description here

library(shiny)
library(shinydashboard)
library(shinyjs)
library(shinyBS)
library(leaflet)
library(magrittr)
library(leaflet.extras)
...

srtmTilesURL <- "https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/SRTM_Color_Index/default/31.25m/{z}/{y}/{x}.png"
astergTilesURL <- "https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/ASTER_GDEM_Greyscale_Shaded_Relief/default/31.25m/{z}/{y}/{x}.jpeg"
astercolTilesURL <- "https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/ASTER_GDEM_Color_Shaded_Relief/default/31.25m/{z}/{y}/{x}.jpeg"


server <- function(input, output, session) {
  output$map <- renderLeaflet({
    crs4326 <-  leafletCRS(
      crsClass = "L.CRS.EPSG4326")
    leaflet(options= leafletOptions(crs=crs4326)) %>% 
    setView(lng = 110, lat = 9, zoom = 4) %>%
    addWMSTiles("http://129.206.228.72/cached/osm/service?",
               options = WMSTileOptions(format = "image/png", transparent = TRUE),
               group = "OSM (default)",
               layers = "osm_auto:all",
               layerId = "OSM WMS - osm-wms.de",
               attribution = "<a href='https://openstreetmap.org'></a>") %>%
    #addProviderTiles(providers$Stamen.Toner, group = "Toner") %>%
    #addProviderTiles(providers$Stamen.TerrainBackground, group ="Terrain Background") %>%
    addTiles(urlTemplate = srtmTilesURL,
             options = tileOptions(noWrap = TRUE, continuousWorld = TRUE, tms = FALSE, opacity = 1, tileSize =256),
             group = "SRTM DEM (col)", 
             layerId = "SRTM_Color_Index", 
             attribution = "<a href='https://earthdata.nasa.gov/gibs'></a>") %>%
    addTiles(urlTemplate = astergTilesURL,
             options = tileOptions(noWrap = TRUE, continuousWorld = TRUE, tms = FALSE, opacity = 1, tileSize =256),
             group = "ASTER DEM (grey)", 
             layerId = "ASTER_GDEM_Greyscale_Shaded_Relief") %>%
    addTiles(urlTemplate = astercolTilesURL,
             options = tileOptions(noWrap = TRUE, continuousWorld = TRUE, tms = FALSE, opacity = 1, tileSize =256),
             group = "ASTER DEM (col)",
             layerId = "ASTER_GDEM_Color_Shaded_Relief") %>%
    addLayersControl(
      baseGroups = c("OSM 4326", "SRTM DEM (col)", "ASTER DEM (grey)", "ASTER DEM (col)"), options = layersControlOptions(collapsed = TRUE)) 
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.