hypertidy / vapour

GDAL API package for R
https://hypertidy.github.io/vapour/
83 stars 9 forks source link

ungeoreferenced imagery #204

Open mdsumner opened 1 year ago

mdsumner commented 1 year ago

we need both SRC_METHOD and DST_METHOD to be NO_GEOTRANSFORM, then we can play purely with target_dim:


im <- vapour::gdal_raster_image("https://herbariumnsw-pds.s3-ap-southeast-2.amazonaws.com/images/NSW041500.jp2", 
                               target_dim = c(0, 1024),
                               options = c("-to", "SRC_METHOD=NO_GEOTRANSFORM", "-to", "DST_METHOD=NO_GEOTRANSFORM"))
ximage(im)

even better would be the overviews, so maybe a "max_dim" argument could do

info <- vapour::vapour_raster_info("https://herbariumnsw-pds.s3-ap-southeast-2.amazonaws.com/images/NSW041500.jp2")
ovr <- matrix(info$overview, byrow = TRUE, ncol = 2)
max_dim <- 1024
if (!is.null(ovr)) {
idx <- max(c(findInterval(max_dim, rev(ovr[,1])), findInterval(max_dim, rev(ovr[,2])))
)
dimension  <- ovr[nrow(ovr):1, ][idx, ]
}
mdsumner commented 1 year ago

hmm, no it doesn't work properly - the target dim screws up the extent

mdsumner commented 1 year ago

the only thing that works reliably with this source is to override the original extent, and ask for specific overview dims

library(vapour)
library(ximage)
info <- vapour_raster_info("https://herbariumnsw-pds.s3-ap-southeast-2.amazonaws.com/images/NSW041500.jp2")

ovr <- matrix(info$overview, byrow = TRUE, ncol = 2)
ovr <- ovr[nrow(ovr):1, ]

im <- vapour::gdal_raster_image("vrt://https://herbariumnsw-pds.s3-ap-southeast-2.amazonaws.com/images/NSW041500.jp2?a_ullr=0,9661,7175,0", 
                               target_dim = ovr[5,])

print(attr(im, "extent"))
ximage(im)

where 'ovr' s