#37055: GDALRaster fails when using Float and NBITS=16
-------------------------------------+-------------------------------------
     Reporter:  Marcos Sánchez       |                     Type:  Bug
  Provencio                          |
       Status:  new                  |                Component:  GIS
      Version:  5.2                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 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
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37055>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019db0e05261-f9f6a64a-1c91-4cec-82cd-f47db55198ce-000000%40eu-central-1.amazonses.com.

Reply via email to