postgis to gdal conversion constant definitions lookup to convert pixel type values from gdal to postgis lookup to convert pixel type values from postgis to gdal struct pack structure for raster header the raster header has the following structure endianness postgis raster version number of bands scale origin skew srid width and height scale origin and skew have x and y values postgis currently uses a fixed endianness 1 and there is only one version 0 lookup values to convert gdal pixel types to struct characters this is used to pack and unpack the pixel values of postgis raster bands size of the packed value in bytes for different numerical types this is needed to cut chunks of band data out of postgis raster strings when decomposing them into gdalrasters see https docs python orglibrarystruct htmlformatcharacters pixel type specifies type of pixel values in a band storage flag specifies whether the band data is stored as part of the datum or is to be found on the server s filesystem there are currently 11 supported pixel value types so 4 bits are enough to account for all reserve the upper 4 bits for generic flags see https trac osgeo orgpostgiswikiwktrasterrfcrfc1v0serialformatpixeltypeandstorageflag lookup to convert pixel type values from gdal to postgis lookup to convert pixel type values from postgis to gdal struct pack structure for raster header the raster header has the following structure endianness postgis raster version number of bands scale origin skew srid width and height scale origin and skew have x and y values postgis currently uses a fixed endianness 1 and there is only one version 0 lookup values to convert gdal pixel types to struct characters this is used to pack and unpack the pixel values of postgis raster bands size of the packed value in bytes for different numerical types this is needed to cut chunks of band data out of postgis raster strings when decomposing them into gdalrasters see https docs python org library struct html format characters signed char unsigned char _bool short unsigned short integer unsigned integer long unsigned long float double pixel type specifies type of pixel values in a band storage flag specifies whether the band data is stored as part of the datum or is to be found on the server s filesystem there are currently 11 supported pixel value types so 4 bits are enough to account for all reserve the upper 4 bits for generic flags see https trac osgeo org postgis wiki wktraster rfc rfc1_v0serialformat pixeltypeandstorageflag
GDAL_TO_POSTGIS = [None, 4, 6, 5, 8, 7, 10, 11, None, None, None, None]


POSTGIS_TO_GDAL = [1, 1, 1, 3, 1, 3, 2, 5, 4, None, 6, 7, None, None]









POSTGIS_HEADER_STRUCTURE = "B H H d d d d d d i H H"



GDAL_TO_STRUCT = [
    None,
    "B",
    "H",
    "h",
    "L",
    "l",
    "f",
    "d",
    None,
    None,
    None,
    None,
]





STRUCT_SIZE = {
    "b": 1,  
    "B": 1,  
    "?": 1,  
    "h": 2,  
    "H": 2,  
    "i": 4,  
    "I": 4,  
    "l": 4,  
    "L": 4,  
    "f": 4,  
    "d": 8,  
}







BANDTYPE_PIXTYPE_MASK = 0x0F
BANDTYPE_FLAG_HASNODATA = 1 << 6