1

I've downloaded a countries shapefile from Natural Earth, and used it to clip GLC2000 raster using Brazil's border as the mask (in R).

setwd('~/R/GLC2000')
library(rgdal)
library(raster)
glc <- raster('glc2000_v1_1')
pa <- readOGR('../shp/ne_10m_admin_0_countries','ne_10m_admin_0_countries')
p <- grep('Brazil',pa$ADMIN)
p1 <- crop(glc,extent(pa[p,]))
glcP <- mask(p1,pa[p,]) # dividing the mask in crop+mask makes it much faster
dim(glcP)
plot(glcP)
writeRaster(glcP,as.character(pa@data[p,'ISO_A3']),'GTiff')

dim(glcP) gives 4369 5056 1, which is big, but not absurdly big.

plot(glcP) gives the image below, which proves it worked as expected.

GLC2000 - Brazil

So why doesn't writeRaster complete its task, even hours after being issued?

I want to to this for every country in the world, that's why I'm trying to do it in R. It's easier for me than a script in, say, QGIS.

8
  • For comparison, using this answer to save it as PNG took about 3 seconds...
    – Rodrigo
    Apr 19, 2018 at 0:18
  • Is it in memory or on disk? ?raster::inMemory Write to a different physical disk, or readAll() first. Also this doesn't look like a good filename for a GeoTIFF, so I'd change that rather than rely on automatic settings, and I'd check what you are actually getting from that code for it
    – mdsumner
    Apr 19, 2018 at 4:07
  • Perhaps it is not slow but it does not work at all. Have you managed to complete the task with your script with any input geometry?
    – user30184
    Apr 19, 2018 at 5:58
  • Weird. Try cropping that raster to a smaller size and seeing how long that takes to write. If a 100x100 raster takes forever, something is seriously wrong...
    – Spacedman
    Apr 19, 2018 at 6:37
  • @Spacedman It worked fast with a 41x59 raster, though it painted the background, which is black on plot, with dark cyan (#009696)... Same for Haiti (319x232).
    – Rodrigo
    Apr 26, 2018 at 15:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.