windowed reading raster with stars

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

windowed reading raster with stars

Loïc Dutrieux-3
Hi everyone,

I have a large geoTiff raster file that does not fit in memory (if I do
read_stars(file_path) I get "Error: cannot allocate vector of size 12.7
Gb"). How can I read a spatial subset of that file.

The example below works with a toy example but not with the actual large
dataset.

library(stars)
library(sf)

tif = system.file("tif/L7_ETMs.tif", package = "stars")
window <- read_stars(tif) %>%
     st_bbox() %>%
     st_as_sfc() %>%
     st_buffer(-2000) %>%
     st_bbox()

tif_sub <- read_stars(tif, proxy = TRUE) %>%
     st_crop(window)

plot(tif_sub)

I get the following error:

Error in x[[i]][1:-21561856, 1:146, , drop = FALSE] :
   only 0's may be mixed with negative subscripts

Kind regards,
Loïc

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: windowed reading raster with stars

Loïc Dutrieux-3
Thanks Edzer,
I confirm that it's working now.

Kind regards,
Loïc

On 04/25/2020 07:05 PM, Edzer Pebesma wrote:

> See https://github.com/r-spatial/stars/issues/276
>
> should be fixed now.
>
> Thanks!
>
> On 4/25/20 6:06 PM, Loïc Dutrieux wrote:
>> Hi Edzer,
>>
>> Below an example that generates a raster with the exact same dimensions
>> and reproduces the "error". I did not manage to set raster values when
>> creating the artificial data though; it's too large to handle in memory.
>>
>> library(stars)
>> library(sf)
>> library(raster)
>>
>> file_path <- tempfile(pattern = "raster", fileext = ".tif")
>> e <- new("Extent", xmin = 15.470217297, xmax = 15.489599681, ymin =
>> 1.097371925, ymax = 1.111615391)
>> b <- brick(e, nrows=20349, ncols=27872, nl=3, crs=CRS('+proj=longlat'))
>>
>> writeRaster(b, filename = file_path, datatype='INT1U')
>>
>> window <- read_stars(file_path, proxy = TRUE) %>%
>>      st_bbox() %>%
>>      st_as_sfc() %>%
>>      st_buffer(-0.001) %>%
>>      st_bbox()
>>
>> tif_sub <- read_stars(file_path, proxy = TRUE) %>%
>>      st_crop(window)
>> plot(tif_sub)
>>
>> Kind regards,
>> Loïc
>>
>> On 04/25/2020 05:27 PM, Edzer Pebesma wrote:
>>> Hi Loïc,
>>>
>>> could you please make an example available somehow, possibly off-list?
>>>
>>> On 4/25/20 5:14 PM, Loïc Dutrieux wrote:
>>>> Hi everyone,
>>>>
>>>> I have a large geoTiff raster file that does not fit in memory (if I do
>>>> read_stars(file_path) I get "Error: cannot allocate vector of size 12.7
>>>> Gb"). How can I read a spatial subset of that file.
>>>>
>>>> The example below works with a toy example but not with the actual large
>>>> dataset.
>>>>
>>>> library(stars)
>>>> library(sf)
>>>>
>>>> tif = system.file("tif/L7_ETMs.tif", package = "stars")
>>>> window <- read_stars(tif) %>%
>>>>       st_bbox() %>%
>>>>       st_as_sfc() %>%
>>>>       st_buffer(-2000) %>%
>>>>       st_bbox()
>>>>
>>>> tif_sub <- read_stars(tif, proxy = TRUE) %>%
>>>>       st_crop(window)
>>>>
>>>> plot(tif_sub)
>>>>
>>>> I get the following error:
>>>>
>>>> Error in x[[i]][1:-21561856, 1:146, , drop = FALSE] :
>>>>     only 0's may be mixed with negative subscripts
>>>>
>>>> Kind regards,
>>>> Loïc
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> [hidden email]
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo