PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ wkblify_raster_level()

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

Definition at line 838 of file raster2pgsql.py.

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