-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vrt() produces .vrts which are unnecessarily slow or even intractable work with #1490
Comments
Shouldn't it rather be |
|
The example of resolution change from the v <- vrt(ff, vrtfile, options = c("-tr", 5, 5)) For library("terra")
r <- rast(ncols = 100, nrows = 100, nlyrs = 3)
values(r) <- rep(c(1, 2, 3), each = 100^2)
x <- rast(ncols = 2, nrows = 2)
filename <- paste0(tempfile(), "_.tif")
ff <- makeTiles(r, x, filename)
vrtfile <- paste0(tempfile(), ".vrt")
# works fine
v <- vrt(ff, vrtfile, options = c("-b", 3, "-b", 2), overwrite = TRUE)
v
#> min values : 3, 2
#> max values : 3, 2
# wrong result
v <- vrt(ff, vrtfile, options = c("b 3", "b 2"), overwrite = TRUE)
v
#> min values : 1, 2, 3
#> max values : 1, 2, 3 |
Hi @kadyb,
Comment: Output only has four bands (tiles) based on the first band. No remaining bands. Shouldn't we expect number of tiles * number of bands? So having in total 12 bands?
Comment: Shouldn't output have values of 3?
Comment: Shouldn't output have 8 bands? First four with values of 3, then the other four with values of 2? Thanks! |
@Rapsodia86, do you have GDAL version < 3.8? Because this has been changed and then the results should be as you expect.
|
Yes, I do (win10):
Ok, so this is expected for now. |
I work with a modest assortment of GeoTIFF based virtual rasters. This consists of a few different .vrts with a few hundred tiles of 10–200 MB each and total sizes of 6–100 GB. Usability of these .vrts in QGIS has been not great and, recently, some of the generated .vrts simply don't render completely or reliably. This has prompted some investigation, some of which gets into how GDAL is compiled for QGIS.
However, a significant contributor to poor render performance is
terra::vrt()
generates .vrts that tell GDAL it's most efficient to load rasters one line at a time viaBlockYSize
. This is often not the case, which is why GDAL defaults to loading entire tiles unless it's a scanline image. For example, a typicalvrt()
call in this use case produces a few thousand source statements like(terra 1.7.65, Win10 22H2, 5950X, 4060 Ti, the R call here is just
vrt(vectorOfTilePaths, "tileFolderPath/foo.vrt", set_names = TRUE)
).A quick fix is to delete
BlockXSize="2000" BlockYSize="1"
. SettingBlockYSize
the same asRasterYSize
also works and, while specifying block sizes is at least semi-discouraged on the GDAL side, might sometimes yield somewhat better performance..vrt usability is also substantially influenced by the number of bands in the .vrt, band datatypes, and file sizes. In principle this is partially addressed by using
terra::vrt(options = c("b 1", "b 2", ...))
or similar to restrict the bands present in the .vrt. In practice, I'm findingoptions
is ignored and the output .vrt contains all of the input tiles' bands. Additionally problematic is there's no way to say which bands to pull from which tiles. For example, to constrain file sizes to where QGIS rendering doesn't time out it might be necessary to shard 12 band floating point tiles into six band floating point tiles plus a spatially matching set of six band, 16 bit integer tiles. Useful visualizations might then call for, say, a three band .vrt consisting of floating point bands 1 and 3 plus one of the integer bands.vrt()
can help with this by making floating point and integer .vrts but it's the necessary manually put the bands together and do find/replaces on the XML. Speaking from experience, this gets old fast.I'm unfamiliar with the working relationship between rspatial and OSGeo so the most effective path to improvements here is unclear to me. A bit of searching in the GDAL repo isn't giving me
gdalbuildvrt
issues around this either. My solution's been writing an object model and XML serialization for the .vrt file format but that's rather a one off.The text was updated successfully, but these errors were encountered: