Skip to content
Prev 29176 / 29559 Next

Spatial nested grid in R

One way is to write it to a (COG) GeoTIFF with overviews ("pyramid", or
zoom levels) - these are pre-calculated copies of the highest resolution
data saved as lower resolution versions.

Do you want this to generate a set of nested data, or is it more about
working with the nested logic?

I'm not sure what version of GDAL is required to write one directly with
terra or raster, but i'll explore. In terms of the nesting logic , you can
read a particular zoom level (or model it with an data-empty object) and
determine cell index using the cells tools in terra (or raster). I think
you would need to generate xyFromCell and use that to cellFromXY between
layers (the arithmetic is not onerous but doesn't exist for reuse anywhere
in R afaik).

I'm interested in this generally for workflows I'm using so might come back
with an example, happy to follow up related questions.

At the command line with COG format you can do
gdalinfo in.tif overviews.if -of COG -co OVERVIEW_COUNT=3  ## 3, for example

or

gdal_translate in.tif overviews.tif
gdaladdo overviews.tif 2 4 8

but, of course there are implications with tile pattern and potential
overlap for a given size. You'd probably also want tiling enabled and
choose a particular tile size (perhaps to match the next resolution down).
And I'd definitely want to make sure my extent was clean whole numbers and
choose sensible sized zoom and tile levels.

Cheers, Mike


On Fri, Feb 10, 2023 at 10:22 AM Manuel Sp?nola <mspinola10 at gmail.com>
wrote: