Processing large vector data requires a way to tile the input data and mosaic the output. The following example only targets the tile creation and final mosaic step. Tiling the data has the reason that some processing steps might be CPU intensive or RAM exhausting if the entire data is processed. Processing steps between making tiles and mosaics are skipped and are not part of this question.

The following code creates polygons, tiles and a try to mosaic:

# create sample data
pts <- st_multipoint(matrix(c(10, 15, 15, 20, 20, 10, 20, 15), nrow = 4, byrow = TRUE), dim = "XY")
pts <- st_cast(st_geometry(pts), "POINT") 
pol <- st_buffer(pts, 3)

# create tiles
tiles <- getSpatialTiles(as(pol, "Spatial"), block.x=6, overlap.percent=10)
for (i in 1:length(tiles)) {
  tile <- st_crop(pol, st_as_sf(tiles[i]))
  st_write(tile, paste0("path/to/tile_", i, ".shp"))

plot(pol, col="green")
plot(tiles, add=TRUE)

enter image description here

# mosaic
file_list <- list.files("path/to/", pattern = "*shp", full.names = TRUE)
shapefile_list <- lapply(file_list, st_read) 
pol.union <- do.call(st_union, shapefile_list)

How to mosaic these tiles? I tryed several approaches (st_union, merge, st_join,...), but my best result yet does not remove the buffer and does not join parts of polygons into single polygons.

pol.union <- shapefile_list%>% 
  lapply(st_union) %>% 
  do.call(c, .)

enter image description here

btw.: if there are better ways to create tiles (without sp), a hint would be nice.

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.