bfastSpatial icon indicating copy to clipboard operation
bfastSpatial copied to clipboard

Read directly from tar archive in pre-processing functions

Open loicdtx opened this issue 10 years ago • 8 comments

library(rgdal)
library(raster)
raster('/vsitar//full/path/to/archive.tar.gz/bandName.tif')

Works on linux, don't know about windows

loicdtx avatar Jul 22 '15 12:07 loicdtx

@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

loicdtx avatar Dec 06 '15 16:12 loicdtx

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?

bendv avatar Dec 06 '15 16:12 bendv

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?

loicdtx avatar Dec 06 '15 16:12 loicdtx

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.

bendv avatar Dec 07 '15 08:12 bendv

I see. Then you probably have to escape the two first slashes, surrounding vsizip. \/vsizip\/ or something like that should work.

loicdtx avatar Dec 07 '15 09:12 loicdtx

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"

janverbesselt avatar Dec 07 '15 10:12 janverbesselt

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.

bendv avatar Dec 07 '15 11:12 bendv

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'))

loicdtx avatar Dec 07 '15 11:12 loicdtx