Opened 3 weeks ago

Last modified 2 days ago

#37055 assigned New feature

GDALRaster fails when using Float and NBITS=16

Reported by: Marcos Sánchez Provencio Owned by: Rish
Component: GIS Version: 6.0
Severity: Normal Keywords:
Cc: Marcos Sánchez Provencio Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

GDALRaster creation fails when trying to use NBITS=16 (thus creating a Float16 dataset)

In [39]: >>> import tempfile
rstfile = tempfile.NamedTemporaryFile(suffix=".tif")
rst = GDALRaster(
    {
         "driver": "GTiff",
         "name": rstfile.name,
         "srid": 4326,
          "width": 255,
          "height": 255,
          "nr_of_bands": 1,
              "papsz_options":dict(NBITS=32)
      }
  )

In [40]: rst.bands[0].data()
Out[40]: 
array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)

But this fails:

In [42]: rst.bands[0].data()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[42], line 1
----> 1 rst.bands[0].data()

File ~/v_django4/lib/python3.14/site-packages/django/contrib/gis/gdal/raster/band.py:207, in GDALBand.data(self, data, offset, size, shape, as_memoryview)
    204     raise ValueError("Size is larger than raster.")
    206 # Create ctypes type array generator
--> 207 ctypes_array = GDAL_TO_CTYPES[self.datatype()] * (shape[0] * shape[1])
    209 if data is None:
    210     # Set read mode
    211     access_flag = 0

IndexError: list index out of range

Change History (6)

comment:1 by Marcos Sánchez Provencio, 3 weeks ago

GDAL version might be relevant. I was using this in Ubuntu 24.04 without problems.
Working (ubuntu 24.04):

gdalinfo --version 
GDAL 3.8.4, released 2024/02/08

Not working (ubuntu 26.04)

gdalinfo --version
GDAL 3.12.2 "Chicoutimi", released 2026/02/03

comment:2 by David Smith, 3 weeks ago

Triage Stage: UnreviewedAccepted
Type: BugNew feature
Version: 5.26.0

GDAL 3.11 added support for float16, see RFC.

This PR added some interger types. It could be used for inspiration for a PR to resolve this ticket.

comment:3 by Rish, 12 days ago

Owner: set to Rish
Status: newassigned

comment:4 by Rish, 10 days ago

Note: Currently there is a [DDoS attack](https://askubuntu.com/questions/1566282/ubuntu-infrastructure-including-ppa-launchpadcontent-net-not-responding-returni) on Ubuntu going on, due to which I wasn't able to access ppa repo, for the latest 3.11 GDAL. Thankfully, there are [images](https://github.com/osgeo/gdal/pkgs/container/gdal/513073460?tag=ubuntu-full-3.11.4) available for this, on which I am working.

comment:5 by Rish, 3 days ago

Has patch: set

comment:6 by David Smith, 2 days ago

Needs tests: set
Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top