PostGIS  2.1.10dev-r@@SVN_REVISION@@
def raster2pgsql.wkblify_raster_level (   options,
  ds,
  level,
  band_range,
  infile,
  i 
)

Definition at line 831 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: