[gdal-dev] 2D multiband to 3D MULTIDIM results in duplicated "x" dimension

Michael Sumner mdsumner at gmail.com
Mon Oct 14 13:47:38 PDT 2024


Thanks Even!   That makes sense.

One quibble though, using the netcdf way gives order "Z, y, x",  but for
Zarr "y, x, Z", is that expected? I can reorder with another step, I
can't see see a relevant creation option.

gdal_translate Rlogo.png out.nc -mo NETCDF_DIM_EXTRA="{Z}" -mo
NETCDF_DIM_Z_DEF="{4,4}" -mo NETCDF_DIM_Z_VALUES="{0,1,2,3}" -mo "Z#axis=Z"
 -co FORMAT=NC4
Input file size is 100, 76

 "Band1": {
      "datatype": "Byte",
      "dimensions": [
        "/Z",
        "/y",
        "/x"
      ],
      "dimension_size": [
        4,
        76,
        100
      ],


gdal_translate Rlogo.png out.zarr -of ZARR
Input file size is 100, 76
    "out": {
      "datatype": "Byte",
      "dimensions": [
        "/Y",
        "/X",
        "/Band"
      ],
      "dimension_size": [
        76,
        100,
        4
      ],



Cheers, Mike



On Tue, Oct 15, 2024 at 12:53 AM Even Rouault <even.rouault at spatialys.com>
wrote:

> Michael,
>
> fixed per https://github.com/OSGeo/gdal/pull/11005
>
> Otherwise just do "gdal_translate Rlogo.png Rlogo.zarr -of Zarr" . By
> default the Zarr driver translates GDAL bands as the Z dimension, unless
> you specify the SINGLE_ARRAY=NO creation option, in which case it will
> create a Zarr array per band (so a different default as the netCDF driver).
>
> Even
> Le 14/10/2024 à 14:10, Michael Sumner via gdal-dev a écrit :
>
> Possibly this is a fool's errand ...
>
> I want to be able to cast an RGBA file as a Zarr, so first to cast as
> multidim I tried the CreateCopy route with NetCDF and I see dimension "x"
> repeated, with "y" missing. (I'm using an external file as the existing
> test PNG files are square in shape).
>
> from osgeo import gdal
>
> ## PNG source is 100x76 * 4 bands
> f = "/vsicurl/
> https://github.com/cran/png/blob/master/inst/img/Rlogo.png?raw=true"
> src_ds = gdal.Open(f)
>
> ## set NetCDF metadata to make Bands 0,1,2,3 a Z dimension
> size_z = 4
> src_ds.SetMetadataItem('NETCDF_DIM_EXTRA', '{Z}')
> src_ds.SetMetadataItem('NETCDF_DIM_Z_DEF', f"{{{size_z},4}}")
> src_ds.SetMetadataItem('NETCDF_DIM_Z_VALUES', '{1.25,2.50}')
> src_ds.SetMetadataItem('Z#axis', 'Z')
>
> # Create netCDF file
> gdal.GetDriverByName('netCDF').CreateCopy('out.nc', src_ds)
>
> ## investigate shape as a mdim
> ds = gdal.OpenEx("out.nc",  gdal.OF_MULTIDIM_RASTER)
> rootGroup = ds.GetRootGroup()
> var = rootGroup.OpenMDArray("Band1")
>
> ## we ended up with x,x,Z
> [dim.GetSize() for  dim in  var.GetDimensions()]
> #[4, 100, 100]
>
>
> That looks like a bug?
>
> And, is there a better way to go about this?  PNG->ZARR is my target, I'm
> fine with programmatic creation of NetCDF, but this could be quite handy as
> a two-step conversion from pseudo-3D to actual 3D via the cli with
> "gdal_translate -mo ...". (This is not for real work fwiw, just for me
> programming at the edges of Zarr, with examples that are clear in visual
> terms).
>
> Cheers, Mike
>
>
>
>
> --
> Michael Sumner
> Research Software Engineer
> Australian Antarctic Division
> Hobart, Australia
> e-mail: mdsumner at gmail.com
>
> _______________________________________________
> gdal-dev mailing listgdal-dev at lists.osgeo.orghttps://lists.osgeo.org/mailman/listinfo/gdal-dev
>
> -- http://www.spatialys.com
> My software is free, but my time generally not.
> Mostly a fool, sometimes acting like a professional (or vice versa)
>
>

-- 
Michael Sumner
Research Software Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20241015/8412d268/attachment.htm>


More information about the gdal-dev mailing list