In the data compilation of xyz-data into parquet files each ping is for convenience assigned to a particular square according to the following grid-model:
One could even entertain assigning each observation to a 8x8 meter raster. Then reasterization could be done from within parquet. But then how should one go if the raster of interest is e.g. 32x32 meters?
A “dynamic raster”
An attemp was made to create rayshade-model of bathymetric relief using a “dynamic” rasterization. In principle the process was to generate rayshades first at 8x8 meter resolution, next 16x16 meter, then 32x32 meters, 64x64 meters ending with 128x128 meters. At each level of rasterization a criteria was used such that if the observations points were less than 10 no rayshading was done at that level. The choice of less than 10 is arbritrary and a better approach may need to be thought of.
Quick and dirty rastering within arrow
We can do a poor-man’s rasterization within parquet quite easily via:
con <-open_dataset("/net/hafkaldi.hafro.is/export/home/haf/einarhj/stasi/gis/botninn/data-parquet/xyz")dx <-5# the grid resolution in metersg <- con |>filter(sq ==25) |>mutate(x = x %/% dx * dx + dx/2,y = y %/% dx * dx + dx/2,one = 1L) |>group_by(x, y) |>summarise(n =sum(one),z =mean(z),.groups ="drop") |># at minimum 3 pings (read: measurements) per gridfilter(n >2) |>select(x, y, z) |>collect()g |>glimpse()
Now it is obvious from the above that we have some gaping holes at this resolution, those being related to the depth. If one were interested in only the most “data-rich” regions we would/could limit the bounds.
Poor-mans dynamic raster
Another way is some kind of a dynamic rastering/rayshading as described above. Here is one code-take on achieving that using “dynamic” rastering:
# NOT RUNdx <-5# milking the stonexyz <- con |>filter(sq ==25,# trim some "outliers" x <1.65e6, y <1.35e5) |>mutate(x = x %/% dx * dx + dx/2,y = y %/% dx * dx + dx/2) |>group_by(x, y) |>summarise(z =mean(z),.groups ="drop") |>collect()r0 <- xyz |> terra::rast(type ="xyz",crs =paste0("epsg:", CRS)) |> terra::trim()# this takes a while (for now, at least) ...rs <- ramb::mb_rashade_xyz_dynamic(xyz, r0, file_prefix ="tmp/vestmannaeyjar_")rs |> terra::writeRaster("tmp_vestmannaeyjar.tif")# create png tiles, for demo. no downsampling heretiler::tile(file ="tmp_vestmannaeyjar.tif",zoom ="0-15",tiles ="/net/hafri.hafro.is/export/home/hafri/einarhj/public_html/tiles/vestmannaeyjar")system("chmod -R a+rx /net/hafri.hafro.is/export/home/hafri/einarhj/public_html/tiles/vestmannaeyjar")