PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 751 of file raster2pgsql.py.

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

Referenced by wkblify_raster_level().

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

Here is the call graph for this function:

Here is the caller graph for this function: