PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ wkblify_raster_header()

def 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 668 of file raster2pgsql.py.

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

References calculate_geoxy(), check_hex(), get_gdal_geotransform(), logit(), and wkblify().

Referenced by wkblify_raster_level().

Here is the call graph for this function:
Here is the caller graph for this function: