Shape file maps with Leaflet

Hi @sirox84,

sorry for the delay; life happened.

On second thought I do not recommend online mapshaper, but the R package {rmapshaper} which is very much the same thing.

By applying rmapshaper::ms_simplify() I was able to reduce the rendering time significantly (to about 1/8 of the original) while maintaining the structure of the shapefile (i.e. retaining the keys for linking your data items).

Still slow, but might make the difference between bearably and unbearably slow...

library(leaflet)
library(tictoc)
library(sf)

borders <- readRDS(url("https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_BRA_2_sf.rds"))

# this is the fun part!
simple_borders <- rmapshaper::ms_simplify(borders, keep = 0.01,
                                          keep_shapes = TRUE)

tictoc::tic()

leaflet(data = simple_borders) %>% 
  addProviderTiles("Stamen.Toner") %>% 
  addPolygons(fill = NA,
              color = "red")

tictoc::toc() 
0.896 sec elapsed
1 Like