hypertidy/ximage

support gdalraster attributed output

mdsumner opened this issue · 5 comments

done in

daeff30

I fixed up a couple of other things there, so may well have broken other parts. All needs a bit of a rethink (after I explore a bit more).

library(gdalraster)
  tms <- "<GDAL_WMS><Service name=\"TMS\"><ServerUrl>http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/${z}/${y}/${x}</ServerUrl></Service><DataWindow><UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY><LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY><TileLevel>17</TileLevel><TileCountX>1</TileCountX><TileCountY>1</TileCountY><YOrigin>top</YOrigin></DataWindow><Projection>EPSG:900913</Projection><BlockSizeX>256</BlockSizeX><BlockSizeY>256</BlockSizeY><BandsCount>3</BandsCount><MaxConnections>10</MaxConnections><Cache /></GDAL_WMS>"
  gebco <- "/vsicurl/https://gebco2023.s3.valeria.science/gebco_2023_land_cog.tif"
  
  ds <- new(GDALRaster, tms)  
  
r <-   read_ds(ds, out_xsize = 1024, out_ysize = 1024, as_list = TRUE)
ximage(r)

ds <- new(GDALRaster, gebco)  

r <-   read_ds(ds, out_xsize = 1024, out_ysize = 512, as_list = TRUE)
ximage(r)


It works for me. Nice examples.

Could there be something like this where x comes in? (no worries if not!)

if (is.numeric(x) && "gis" %in% names(attributes(x))) {
	## gdalraster output
	gis <- attr(x, "gis")
	x_list <- asplit(array(x, dim = gis$dim), 3)
	attr(x_list, "gis") <- gis
	ximage.list(x_list, extent = extent, zlim = zlim, add = add, ..., xlab = xlab, ylab = ylab, col = col)
}

Then the output from gdalraster could be either list, or vector interleaved by band. With the above, the list elements become 2-D arrays instead of vectors but it doesn't seem to matter. This works (drops as_list = TRUE so r is vector):

base_url <- "/vsicurl/https://raw.githubusercontent.com/usdaforestservice/gdalraster/main/sample-data/"
f <- paste0(base_url, "landsat_c2ard_sr_mt_hood_jul2022_utm.tif")
ds <- new(GDALRaster, f)
r <- read_ds(ds, bands=c(7,5,4))

gis <- attr(r, "gis")
r <- asplit(array(r, dim = gis$dim), 3)
attr(r, "gis") <- gis
ximage(r)

This is an aside, but the default normalization must be slightly different. Not a problem or anything, just noticing:

plot_raster(r)

ah yes for sure, normalizing is one of those things I've let slip in terms of details - I'm hoping to have a deeper review of the entire code base here in coming weeks

could you please PR the change for the vector form, just so I don't lose track of it? got a busy week but will be back at this ~23 Feb ... if not I will keep this issue in my pile

(I had no idea about asplit!! that's awesome, I always do split with an awkward rep/seq ...)

will do, thanks