PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ wkblify_band()

def raster2pgsql.wkblify_band (   options,
  band,
  level,
  xoff,
  yoff,
  read_block_size,
  block_size,
  infile,
  bandidx 
)
Writes band of given GDAL dataset into HEX-encoded WKB for WKT Raster output.

Definition at line 749 of file raster2pgsql.py.

749 def wkblify_band(options, band, level, xoff, yoff, read_block_size, block_size, infile, bandidx):
750  """Writes band of given GDAL dataset into HEX-encoded WKB for WKT Raster output."""
751  assert band is not None, "Error: Missing GDAL raster band"
752 
753  hexwkb = ''
754 
755  if options.register:
756  # Off-db raster
757  # TODO: Do we want to handle options.overview_level? --mloskot
758  # ANSWER:
759  # TODO: Where bandidx and ds come from? --mloskot
760  # ANSWER: Provided by caller method --jorgearevalo
761  hexwkb += wkblify('B', bandidx - 1)
762  filepath = os.path.abspath(infile.replace('\\', '\\\\'))
763  logit('MSG: Out-db raster path=%s\n' % filepath)
764  hexwkb += wkblify(str(len(filepath)) + 's', filepath)
765  hexwkb += wkblify('B', 0)
766  else:
767  # In-db raster
768 
769  # Right most column and bottom most row of blocks have
770  # portions that extend beyond the raster
771  read_padding_size = calculate_block_pad_size(band, xoff, yoff, read_block_size)
772  valid_read_block_size = ( read_block_size[0] - read_padding_size[0],
773  read_block_size[1] - read_padding_size[1] )
774 
775 
776  if read_padding_size[0] > 0 or read_padding_size[1] > 0:
777  target_block_size = (valid_read_block_size[0] / level, valid_read_block_size[1] / level)
778  target_padding_size = (read_padding_size[0] / level, read_padding_size[1] / level)
779  else:
780  target_block_size = block_size
781  target_padding_size = ( 0, 0 )
782 
783  logit('MSG: Normalize read_block=%s for level=%d to valid_read_block=%s with padding=%s\n' % \
784  (read_block_size, level, valid_read_block_size, read_padding_size))
785  logit('MSG: Normalize target_block=%s for level=%d to valid_target_block=%s with padding=%s\n' % \
786  (block_size, level, target_block_size, target_padding_size))
787  logit('MSG: ReadAsArray( %d, %d, %s, %s)\n' % \
788  (xoff, yoff, str(valid_read_block_size), str(target_block_size)))
789 
790  assert valid_read_block_size[0] > 0 and valid_read_block_size[1] > 0
791  assert target_block_size[0] > 0 and target_block_size[1] > 0
792 
793  pixels = band.ReadAsArray(xoff, yoff, valid_read_block_size[0], valid_read_block_size[1],
794  target_block_size[0], target_block_size[1])
795 
796  # XXX: Use for debugging only
797  #dump_block_numpy(pixels)
798 
799  out_pixels = numpy.zeros((block_size[1], block_size[0]), pt2numpy(band.DataType))
800 
801  logit('MSG: Read valid source:\t%d x %d\n' % (len(pixels[0]), len(pixels)))
802  logit('MSG: Write into block:\t%d x %d\n' % (len(out_pixels[0]), len(out_pixels)))
803 
804  if target_padding_size[0] > 0 or target_padding_size[1] > 0:
805 
806  ysize_read_pixels = len(pixels)
807  nodata_value = fetch_band_nodata(band)
808 
809  # Apply columns padding
810  pad_cols = numpy.array([nodata_value] * target_padding_size[0])
811  for row in range (0, ysize_read_pixels):
812  out_line = numpy.append(pixels[row], pad_cols)
813  out_pixels[row] = out_line
814 
815  # Fill rows padding with nodata value
816  for row in range(ysize_read_pixels, ysize_read_pixels + target_padding_size[1]):
817  out_pixels[row].fill(nodata_value)
818  else:
819  out_pixels = pixels
820 
821  # XXX: Use for debugging only
822  #dump_block_numpy(out_pixels)
823 
824  hexwkb = binascii.hexlify(out_pixels)
825 
826  check_hex(hexwkb)
827  return hexwkb
828 
def check_hex(hex, bytes_size=None)
def pt2numpy(pt)
def logit(msg)
def calculate_block_pad_size(band, xoff, yoff, block_size)
def fetch_band_nodata(band, default=0)
def wkblify(fmt, data)
def wkblify_band(options, band, level, xoff, yoff, read_block_size, block_size, infile, bandidx)

References calculate_block_pad_size(), check_hex(), fetch_band_nodata(), genraster.fill, logit(), pt2numpy(), and wkblify().

Referenced by wkblify_raster_level().

Here is the call graph for this function:
Here is the caller graph for this function: