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

◆ wkblify_raster_header()

raster2pgsql.wkblify_raster_header (   options,
  ds,
  level,
  ulp,
  xsize = None,
  ysize = None 
)
Writes WKT Raster header based on given GDAL into HEX-encoded WKB.

Definition at line 670 of file raster2pgsql.py.

670def wkblify_raster_header(options, ds, level, ulp, xsize = None, ysize = None):
671 """Writes WKT Raster header based on given GDAL into HEX-encoded WKB."""
672 assert ds is not None, "Error: Missing GDAL dataset"
673 assert level >= 1
674 assert len(ulp) == 2, "Error: invalid upper-left corner"
675
676 if xsize is None or ysize is None:
677 assert xsize is None and ysize is None
678 xsize = ds.RasterXSize
679 ysize = ds.RasterYSize
680
681 # Collect GeoReference information
682 gt = get_gdal_geotransform(ds)
683 ul = calculate_geoxy(gt, (ulp[0], ulp[1]))
684 rt_ip = ( ul[0], ul[1] )
685 rt_skew = ( gt[2], gt[4] )
686 rt_scale = ( gt[1] * level, gt[5] * level )
687
688 # TODO: Any way to lookup for SRID based on SRS in WKT?
689 #srs = osr.SpatialReference()
690 #srs.ImportFromWkt(ds.GetProjection())
691
692 # Burn input raster as WKTRaster WKB format
693 hexwkb = ''
694
695 hexwkb += wkblify('B', options.endian)
696
697 hexwkb += wkblify('H', options.version)
698
699 if options.band is not None and options.band > 0:
700 hexwkb += wkblify('H', 1)
701 else:
702 hexwkb += wkblify('H', ds.RasterCount)
703 check_hex(hexwkb, 5)
704
705 hexwkb += wkblify('d', rt_scale[0])
706 hexwkb += wkblify('d', rt_scale[1])
707 hexwkb += wkblify('d', rt_ip[0])
708 hexwkb += wkblify('d', rt_ip[1])
709 hexwkb += wkblify('d', rt_skew[0])
710 hexwkb += wkblify('d', rt_skew[1])
711 hexwkb += wkblify('i', options.srid)
712 check_hex(hexwkb, 57)
713
714 hexwkb += wkblify('H', xsize)
715 hexwkb += wkblify('H', ysize)
716 check_hex(hexwkb, 61)
717
718 logit("MSG: Georeference: px = %s -> ul = %s \tresolution = %s \trotation = %s\n" \
719 % (str(ulp), str(rt_ip), str(rt_scale), str(rt_skew)))
720 return hexwkb
721
#define str(s)