750 def wkblify_band(options, band, level, xoff, yoff, read_block_size, block_size, infile, bandidx):
751 """Writes band of given GDAL dataset into HEX-encoded WKB for WKT Raster output."""
752 assert band
is not None,
"Error: Missing GDAL raster band"
762 hexwkb +=
wkblify(
'B', bandidx - 1)
763 filepath = os.path.abspath(infile.replace(
'\\',
'\\\\'))
764 logit(
'MSG: Out-db raster path=%s\n' % filepath)
765 hexwkb +=
wkblify(
str(len(filepath)) +
's', filepath)
773 valid_read_block_size = ( read_block_size[0] - read_padding_size[0],
774 read_block_size[1] - read_padding_size[1] )
777 if read_padding_size[0] > 0
or read_padding_size[1] > 0:
778 target_block_size = (valid_read_block_size[0] / level, valid_read_block_size[1] / level)
779 target_padding_size = (read_padding_size[0] / level, read_padding_size[1] / level)
781 target_block_size = block_size
782 target_padding_size = ( 0, 0 )
784 logit(
'MSG: Normalize read_block=%s for level=%d to valid_read_block=%s with padding=%s\n' % \
785 (read_block_size, level, valid_read_block_size, read_padding_size))
786 logit(
'MSG: Normalize target_block=%s for level=%d to valid_target_block=%s with padding=%s\n' % \
787 (block_size, level, target_block_size, target_padding_size))
788 logit(
'MSG: ReadAsArray( %d, %d, %s, %s)\n' % \
789 (xoff, yoff,
str(valid_read_block_size),
str(target_block_size)))
791 assert valid_read_block_size[0] > 0
and valid_read_block_size[1] > 0
792 assert target_block_size[0] > 0
and target_block_size[1] > 0
794 pixels = band.ReadAsArray(xoff, yoff, valid_read_block_size[0], valid_read_block_size[1],
795 target_block_size[0], target_block_size[1])
800 out_pixels = numpy.zeros((block_size[1], block_size[0]),
pt2numpy(band.DataType))
802 logit(
'MSG: Read valid source:\t%d x %d\n' % (len(pixels[0]), len(pixels)))
803 logit(
'MSG: Write into block:\t%d x %d\n' % (len(out_pixels[0]), len(out_pixels)))
805 if target_padding_size[0] > 0
or target_padding_size[1] > 0:
807 ysize_read_pixels = len(pixels)
811 pad_cols = numpy.array([nodata_value] * target_padding_size[0])
812 for row
in range (0, ysize_read_pixels):
813 out_line = numpy.append(pixels[row], pad_cols)
814 out_pixels[row] = out_line
817 for row
in range(ysize_read_pixels, ysize_read_pixels + target_padding_size[1]):
818 out_pixels[row].
fill(nodata_value)
825 hexwkb = binascii.hexlify(out_pixels)
def check_hex(hex, bytes_size=None)
def calculate_block_pad_size(band, xoff, yoff, block_size)
def fetch_band_nodata(band, default=0)
def wkblify_band(options, band, level, xoff, yoff, read_block_size, block_size, infile, bandidx)