|
@@ -3,8 +3,8 @@ import struct
|
|
|
from django.forms import ValidationError
|
|
|
|
|
|
from .const import (
|
|
|
- GDAL_TO_POSTGIS, GDAL_TO_STRUCT, POSTGIS_HEADER_STRUCTURE, POSTGIS_TO_GDAL,
|
|
|
- STRUCT_SIZE,
|
|
|
+ BANDTYPE_FLAG_HASNODATA, GDAL_TO_POSTGIS, GDAL_TO_STRUCT,
|
|
|
+ POSTGIS_HEADER_STRUCTURE, POSTGIS_TO_GDAL, STRUCT_SIZE,
|
|
|
)
|
|
|
|
|
|
|
|
@@ -48,10 +48,10 @@ def from_pgraster(data):
|
|
|
pixeltype, data = chunk(data, 2)
|
|
|
pixeltype = unpack('B', pixeltype)[0]
|
|
|
|
|
|
-
|
|
|
- has_nodata = pixeltype >= 64
|
|
|
+
|
|
|
+ has_nodata = pixeltype & BANDTYPE_FLAG_HASNODATA
|
|
|
if has_nodata:
|
|
|
- pixeltype -= 64
|
|
|
+ pixeltype &= ~BANDTYPE_FLAG_HASNODATA
|
|
|
|
|
|
|
|
|
pixeltype = POSTGIS_TO_GDAL[pixeltype]
|
|
@@ -116,12 +116,13 @@ def to_pgraster(rast):
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
structure = 'B' + GDAL_TO_STRUCT[band.datatype()]
|
|
|
|
|
|
|
|
@@ -129,7 +130,7 @@ def to_pgraster(rast):
|
|
|
|
|
|
|
|
|
if band.nodata_value is not None:
|
|
|
- pixeltype += 64
|
|
|
+ pixeltype |= BANDTYPE_FLAG_HASNODATA
|
|
|
|
|
|
|
|
|
bandheader = pack(structure, (pixeltype, band.nodata_value or 0))
|