PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 670 of file raster2pgsql.py.

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

Referenced by wkblify_raster_level().

670 def 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 is not None, "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  ### Endiannes
695  hexwkb += wkblify('B', options.endian)
696  ### Version
697  hexwkb += wkblify('H', options.version)
698  ### Number of bands
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  ### Georeference
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  ### Number of columns and rows
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 
def calculate_geoxy(gt, xy)
def wkblify(fmt, data)
def wkblify_raster_header
def get_gdal_geotransform(ds)
def logit(msg)

Here is the call graph for this function:

Here is the caller graph for this function: