Re: [gdal-dev] The relationship between overview levels and zoom levels?

2023-10-08 Thread Even Rouault via gdal-dev

James,

It all depends on how software will deal with overviews. Some might 
explicitly have logic where it inspects which overviews are present and 
decide which one to use. If we are talking about a client like QGIS that 
uses the RasterIO() method on the full resolution band with a window of 
interest (nXOff, nYOff, nXSize, nYSize) and a target buffer size 
(nBufXSize, nBufYSize),  GDAL computes a target downscaling factor for 
that which is the min(nXSize/nBufXSize, nYSize/nBufYSize).  It then 
walks through overviews and will select the frist one whose downscaling 
factor is greater than target_dowscanling_factor / 1.2


If you have overviews at [2,4,8,16]

target_downscaling_factor    selected_overview
-    --
]0, 2. /1.2[     full resolution band
[2. / 1.2, 4. / 1.2[     2x downsampled
[4. / 1.2, 8. / 1.2[     4x downsampled
[8. / 1.2, 16. / 1.2[    8x downsampled
[16. / 1.2, inf[ 16x downsampled

If you just have overview [16]

target_downscaling_factor    selected_overview
-    --
]0, 16. /1.2[    full resolution band
[16. / 1.2, inf[ 16x downsampled

I've submitted in https://github.com/OSGeo/gdal/pull/8526 a doc 
improvement capturing above explanations


Even


Le 08/10/2023 à 00:01, James Sammone via gdal-dev a écrit :
I'm not sure if this is the best channel to ask this question as it 
might be beyond the scope, but I've asked it in a few others and have 
had no responses aside from others also being curious.


I am trying to understand the relationship between overviews and zoom 
levels so I know how to make more efficient Cloud Optimized GeoTIFFs. 
Using gdaladdo or gdal.BuildOverviews(), I can create overviews at 
[2,4,8,16] or at just [16]. From my understanding, this means the size 
is being divided by those values to provide downsample arrays of the 
original source. In the first example [2,4,8,16], I've created 4 
separate overview arrays into the GeoTIFF that are 2x, 4x, 8x, and 16x 
downsampled. And in the second example using only [16], I've built one 
overview array into the GeoTIFF that is 16x downsampled.


How can I understand how these overviews are applied when it comes to 
zoom levels? Does the 16x downsample appear sooner in the second 
example when zooming out than for the first example due to being first 
in order? Or do the 16x downsamples appear at the same zoom level for 
both cases but the second example has additional 2x, 4x, and 8x 
downsamples that also appear before getting there?




Thanks for any insight into this anyone can provide. Despite using 
overviews all the time, I've struggled with this for a while and had 
largely consigned to not understanding it.


Best,

James


___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


--
http://www.spatialys.com
My software is free, but my time generally not.

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] The relationship between overview levels and zoom levels?

2023-10-08 Thread Rahkonen Jukka via gdal-dev
Hi,

There are documentation about overviews in 
https://gdal.org/drivers/raster/cog.html, 
https://gdal.org/drivers/raster/gtiff.html, and 
https://gdal.org/programs/gdal_translate.html. Probably in other places, too, 
but reading those carefully is a good start. They deal also a bit with zoom 
levels.

What happens when a client opens an image with only one overview [16] is 
totally up to the client. It knows that the 1/16 downsampled version is 
available and it may decide to use the closest available overview: first full 
resolution till 1/8 and then jump to use 1/16. This is the AUTO approach of 
gdal_translate. Some other client would prefer better quality and use the full 
resolution up till 1/16 to avoid upsampling data that has downsampled earlier.

The COG driver has options for creating the overviews to match with the zoom 
levels of the selected tiling schema. Then there will be no need to resample 
the overview data again when the client makes zoom level based requests.

-Jukka Rahkonen-



Lähettäjä: gdal-dev  Puolesta James Sammone 
via gdal-dev
Lähetetty: sunnuntai 8. lokakuuta 2023 1.02
Vastaanottaja: gdal-dev@lists.osgeo.org
Aihe: [gdal-dev] The relationship between overview levels and zoom levels?

I'm not sure if this is the best channel to ask this question as it might be 
beyond the scope, but I've asked it in a few others and have had no responses 
aside from others also being curious.

I am trying to understand the relationship between overviews and zoom levels so 
I know how to make more efficient Cloud Optimized GeoTIFFs. Using gdaladdo or 
gdal.BuildOverviews(), I can create overviews at [2,4,8,16] or at just [16]. 
From my understanding, this means the size is being divided by those values to 
provide downsample arrays of the original source. In the first example 
[2,4,8,16], I've created 4 separate overview arrays into the GeoTIFF that are 
2x, 4x, 8x, and 16x downsampled. And in the second example using only [16], 
I've built one overview array into the GeoTIFF that is 16x downsampled.

How can I understand how these overviews are applied when it comes to zoom 
levels? Does the 16x downsample appear sooner in the second example when 
zooming out than for the first example due to being first in order? Or do the 
16x downsamples appear at the same zoom level for both cases but the second 
example has additional 2x, 4x, and 8x downsamples that also appear before 
getting there?

Thanks for any insight into this anyone can provide. Despite using overviews 
all the time, I've struggled with this for a while and had largely consigned to 
not understanding it.

Best,

James
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] The relationship between overview levels and zoom levels?

2023-10-08 Thread Richard Duivenvoorde via gdal-dev

Hi James,

If I understand correctly, it is simpler then you might think.

The main purpose of these overviews is to have a quicker/better response at 
higher
(overview) levels. So if you have one giant Geotiff (meaning a LOT of cells),
you still would have to open and check ALL cell values, even if you want to
have a small overview image of 100x100 pixels, in which you have to downs-ample
anyway to get the general overview. Down-sampling images is a very cpu
intensive task, which can be done in different ways. The best looking way
also are the most 'expensive'.

The Overviews are more like a good looking cache (already down-sampled) that
are saved so you don not have to go into the full dataset the next time
you only need this 100x100 pixel image.

In general, the overview/pyramid levels have nothing to do with the zoom
levels of a software client. Having 5 or 8 overview levels in your data, a 
client
can still zoom in 10 or 12 or 3 steps through the map image.

It will just pick the most efficient available image/overview.

So say a software client in which you want to have a general overview which
(if you would work with printed maps) would (on zoom scale level) be more close
to the level which is is like the 8x pyramid (zoom level), would
- in the case there IS a 8x pyramid (your [2,4,8,16]) case): just pick the
8x version to generate the image for you.
- in the case there is NO 8x level (image), it will pick the level which
will take the least effort to generate the 8x zoom image, with the extra
constraint that it will never have to up-sample(? is that the term)? the
image. So in this case I think it will not pick the 16x level, because that
would mean that it will have to blow up pixels to fit..
Same with (viewing) zoom levels NOT on the exact overview levels: it will
take the (overview) data that is the least work.

I realize this is mostly talking about normal geotiffs, but I think the
reasoning also goes up for Cloud Optimized GeoTIFFs.

It's all about 'prerendering' because down--sampling is a cpu intensive
task. And for prerendered images you can use more expensive sample
algorithms.

Hope this helps, or else somebody has a better answer :-)

Regards,

Richard Duivenvoorde



On 10/8/23 00:01, James Sammone via gdal-dev wrote:

I'm not sure if this is the best channel to ask this question as it might
be beyond the scope, but I've asked it in a few others and have had no
responses aside from others also being curious.


I am trying to understand the relationship between overviews and zoom
levels so I know how to make more efficient Cloud Optimized GeoTIFFs. Using
gdaladdo or gdal.BuildOverviews(), I can create overviews at [2,4,8,16] or
at just [16]. From my understanding, this means the size is being divided
by those values to provide downsample arrays of the original source. In the
first example [2,4,8,16], I've created 4 separate overview arrays into the
GeoTIFF that are 2x, 4x, 8x, and 16x downsampled. And in the second example
using only [16], I've built one overview array into the GeoTIFF that is 16x
downsampled.

How can I understand how these overviews are applied when it comes to zoom
levels? Does the 16x downsample appear sooner in the second example when
zooming out than for the first example due to being first in order? Or do
the 16x downsamples appear at the same zoom level for both cases but the
second example has additional 2x, 4x, and 8x downsamples that also appear
before getting there?

Thanks for any insight into this anyone can provide. Despite using
overviews all the time, I've struggled with this for a while and had
largely consigned to not understanding it.

Best,

James


___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev