0

I have a SpatialPolygonsDataFrame [https://drive.google.com/file/d/0B5amt_a1FFXyZkd6eXF0czlReGc/view?usp=sharing] which is not projected. The spatial coordinates are range(long) = c(5e10 ; 8e10) and range(lat) = c(1e7,3e7). I want to use the package leaflet to display the map using:

leaflet() %>%
  addProviderTiles("CartoDB.Positron") %>%
  addPolygons(data = polydf, 
              fillColor = ~pal(percent), 
              color = "#b2aeae"
              popup = popup)

However, I only get the CartoDB.Positron map, with no layer corresponding to the SpatialPolygonsDataFrame. I think that I have to change the coordinates. I tried to set a custom CRS and then transforming it and got some very distorted display on my map. I could not find how to obtain the correct reference system.

user34771
  • 455
  • 1
  • 4
  • 15
  • Can you add your polygon layer to your post. Without it, it will be hard to help you. – MLavoie Mar 18 '16 at 20:44
  • In the shapefile you posted a link to, the bounding box ranged from long -180 to 180 and lat 55 to 88. Can you provide the raw shapefile before you tried to transform it? –  Mar 18 '16 at 23:22
  • You can find the initial shapefile in the R package ggswissmaps. I spent a long time looking for coordinate systems and I finally found one that almost matches the map. It is the Swiss CRS `"+proj=somerc +lat_0=46.9524056 +lon_0=7.43958333 +ellps=bessel +x_0=600000 +y_0=200000 +towgs84=674.374,15.056,405.346+units=m +k_0=1 +no_defs"`, which I then reprojected in the WGS84. There is a very small shift remaining, but it is already pretty good. – user34771 Mar 18 '16 at 23:57
  • If you do not have to polygons from use the ggswissmaps package, you can use another data set from GADM. You can download data with the raster package like this: `getData('GADM', country='CH', level=1)`. – jazzurro Mar 19 '16 at 00:34
  • Thank you very much, very useful. I used the ggswissmaps data mainly because it contains the code of the Swiss cantonal areas, but I will have a look at GADM. – user34771 Mar 19 '16 at 08:58

0 Answers0