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" 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)
772 valid_read_block_size = ( read_block_size[0] - read_padding_size[0],
773 read_block_size[1] - read_padding_size[1] )
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)
780 target_block_size = block_size
781 target_padding_size = ( 0, 0 )
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)))
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
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])
799 out_pixels = numpy.zeros((block_size[1], block_size[0]),
pt2numpy(band.DataType))
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)))
804 if target_padding_size[0] > 0
or target_padding_size[1] > 0:
806 ysize_read_pixels = len(pixels)
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
816 for row
in range(ysize_read_pixels, ysize_read_pixels + target_padding_size[1]):
817 out_pixels[row].
fill(nodata_value)
824 hexwkb = binascii.hexlify(out_pixels)
def calculate_block_pad_size(band, xoff, yoff, block_size)
def wkblify_band(options, band, level, xoff, yoff, read_block_size, block_size, infile, bandidx)
def fetch_band_nodata(band, default=0)
def check_hex(hex, bytes_size=None)