create_image_collection

Create an image collection from a set of GDAL datasets or files

Description

This function iterates over files or GDAL dataset identifiers and extracts datetime, image identifiers, and band information according to a given collection format.

Usage

create_image_collection(
  files,
  format = NULL,
  out_file = tempfile(fileext = ".sqlite"),
  date_time = NULL,
  band_names = NULL,
  use_subdatasets = FALSE,
  unroll_archives = TRUE,
  quiet = FALSE,
  one_band_per_file = NULL
)

Arguments

Argument Description
files character vector with paths to image files on disk or any GDAL dataset identifiers (including virtual file systems and higher level drivers or GDAL subdatasets)
format collection format, can be either a name to use predefined formats (as output from collection_formats) or a path to a custom JSON format description file
out_file optional name of the output SQLite database file, defaults to a temporary file
date_time vector with date/ time for files; can be of class character, Date, or POSIXct (argument is only applicable for image collections without collection format)
band_names character vector with band names, length must match the number of bands in provided files (argument is only applicable for image collections without collection format)
use_subdatasets logical; use GDAL subdatasets of provided files (argument is only applicable for image collections without collection format)
unroll_archives automatically convert .zip, .tar archives and .gz compressed files to GDAL virtual file system dataset identifiers (e.g. by prepending /vsizip/) and add contained files to the list of considered files
quiet logical; if TRUE, do not print resulting image collection if return value is not assigned to a variable
one_band_per_file logical; if TRUE, assume that band_names are given for all files (argument is only applicable for image collections without collection format, see Details)

Details

An image collection is a simple index (a SQLite database) containing references to existing image files / GDAL dataset identifiers.

Collections can be created in two different ways: First, if a collection format is specified (argument format), date/time, bands, and metadata are automatically extracted from provided files. This is the most general approach but requires a collection format for the specific dataset.

Second, image collections can sometimes be created without collection format by manually specifying date/time of images (argument date_time) and names of bands (argument band_names). This is possible if either each image file contains all bands of the collection or only a single band. In the former case band_names simply contains the names of the bands or can be NULL to use default names. In the latter case (image files contain a single band only), the lengths of band_names and date_time must be identical. By default, the function assumes one band per file if length(band_names) == length(files). In the unlikely situation that this is not desired, it can be explicitly set using one_band_per_file.

Value

image collection proxy object, which can be used to create a data cube using raster_cube

Examples

# 1. create image collection using a collection format 
L8_files <- list.files(system.file("L8NY18", package = "gdalcubes"),
                       ".TIF", recursive = TRUE, full.names = TRUE)
x = create_image_collection(L8_files, "L8_L1TP")
x 
Image collection object, referencing 19 images with 12 bands
Images:
                                      name      left      top   bottom
1 LC08_L1TP_013032_20180131_20180207_01_T1 -74.67898 41.39099 39.25027
2 LC08_L1TP_013032_20180405_20180417_01_T1 -74.70333 41.39106 39.25080
3 LC08_L1TP_013032_20180421_20180502_01_T1 -74.70681 41.39107 39.25098
4 LC08_L1TP_013032_20180710_20180717_01_T1 -74.66854 41.39096 39.24991
5 LC08_L1TP_013032_20180827_20180911_01_T1 -74.67202 41.39097 39.25000
6 LC08_L1TP_013032_20181030_20181115_01_T1 -74.69637 41.39104 39.25062
      right            datetime        srs
1 -71.92546 2018-01-31T00:00:00 EPSG:32618
2 -71.94695 2018-04-05T00:00:00 EPSG:32618
3 -71.95411 2018-04-21T00:00:00 EPSG:32618
4 -71.91114 2018-07-10T00:00:00 EPSG:32618
5 -71.91472 2018-08-27T00:00:00 EPSG:32618
6 -71.93979 2018-10-30T00:00:00 EPSG:32618
[ omitted 13 images ] 

Bands:
   name offset scale unit   nodata image_count
1   B01      0     1      0.000000          19
2   B02      0     1      0.000000          19
3   B03      0     1      0.000000          19
4   B04      0     1      0.000000          19
5   B05      0     1      0.000000          19
6   B06      0     1      0.000000          19
7   B07      0     1      0.000000          19
8   B08      0     1      0.000000          19
9   B09      0     1      0.000000          19
10  B10      0     1      0.000000          19
11  B11      0     1      0.000000          19
12  BQA      0     1                        19
# 2. create image collection without format for a single band
L8_files_B4 <- list.files(system.file("L8NY18", package = "gdalcubes"),
                       "_B4.TIF", recursive = TRUE, full.names = TRUE)
