1

Issue presented using GDAL called from Python

I have a TIFF file, src.tiff. I want to reproject it and create a COG, dst.tiff. To achieve that, I do the following:

from osgeo import gdal warp_opts = gdal.WarpOptions( dstSRS="EPSG:3857", # comment out this line if you want to have a meta["metadata"]["TILING_SCHEME"]["ZOOM_LEVEL"] value resampleAlg="cubic", dstAlpha=True, format="COG", creationOptions=[ "COMPRESS=DEFLATE", "BLOCKSIZE=512", "TILING_SCHEME=GoogleMapsCompatible", ], ) gdal.Warp("dst.tiff", "src.tiff", options=warp_opts) 

This produces dst.tiff, a COG. It has overviews, as expected. Here is how I know that:

meta = gdal.Run("raster", "info", input="dst.tiff").Output() print(meta["bands"][0]['overviews']) 

Output:

[{'size': [1536, 1280]}, {'size': [768, 640]}, {'size': [384, 320]}] 

However, there is no TILING_SCHEME/ZOOM_LEVEL parameter. I am looking for it:

print(meta["metadata"]["TILING_SCHEME"]["ZOOM_LEVEL"]) 

I get KeyError: 'TILING_SCHEME'. However, if I uncomment the dstSRS="EPSG:3857" line from gdal.WarpOptions, and rerun gdal.Warp, then

meta = gdal.Run("raster", "info", input="dst.tiff").Output() print(meta["metadata"]["TILING_SCHEME"]["ZOOM_LEVEL"]) 

returns 13.


Same issue using GDAL called from CLI

This returns null unless I remove -t_srs EPSG:3857 \, in which case I get 13:

gdalwarp -of COG \ -t_srs EPSG:3857 \ -co COMPRESS=DEFLATE \ -co BLOCKSIZE=512 \ -co TILING_SCHEME=GoogleMapsCompatible \ src.tiff dst.tiff gdalinfo dst.tiff -json | jq -r '.metadata.TILING_SCHEME.ZOOM_LEVEL' 

How can I reproject and have TILING_SCHEME metadata in a COG I produce using GDAL?

1 Answer 1

2

By the documentation https://gdal.org/en/stable/drivers/raster/cog.html when you use some well known tiling schema then -t_srs has no effect because the tiling schema defines the coordinate system.

In non-CUSTOM mode, TARGET_SRS, RES and EXTENT options are ignored.

The answer to your question "How can I reproject and have TILING_SCHEME metadata in a COG I produce using GDAL?" is not to use -t_srs together with -co TILING_SCHEME=GoogleMapsCompatible. "GoogleMapsCompatible" is always EPSG:3857, it cannot be compatible with any other coordinate system. There seems to be a small bug in GDAL when it skips writing the metadata, though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.