From c5044a1237037464c17e33a898a5635225465de3 Mon Sep 17 00:00:00 2001 From: Markus Metz Date: Sun, 19 Apr 2026 16:09:42 +0200 Subject: [PATCH] read vrt tile only if needed --- lib/raster/vrt.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/raster/vrt.c b/lib/raster/vrt.c index e1bca1c192d..a2ada47495b 100644 --- a/lib/raster/vrt.c +++ b/lib/raster/vrt.c @@ -205,8 +205,28 @@ int Rast_get_vrt_row(int fd, void *buf, int row, RASTER_MAP_TYPE data_type) #pragma omp critical(raster_vrt_read) for (i = 0; i < vrt->tlist->n_values; i++) { struct tileinfo *p = &ti[vrt->tlist->value[i]]; + double tile_west, tile_east; - if (p->cellhd.north > rows && p->cellhd.south <= rown) { + tile_west = p->cellhd.west; + tile_east = p->cellhd.east; + + if (R__.rd_window.proj == PROJECTION_LL) { + /* longitude wrapping of the tile into the current + * reading window */ + while (tile_west > rd_window->east) { + tile_west -= 360.0; + tile_east -= 360.0; + } + while (tile_east < rd_window->west) { + tile_west += 360.0; + tile_east += 360.0; + } + } + + /* open the tile only if it overlaps with the current reading + * row and the current reading EW extents */ + if (p->cellhd.north > rows && p->cellhd.south <= rown && + tile_west < p->cellhd.east && tile_east > p->cellhd.west) { int tfd; void *p1, *p2;