[gdal-dev] overview sizes for COG

2024-03-19 Thread Michael Sumner via gdal-dev
Hi, can we specify overview sizes exactly? I have this odd grid that is
36000x17999, and I get consequently yucky overview sizes:

gdal_create -outsize 36000 17999 -ot Int8 -co SPARSE_OK=YES -a_srs
EPSG:4326 -a_ullr 0 17999 0 36000 weird.tif
gdal_translate weird.tif cog.tif  -of COG
gdalinfo cog.tif | grep Overviews
#  Overviews: 18000x8999, 9000x4499, 4500x2249, 2250x1124, 1125x562,
562x281, 281x14

Should I worry about this?  Can the sizes be specified via Translate? (I
can see how they could be generated externally and bundled, but I'm looking
for a way at this high level).

( Maybe I shouldn't even care about the sizes ... and maybe I should
resample the grid to be a better overall size, but I consider that out of
scope here.)

I'm comparing with other COG creators, e.g. odc which makes tidy overviews
( I will explore how it's getting done).

import xarray
from odc.geo.xr import assign_crs
from odc.geo.cog import write_cog

ds = xarray.open_dataset("weird.tif")
ds = assign_crs(ds, crs="EPSG:4326")  ## do something to tag it as odc


write_cog(ds["band_data"], "odc.tif")
os.system("gdalinfo odc.tif | grep Overviews")
#  Overviews: 18000x9000, 9000x4500, 4500x2250, 2250x1125, 1125x563

Cheers, Mike


-- 
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsum...@gmail.com
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] overview sizes for COG

2024-03-19 Thread Even Rouault via gdal-dev

Michael,

Hi, can we specify overview sizes exactly?


No, the BuildOverviews() interface onlys take an array of overview 
factors. It is up to the driver implementation to decide how it computes 
the overview size from the main raster size and overview factor.


The COG driver is a bit of a special case, since it automagically 
compute overviews if they don't exist in the source dataset, and doesn't 
take an explicit list of overview factors. It simply divides by two 
successively, with floor truncation: 
https://github.com/OSGeo/gdal/blob/master/frmts/gtiff/cogdriver.cpp#L1092


I have this odd grid that is 36000x17999, and I get consequently yucky 
overview sizes:


gdal_create -outsize 36000 17999 -ot Int8 -co SPARSE_OK=YES -a_srs 
EPSG:4326 -a_ullr 0 17999 0 36000 weird.tif

gdal_translate weird.tif cog.tif  -of COG
gdalinfo cog.tif | grep Overviews
#  Overviews: 18000x8999, 9000x4499, 4500x2249, 2250x1124, 1125x562, 
562x281, 281x14


Should I worry about this?


Probably not ? :-)

Can the sizes be specified via Translate? (I can see how they could be 
generated externally and bundled, but I'm looking for a way at this 
high level).
I guess someone could potentially add a OVERVIEW_SIZES=W1xH1,W2xH2,... 
creation option to the COG driver if that was really needed...


( Maybe I shouldn't even care about the sizes ... and maybe I should 
resample the grid to be a better overall size, but I consider that out 
of scope here.)


I'm comparing with other COG creators, e.g. odc which makes tidy 
overviews ( I will explore how it's getting done).


It looks like they might use (previous_size + 1) / 2 (or ceil rounding)

--
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] overview sizes for COG

2024-03-19 Thread Michael Sumner via gdal-dev
Excellent!  Thanks for the answers.

When I've explored a bit more I might implement the overview sizes just so
we can match downstream tools (the current motivation is like-for-like
performance comparison, I haven't looked there but I think odc goes very
low level to eke out speed).

Cheers, Mike



On Wed, Mar 20, 2024 at 10:39 AM Even Rouault 
wrote:

> Michael,
>
> Hi, can we specify overview sizes exactly?
>
> No, the BuildOverviews() interface onlys take an array of overview
> factors. It is up to the driver implementation to decide how it computes
> the overview size from the main raster size and overview factor.
>
> The COG driver is a bit of a special case, since it automagically compute
> overviews if they don't exist in the source dataset, and doesn't take an
> explicit list of overview factors. It simply divides by two successively,
> with floor truncation:
> https://github.com/OSGeo/gdal/blob/master/frmts/gtiff/cogdriver.cpp#L1092
>
> I have this odd grid that is 36000x17999, and I get consequently yucky
> overview sizes:
>
> gdal_create -outsize 36000 17999 -ot Int8 -co SPARSE_OK=YES -a_srs
> EPSG:4326 -a_ullr 0 17999 0 36000 weird.tif
> gdal_translate weird.tif cog.tif  -of COG
> gdalinfo cog.tif | grep Overviews
> #  Overviews: 18000x8999, 9000x4499, 4500x2249, 2250x1124, 1125x562,
> 562x281, 281x14
>
> Should I worry about this?
>
> Probably not ? :-)
>
> Can the sizes be specified via Translate? (I can see how they could be
> generated externally and bundled, but I'm looking for a way at this high
> level).
>
> I guess someone could potentially add a OVERVIEW_SIZES=W1xH1,W2xH2,...
> creation option to the COG driver if that was really needed...
>
>
> ( Maybe I shouldn't even care about the sizes ... and maybe I should
> resample the grid to be a better overall size, but I consider that out of
> scope here.)
>
> I'm comparing with other COG creators, e.g. odc which makes tidy overviews
> ( I will explore how it's getting done).
>
> It looks like they might use (previous_size + 1) / 2 (or ceil rounding)
>
> -- http://www.spatialys.com
> My software is free, but my time generally not.
>
>

-- 
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsum...@gmail.com
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev