as_array

Convert a data cube to an in-memory R array

Description

Convert a data cube to an in-memory R array

Usage

as_array(x)

Arguments

Argument Description
x data cube

Value

Four dimensional array with dimensions band, t, y, x

Note

Depending on the data cube size, this function may require substantial amounts of main memory, i.e. it makes sense for small data cubes only.

Examples

# create image collection from example Landsat data only 
# if not already done in other examples
if (!file.exists(file.path(tempdir(), "L8.db"))) {
  L8_files <- list.files(system.file("L8NY18", package = "gdalcubes"),
                         ".TIF", recursive = TRUE, full.names = TRUE)
  create_image_collection(L8_files, "L8_L1TP", file.path(tempdir(), "L8.db"), quiet = TRUE) 
}

L8.col = image_collection(file.path(tempdir(), "L8.db"))
v = cube_view(extent=list(left=388941.2, right=766552.4, 
              bottom=4345299, top=4744931, t0="2018-04", t1="2018-05"),
              srs="EPSG:32618", nx = 100, ny=100, dt="P1M")
x = as_array(select_bands(raster_cube(L8.col, v), c("B04", "B05")))
dim(x)
[1]   2   2 100 100
dimnames(x)
$bands
[1] "B04" "B05"

$t
[1] "2018-04-01" "2018-05-01"

$y
  [1] "4345299"    "4349295.32" "4353291.64" "4357287.96" "4361284.28"
  [6] "4365280.6"  "4369276.92" "4373273.24" "4377269.56" "4381265.88"
 [11] "4385262.2"  "4389258.52" "4393254.84" "4397251.16" "4401247.48"
 [16] "4405243.8"  "4409240.12" "4413236.44" "4417232.76" "4421229.08"
 [21] "4425225.4"  "4429221.72" "4433218.04" "4437214.36" "4441210.68"
 [26] "4445207"    "4449203.32" "4453199.64" "4457195.96" "4461192.28"
 [31] "4465188.6"  "4469184.92" "4473181.24" "4477177.56" "4481173.88"
 [36] "4485170.2"  "4489166.52" "4493162.84" "4497159.16" "4501155.48"
 [41] "4505151.8"  "4509148.12" "4513144.44" "4517140.76" "4521137.08"
 [46] "4525133.4"  "4529129.72" "4533126.04" "4537122.36" "4541118.68"
 [51] "4545115"    "4549111.32" "4553107.64" "4557103.96" "4561100.28"
 [56] "4565096.6"  "4569092.92" "4573089.24" "4577085.56" "4581081.88"
 [61] "4585078.2"  "4589074.52" "4593070.84" "4597067.16" "4601063.48"
 [66] "4605059.8"  "4609056.12" "4613052.44" "4617048.76" "4621045.08"
 [71] "4625041.4"  "4629037.72" "4633034.04" "4637030.36" "4641026.68"
 [76] "4645023"    "4649019.32" "4653015.64" "4657011.96" "4661008.28"
 [81] "4665004.6"  "4669000.92" "4672997.24" "4676993.56" "4680989.88"
 [86] "4684986.2"  "4688982.52" "4692978.84" "4696975.16" "4700971.48"
 [91] "4704967.8"  "4708964.12" "4712960.44" "4716956.76" "4720953.08"
 [96] "4724949.4"  "4728945.72" "4732942.04" "4736938.36" "4740934.68"

$x
  [1] "388941.2"   "392717.312" "396493.424" "400269.536" "404045.648"
  [6] "407821.76"  "411597.872" "415373.984" "419150.096" "422926.208"
 [11] "426702.32"  "430478.432" "434254.544" "438030.656" "441806.768"
 [16] "445582.88"  "449358.992" "453135.104" "456911.216" "460687.328"
 [21] "464463.44"  "468239.552" "472015.664" "475791.776" "479567.888"
 [26] "483344"     "487120.112" "490896.224" "494672.336" "498448.448"
 [31] "502224.56"  "506000.672" "509776.784" "513552.896" "517329.008"
 [36] "521105.12"  "524881.232" "528657.344" "532433.456" "536209.568"
 [41] "539985.68"  "543761.792" "547537.904" "551314.016" "555090.128"
 [46] "558866.24"  "562642.352" "566418.464" "570194.576" "573970.688"
 [51] "577746.8"   "581522.912" "585299.024" "589075.136" "592851.248"
 [56] "596627.36"  "600403.472" "604179.584" "607955.696" "611731.808"
 [61] "615507.92"  "619284.032" "623060.144" "626836.256" "630612.368"
 [66] "634388.48"  "638164.592" "641940.704" "645716.816" "649492.928"
 [71] "653269.04"  "657045.152" "660821.264" "664597.376" "668373.488"
 [76] "672149.6"   "675925.712" "679701.824" "683477.936" "687254.048"
 [81] "691030.16"  "694806.272" "698582.384" "702358.496" "706134.608"
 [86] "709910.72"  "713686.832" "717462.944" "721239.056" "725015.168"
 [91] "728791.28"  "732567.392" "736343.504" "740119.616" "743895.728"
 [96] "747671.84"  "751447.952" "755224.064" "759000.176" "762776.288"