Your raster-sp
workflow worked fine for me, not sure how you got 19 columns either. If it wasn't a typo, it might have been an rgdal
bug on write; that's the only related package that I can see a recent update for. Anyway here's a couple of examples with the newer sf
package:
library(sf)
# make an object the size and shape of the output you want
globe_bb <- matrix(c(-180, 90,
180, 90,
180, -90,
-180, -90,
-180, 90), byrow = TRUE, ncol = 2) %>%
list() %>%
st_polygon() %>%
st_sfc(., crs = 4326)
# generate grid of 20 x 10 tiles (200 in total, each 18 x 18 degrees)
globe_grid_18x18 <- st_make_grid(globe_bb, n = c(20, 10),
crs = 4326, what = 'polygons') %>%
st_sf('geometry' = ., data.frame('ID' = 1:length(.)))
# identical to the above:
globe_grid_18x18a <- st_make_grid(globe_bb, cellsize = c(18, 18),
crs = 4326, what = 'polygons') %>%
st_sf('geometry' = ., data.frame('ID' = 1:length(.)))
# you wanted this though, yes? Grid of 20 x 10 tiles (324 tiles, each 20 x 10 degrees)
globe_grid_20x10 <- st_make_grid(globe_bb, n = c(18, 18),
crs = 4326, what = 'polygons') %>%
st_sf('geometry' = ., data.frame('ID' = 1:length(.)))
# e.g. for checking in qgis
st_write(globe_grid_20x10, 'C:/DATA/globe_grid_20x10_sf.gpkg')
The st_sf()
step is optional, if you just want to write the grid directly to file.
Best Answer
This is quite simple you can use gdaltindex to build this grid.
In QGIS go to Raster -> Misc. -> Tile index. Give the path to the raster-files, set the name and directory for the resulting shape. I prefer absolute paths for catalogue purposes.
Then hit ok. :)