def to_pgraster(rast):
 if ((rast is None) or (rast == '')):
  return
 rasterheader = (1, 0, len(rast.bands), rast.scale.x, rast.scale.y, rast.origin.x, rast.origin.y, rast.skew.x, rast.skew.y, rast.srs.srid, rast.width, rast.height)
 result = pack(POSTGIS_HEADER_STRUCTURE, rasterheader)
 for band in rast.bands:
  structure = ('B' + GDAL_TO_STRUCT[band.datatype()])
  pixeltype = GDAL_TO_POSTGIS[band.datatype()]
  if (band.nodata_value is not None):
   pixeltype += 64
  bandheader = pack(structure, (pixeltype, (band.nodata_value or 0)))
  band_data_hex = binascii.hexlify(band.data(as_memoryview=True)).upper()
  result += (bandheader + band_data_hex)
 return result.decode()

def to_pgraster ( rast ) : if ( ( rast is None ) or ( rast == '' ) ) : return rasterheader = ( 1 , 0 , len ( rast . bands ) , rast . scale . x , rast . scale . y , rast . origin . x , rast . origin . y , rast . skew . x , rast . skew . y , rast . srs . srid , rast . width , rast . height ) result = pack ( POSTGIS_HEADER_STRUCTURE , rasterheader ) for band in rast . bands : structure = ( 'B' + GDAL_TO_STRUCT [ band . datatype ( ) ] ) pixeltype = GDAL_TO_POSTGIS [ band . datatype ( ) ] if ( band . nodata_value is not None ) : pixeltype += 64 bandheader = pack ( structure , ( pixeltype , ( band . nodata_value or 0 ) ) ) band_data_hex = binascii . hexlify ( band . data ( as_memoryview = True ) ) . upper ( ) result += ( bandheader + band_data_hex ) return result . decode ( )
convert a gdalraster into postgis raster format .