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 , 3 weeks ago
comment:2 by , 3 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Type: | Bug → New feature |
| Version: | 5.2 → 6.0 |
comment:3 by , 12 days ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:4 by , 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 , 3 days ago
| Has patch: | set |
|---|
comment:6 by , 2 days ago
| Needs tests: | set |
|---|---|
| Patch needs improvement: | set |
GDAL version might be relevant. I was using this in Ubuntu 24.04 without problems.
Working (ubuntu 24.04):
Not working (ubuntu 26.04)