d = as.Date(substr(basename(L8_files_B4), 18, 25), "%Y%m%d")
y = create_image_collection(L8_files_B4, date_time = d, band_names = "B4")
y
Image collection object, referencing 19 images with 1 bands
Images:
                                                                                                                                       name
1 /home/marius/R/x86_64-pc-linux-gnu-library/4.3/gdalcubes/L8NY18/LC08_L1TP_013032_20180131_20180207_01_T1/LC08_L1TP_013032_20180131_B4.TIF
2 /home/marius/R/x86_64-pc-linux-gnu-library/4.3/gdalcubes/L8NY18/LC08_L1TP_013032_20180405_20180417_01_T1/LC08_L1TP_013032_20180405_B4.TIF
3 /home/marius/R/x86_64-pc-linux-gnu-library/4.3/gdalcubes/L8NY18/LC08_L1TP_013032_20180421_20180502_01_T1/LC08_L1TP_013032_20180421_B4.TIF
4 /home/marius/R/x86_64-pc-linux-gnu-library/4.3/gdalcubes/L8NY18/LC08_L1TP_013032_20180710_20180717_01_T1/LC08_L1TP_013032_20180710_B4.TIF
5 /home/marius/R/x86_64-pc-linux-gnu-library/4.3/gdalcubes/L8NY18/LC08_L1TP_013032_20180827_20180911_01_T1/LC08_L1TP_013032_20180827_B4.TIF
6 /home/marius/R/x86_64-pc-linux-gnu-library/4.3/gdalcubes/L8NY18/LC08_L1TP_013032_20181030_20181115_01_T1/LC08_L1TP_013032_20181030_B4.TIF
       left      top   bottom     right            datetime        srs
1 -74.67898 41.39099 39.25027 -71.92546 2018-01-31T00:00:00 EPSG:32618
2 -74.70333 41.39106 39.25080 -71.94695 2018-04-05T00:00:00 EPSG:32618
3 -74.70681 41.39107 39.25098 -71.95411 2018-04-21T00:00:00 EPSG:32618
4 -74.66854 41.39096 39.24991 -71.91114 2018-07-10T00:00:00 EPSG:32618
5 -74.67202 41.39097 39.25000 -71.91472 2018-08-27T00:00:00 EPSG:32618
6 -74.69637 41.39104 39.25062 -71.93979 2018-10-30T00:00:00 EPSG:32618
[ omitted 13 images ] 

Bands:
  name offset scale unit nodata image_count
1   B4      0     1                      19
# 3. create image collection without format for all bands
d = as.Date(substr(basename(L8_files), 18, 25), "%Y%m%d")
fname = basename(tools::file_path_sans_ext(L8_files))
b = substr(fname, 27, nchar(fname))
z = create_image_collection(L8_files, date_time = d, band_names = b)
z
Image collection object, referencing 228 images with 12 bands
Images:
                           name      left      top   bottom     right
1  LC08_L1TP_013032_20180131_B1 -74.67898 41.39099 39.25027 -71.92546
2 LC08_L1TP_013032_20180131_B10 -74.67898 41.39099 39.25027 -71.92546
3 LC08_L1TP_013032_20180131_B11 -74.67898 41.39099 39.25027 -71.92546
4  LC08_L1TP_013032_20180131_B2 -74.67898 41.39099 39.25027 -71.92546
5  LC08_L1TP_013032_20180131_B3 -74.67898 41.39099 39.25027 -71.92546
6  LC08_L1TP_013032_20180131_B4 -74.67898 41.39099 39.25027 -71.92546
             datetime        srs
1 2018-01-31T00:00:00 EPSG:32618
2 2018-01-31T00:00:00 EPSG:32618
3 2018-01-31T00:00:00 EPSG:32618
4 2018-01-31T00:00:00 EPSG:32618
5 2018-01-31T00:00:00 EPSG:32618
6 2018-01-31T00:00:00 EPSG:32618
[ omitted 222 images ] 

Bands:
   name offset scale unit nodata image_count
1    B1      0     1                      19
2   B10      0     1                      19
3   B11      0     1                      19
4    B2      0     1                      19
5    B3      0     1                      19
6    B4      0     1                      19
7    B5      0     1                      19
8    B6      0     1                      19
9    B7      0     1                      19
10   B8      0     1                      19
11   B9      0     1                      19
12  BQA      0     1                      19