Edit: ignore this first block, it's a mistake. See here for my better example. I think this works already on Windows rgdal-CRAN binary, so that's great. I'll use travis to find out if it works on OSX.
http://rpubs.com/cyclemumner/358029
The conversation started here: https://stat.ethz.ch/pipermail/r-sig-geo/2018-February/026328.html
END EDIT 2018-02-09
library(raster)
yesterday <- Sys.Date() - 1
TileLevel <- 3
xml_specification <-
paste0('<GDAL_WMS>
<Service name="TMS">
<ServerUrl>
https://gibs.earthdata.nasa.gov/wmts/epsg3413/best/MODIS_Aqua_CorrectedReflectance_Bands721/default/
',
format(yesterday, "%Y-%m-%d"),
'/250m/${z}/${y}/${x}.jpg</ServerUrl>
</Service>
<DataWindow>
<UpperLeftX>-4194304</UpperLeftX>
<UpperLeftY>4194304</UpperLeftY>
<LowerRightX>4194304</LowerRightX>
<LowerRightY>-4194304</LowerRightY>
<TileLevel>', TileLevel, '</TileLevel>
<TileCountX>2</TileCountX>
<TileCountY>2</TileCountY>
<YOrigin>top</YOrigin>
</DataWindow>
<Projection>EPSG:3413</Projection>
<BlockSizeX>512</BlockSizeX>
<BlockSizeY>512</BlockSizeY>
<BandsCount>3</BandsCount>
</GDAL_WMS>
')
## raster is *lazy* here, we only get metadata
rastersource <- raster(xml_specification)
localproj <- projection(rastersource)
llproj <- "+init=epsg:4326"
local_ex <- projectExtent(raster(extent(c(-135, 170), c(52, 75)),
crs = llproj), localproj)
x <- crop(rastersource, extent(local_ex))
Error in rgdal::getRasterData(con, offset = offs, region.dim = reg, band = object@data@band) : Failure during raster IO
sessionInfo() R version 3.4.3 (2017-11-30) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux buster/sid
Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_AU.UTF-8 LC_COLLATE=en_AU.UTF-8
[5] LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8
[7] LC_PAPER=en_AU.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages: [1] raster_2.6-7 sp_1.2-7 devtools_1.13.4
loaded via a namespace (and not attached):
[1] compiler_3.4.3 rgdal_1.2-16 tools_3.4.3 withr_2.1.1
[5] yaml_2.1.16 Rcpp_0.12.15 memoise_1.1.0 grid_3.4.3
[9] digest_0.6.15 lattice_0.20-35
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] maptools_0.9-2 raster_2.6-7 rgdal_1.2-16 sp_1.2-7
loaded via a namespace (and not attached):
[1] compiler_3.4.3 foreign_0.8-69 Rcpp_0.12.14 grid_3.4.3 lattice_0.20-35
I get this error on the raster function call.