Read directly from tar archive in pre-processing functions
library(rgdal)
library(raster)
raster('/vsitar//full/path/to/archive.tar.gz/bandName.tif')
Works on linux, don't know about windows
@bendv @johanez , can you check whether this works on Windows & Macs
library(bfastSpatial)
tarPath <- list.files(system.file('external', package='bfastSpatial'), full.names = TRUE)[1]
raster(sprintf('/vsizip/%s/%s', tarPath, 'LE70230282011250EDC00_sr_band1.tif'))
Thanks
This doesn't work on Windows. It reads the string in literally and returns a not recognised as a supported file format error. I can't check on my Mac, because I left it back in Canada, but perhaps @verbe039 could give it a try?
Okay, I was sort of expecting that... What does the string look like? Could you try replacing the forward slashes of tarPath by double backslashes?
It appends C:\vsizip to the full path of the filename, so in my case it looks something like C:\vsizip\D:\...\bfastSpatial\external\LE70230282011250EDC00_sub.zip\LE70230282011250EDC00_sr_band1.tif. So the problem is not with the slashes, because they are automatically replaced.
I see. Then you probably have to escape the two first slashes, surrounding vsizip. \/vsizip\/ or something like that should work.
on mac it does not complain (no error) but the string/path does not make sense:
> tarPath <- list.files(system.file('external', package='bfastSpatial'), full.names = TRUE)[1]
> raster(sprintf('/vsizip/%s/%s', tarPath, 'LE70230282011250EDC00_sr_band1.tif'))
class : RasterLayer
dimensions : 243, 258, 62694 (nrow, ncol, ncell)
resolution : 30, 30 (x, y)
extent : 498765, 506505, 5081145, 5088435 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=16 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : /vsizip//Users/verbe039/Library/R/3.2/library/bfastSpatial/external/LE70230282011250EDC00_sub.zip/LE70230282011250EDC00_sr_band1.tif
names : LE70230282011250EDC00_sr_band1
What is your objective with : ?
> sprintf('/vsizip/%s/%s', tarPath, 'LE70230282011250EDC00_sr_band1.tif')
[1] "/vsizip//Users/verbe039/Library/R/3.2/library/bfastSpatial/external/LE70230282011250EDC00_sub.zip/LE70230282011250EDC00_sr_band1.tif"
You can read in directly as a virtual file system. See https://trac.osgeo.org/gdal/wiki/UserDocs/ReadInZip
But it's not clear to me yet how this works in windows.
Did you try this Ben?
library(bfastSpatial)
tarPath <- list.files(system.file('external', package='bfastSpatial'), full.names = TRUE)[1]
raster(sprintf('\/vsizip\/%s/%s', tarPath, 'LE70230282011250EDC00_sr_band1.tif'))