PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ wkblify_raster_level()

def raster2pgsql.wkblify_raster_level (   options,
  ds,
  level,
  band_range,
  infile,
  i 
)

Definition at line 829 of file raster2pgsql.py.

References calculate_bounding_box(), calculate_grid_size(), check_hex(), collect_nodata_values(), collect_pixel_types(), get_gdal_geotransform(), logit(), make_sql_addrastercolumn(), make_sql_create_table(), make_sql_insert_raster(), make_sql_register_overview(), make_sql_schema_table_names(), parse_block_size(), wkblify_band(), wkblify_band_header(), and wkblify_raster_header().

Referenced by wkblify_raster().

829 def wkblify_raster_level(options, ds, level, band_range, infile, i):
830  assert ds is not None
831  assert level >= 1
832  assert len(band_range) == 2
833 
834  band_from = band_range[0]
835  band_to = band_range[1]
836 
837  # Collect raster and block dimensions
838  raster_size = ( ds.RasterXSize, ds.RasterYSize )
839  if options.block_size is not None:
840  block_size = parse_block_size(options)
841  read_block_size = ( block_size[0] * level, block_size[1] * level)
842  grid_size = calculate_grid_size(raster_size, read_block_size)
843  else:
844  block_size = raster_size # Whole raster as a single block
845  read_block_size = block_size
846  grid_size = (1, 1)
847 
848  logit("MSG: Processing raster=%s using read_block_size=%s block_size=%s of grid=%s in level=%d\n" % \
849  (str(raster_size), str(read_block_size), str(block_size), str(grid_size), level))
850 
851  # Register base raster in RASTER_COLUMNS - SELECT AddRasterColumn();
852  if level == 1:
853  if i == 0 and options.create_table:
854  gt = get_gdal_geotransform(ds)
855  pixel_size = ( gt[1], gt[5] )
856  pixel_types = collect_pixel_types(ds, band_from, band_to)
857  nodata_values = collect_nodata_values(ds, band_from, band_to)
858  extent = calculate_bounding_box(ds, gt)
859  sql = make_sql_addrastercolumn(options, pixel_types, nodata_values,
860  pixel_size, block_size, extent)
861  options.output.write(sql)
862  gen_table = options.table
863 
864  else:
865  # Create overview table and register in RASTER_OVERVIEWS
866 
867  # CREATE TABLE o_<LEVEL>_<NAME> ( rid serial, options.column RASTER )
868  schema_table_names = make_sql_schema_table_names(options.table)
869  level_table_name = 'o_' + str(level) + '_' + schema_table_names[1]
870  level_table = schema_table_names[0] + '.' + level_table_name
871  if i == 0:
872  sql = make_sql_create_table(options, level_table, True)
873  options.output.write(sql)
874  sql = make_sql_register_overview(options, level_table_name, level)
875  options.output.write(sql)
876  gen_table = level_table
877 
878  # Write (original) raster to hex binary output
879  tile_count = 0
880  hexwkb = ''
881 
882  for ycell in range(0, grid_size[1]):
883  for xcell in range(0, grid_size[0]):
884 
885  xoff = xcell * read_block_size[0]
886  yoff = ycell * read_block_size[1]
887 
888  logit("MSG: --------- CELL #%04d\tindex = %d x %d\tdim = (%d x %d)\t(%d x %d) \t---------\n" % \
889  (tile_count, xcell, ycell, xoff, yoff, xoff + read_block_size[0], yoff + read_block_size[1]))
890 
891  if options.block_size is not None:
892  hexwkb = '' # Reset buffer as single INSERT per tile is generated
893  hexwkb += wkblify_raster_header(options, ds, level, (xoff, yoff),
894  block_size[0], block_size[1])
895  else:
896  hexwkb += wkblify_raster_header(options, ds, level, (xoff, yoff))
897 
898  for b in range(band_from, band_to):
899  band = ds.GetRasterBand(b)
900  assert band is not None, "Missing GDAL raster band %d" % b
901  logit("MSG: Band %d\n" % b)
902 
903  hexwkb += wkblify_band_header(options, band)
904  hexwkb += wkblify_band(options, band, level, xoff, yoff, read_block_size, block_size, infile, b)
905 
906  # INSERT INTO
907  check_hex(hexwkb) # TODO: Remove to not to decrease performance
908  sql = make_sql_insert_raster(gen_table, options.column, hexwkb, options.filename, infile)
909  options.output.write(sql)
910 
911  tile_count = tile_count + 1
912 
913  return (gen_table, tile_count)
914 
def make_sql_register_overview(options, ov_table, ov_factor)
def collect_nodata_values(ds, band_from, band_to)
def collect_pixel_types(ds, band_from, band_to)
def parse_block_size(options)
def get_gdal_geotransform(ds)
def wkblify_band(options, band, level, xoff, yoff, read_block_size, block_size, infile, bandidx)
def calculate_bounding_box(ds, gt)
def logit(msg)
def make_sql_create_table(options, table=None, is_overview=False)
def wkblify_band_header(options, band)
def wkblify_raster_level(options, ds, level, band_range, infile, i)
def make_sql_insert_raster(table, rast, hexwkb, insert_filename, file)
def calculate_grid_size(raster_size, block_size)
def make_sql_schema_table_names(schema_table)
def check_hex(hex, bytes_size=None)
def make_sql_addrastercolumn(options, pixeltypes, nodata, pixelsize, blocksize, extent)
def wkblify_raster_header(options, ds, level, ulp, xsize=None, ysize=None)
Here is the call graph for this function:
Here is the caller graph for this function: