Using leaflet() plotting ~10000 latitude longitude points. But using sf::st_union() is very slow.

I am plotting weather zones in leaflet map. With more than 10000 coordinates as circles which are joined using sf::st_union(). This process is very slow taking 5min or above to produce spatial objects.

Example of the code is

dataset #Main dataset containing LATITUDE, LONGITUDE and value(1 to 6) column

layer1 <- subset(dataset,value==1)
sf_layer1 <- st_as_sf(layer1, coords = c("LONGITUDE", "LATITUDE"))
sflayer1_circles <- st_buffer(sf_layer1, dist = 1.25)
sflayer1_combined <- st_union(sflayer1_circles) # Taking lots of time,Object being plotted in leaflet
layer1_sp <- as(sflayer1_combined, 'Spatial')  

# Done same for value=2,3,4,5,6 as layer(2,3,4,5,6)

leaflet() %>%
  addTiles() %>%

  addPolygons(data = sflayer1_combined,color="grey", stroke = FALSE, layerId = 1)%>%
  addPolygons(data = sflayer2_combined,color="yellow", stroke = FALSE, layerId = 2)%>%
   addPolygons(data = sflayer3_combined,color="red", stroke = FALSE, layerId = 3)%>%
  addPolygons(data = sflayer4_combined,color="purple", stroke = FALSE, layerId = 4)%>%
  addPolygons(data = sflayer5_combined,color="black", stroke = FALSE, layerId = 5)%>%
  addPolygons(data = sflayer6_combined,color="green", stroke = FALSE, layerId = 6)%>%

addCircleMarkers(data = layer1,lat = layer1$LATITUDE,lng = layer1$LONGITUDE,layerId = 1,popup = paste("LATITUDE=",layer1$LATITUDE,"<br>","LONGITUDE=",layer1$LONGITUDE,"<br>","value=",layer1$value),radius = 1,color = "grey")%>% #similar for other layers

The problem is with union taking lot of time. Is there any way to speed it up or any other faster substitute.

Thanking you for your time and concern.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.