3

I am trying to get a map in the Dutch Rijksdriehoekstelsel coordinates in a Leaflet map in R that is going in a Shiny app later. I am going to have to add polygons later, and changing their X and Y coordinates into the WGS84 would be horrible. I stole the proj4def and resolutions from the example posted at the bottom. However, I just get a grey screen with the zoom in and out buttons. Either I have screwed up the leafletOptions or the tileLayer.

library(leaflet)

leaflet(
 options =
    leafletOptions(
      crs=leafletCRS(
        crsClass="L.Proj.CRS.TMS",
        code='EPSG:28992',
        proj4def='+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812 +no_defs',
  c(-285401.92, 22598.08, 595401.9199999999, 903401.9199999999),
    resolutions = c(3440.640, 1720.320, 860.160, 430.080, 215.040, 107.520, 53.760, 26.880, 13.440, 6.720, 3.360, 1.680, 0.840, 0.420),
      )
  )) %>%
  addTiles(urlTemplate='http://geodata.nationaalgeoregister.nl/tms/1.0.0/brtachtergrondkaart/{z}/{x}/{y}.png', 
  tileOptions(minZoom=3,maxZoom=13,tms=TRUE,continuousWorld=TRUE)   ) %>%
  setView(52,5.1,13)

This is an example in Javascript that has done the same thing: http://bl.ocks.org/webmappergists/raw/1ceac1353920b3810486/

  • deleting the transformation between proj4def and resolutions also changes nothing. – DS501 Apr 17 '17 at 21:10
3

First of all, the map is gray because you mixed up the coordinates. Just change the view from setView(52,5.1,13) to setView(5.1,52,13) and the map should render. It will be wrong though.

You had a few errors in your code. First you forgot to define the projectedBounds. You just added the vector without defining or doing anything whith it. It should look something like this:

projectedBounds = c(-285401.92, 22598.08, 595401.9199999999, 903401.9199999999))

So the entire crs should look like this:

minZoom = 0
maxZoom = 13
resolutions <- 0.42*(2^(maxZoom:minZoom))

epsg28992 <- leafletCRS(crsClass = 'L.Proj.CRS.TMS', code = 'EPSG:28992',
                       proj4def = '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725 +units=m +no_defs',
                       resolutions = resolutions,
                       projectedBounds = c(-285401.92, 22598.08, 595401.9199999999, 903401.9199999999))

Then you just have to add the tiles, set the view and you're done.

Entire code:

library(leaflet)

minZoom = 0
maxZoom = 13
resolutions <- 0.42*(2^(maxZoom:minZoom))

epsg28992 <- leafletCRS(crsClass = 'L.Proj.CRS.TMS', code = 'EPSG:28992',
                       proj4def = '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725 +units=m +no_defs',
                       resolutions = resolutions,
                       projectedBounds = c(-285401.92, 22598.08, 595401.9199999999, 903401.9199999999))

leaflet(options = leafletOptions(
                                  crs = epsg28992, 
                                  minZoom = minZoom, maxZoom = maxZoom)) %>%
  setView(5.092098, 52.093992, zoom = 4) %>%
  addTiles('http://geodata.nationaalgeoregister.nl/tms/1.0.0/brtachtergrondkaart/{z}/{x}/{y}.png', options = tileOptions(tms=TRUE))

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.