Opened 75 minutes ago
Last modified 69 minutes ago
#37055 new Bug
GDALRaster fails when using Float and NBITS=16
| Reported by: | Marcos Sánchez Provencio | Owned by: | |
|---|---|---|---|
| Component: | GIS | Version: | 5.2 |
| Severity: | Normal | Keywords: | |
| Cc: | Marcos Sánchez Provencio | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| 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
Note:
See TracTickets
for help on using tickets.
GDAL version might be relevant. I was using this in Ubuntu 24.04 without problems.
Working (ubuntu 24.04):
Not working (ubuntu 26.04)