Version 8 (modified by pbaumann, 4 years ago) (diff)


Encode function in rasql

The encode() function allows to export 2D MDDs to various formats as supported by the GDAL library. This function has the following signature:

  encode( mddExpr, format, formatParams? )



This is an expression that must evaluate to an 2D MDD object. Supported is encoding of single-band MDDs of any type, and multi-band MDDs where all bands have to be of the same type.


This is a string parameter (has to be in quotes in the query) that indicates to which format should the MDD be encoded. It has to be the format ID that GDAL understands, i.e. one of the IDs that gdal_translate outputs. For example:

$ gdal_translate

GDAL 1.9.0, released 2011/12/29

The following format drivers are configured and support output:
  VRT: Virtual Raster
  GTiff: GeoTIFF
  NITF: National Imagery Transmission Format
  HFA: Erdas Imagine Images (.img)

The identifiers in the first column above (VRT, GTiff, etc.) are the accepted values. For a full list of the formats supported by GDAL and respective codes see


This optional string parameter allows to pass format-specific options, as well as generic parameters like a geo-referencing bounding box and CRS. The parameters have to be fit into one string (quoted in the query) in the following format:


Note that both the key and the value are case-sensitive.

Parameters that apply to each format

  • xmin, ymin, xmax, ymax for specifying the bounding box;
  • metadata for any extra metadata that should be added to the output file;
  • nodata allows to give a list of nodata values for each band separated by a comma, e.g. "nodata=119,208,248;" will set the blue color of the sample rasdaman image rgb to transparent; if only one value is given it will be set to all bands;
  • crs, which can accept any of these CRS representations (reference):
  1. Well Known Text definition
  2. "EPSG:n"
  3. "EPSGA:n"
  4. "AUTO:proj_id,unit_id,lon0,lat0" indicating OGC WMS auto projections
  5. "urn:ogc:def:crs:EPSG::n" indicating OGC URNs (deprecated by OGC)
  6. PROJ.4 definitions
  7. well known name, such as NAD27, NAD83, WGS84 or WGS72.
  8. WKT in ESRI format, prefixed with "ESRI::"
  9. "IGNF:xxx" - "+init=IGNF:xxx"

The bleeding-edge of GDAL also supports OGC CRS URLs (patch provided by DM).

Further format-specific parameters are listed on the respective format pages, e.g. GeoTIFF for example would support an INTERLEAVE=[BAND,PIXEL] parameter.


The result from the encode() function is a 1D MDD of type char, which is the MDD encoded to the target format. In other words, encode() behaves same as png(), netcdf(), and the other convertor function in rasdaman.


The below query will encode a 2D slice (out of the 3D collection COLL) to GeoTIFF, setting the bounding box and crs appropriately, and with the band interleaving (default is pixel):

rasql -q 'select encode( c[0, *:*, *:*], "GTiff", "xmin=25;ymin=-40;xmax=75;ymax=75;crs=EPSG:4326;INTERLEAVE=BAND;metadata=\"some metadata\"" ) from COLL as c' --out file