vapour icon indicating copy to clipboard operation
vapour copied to clipboard

ungeoreferenced imagery

Open mdsumner opened this issue 2 years ago • 2 comments

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 avatar Apr 24 '23 08:04 mdsumner

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

mdsumner avatar Apr 24 '23 08:04 mdsumner

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

mdsumner avatar Apr 24 '23 09:04 mdsumner