Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 7fd7c575020aa78a8e2e309ea8909f43 > files > 420

gdal-1.6.2-6.fc13.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>GDAL: GDAL Virtual Format Tutorial</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2-20100208 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">


<h1><a class="anchor" id="gdal_vrttut">GDAL Virtual Format Tutorial </a></h1><h2><a class="anchor" id="gdal_vrttut_intro">
Introduction</a></h2>
<p>The VRT driver is a format driver for GDAL that allows a virtual GDAL dataset to be composed from other GDAL datasets with repositioning, and algorithms potentially applied as well as various kinds of metadata altered or added. VRT descriptions of datasets can be saved in an XML format normally given the extension .vrt.</p>
<p>An example of a simple .vrt file referring to a 512x512 dataset with one band loaded from utm.tif might look like this:</p>
<div class="fragment"><pre class="fragment">&lt;<a class="code" href="classVRTDataset.html">VRTDataset</a> rasterXSize=<span class="stringliteral">&quot;512&quot;</span> rasterYSize=<span class="stringliteral">&quot;512&quot;</span>&gt;
  &lt;GeoTransform&gt;440720.0, 60.0, 0.0, 3751320.0, 0.0, -60.0&lt;/GeoTransform&gt;
  &lt;<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a> dataType=<span class="stringliteral">&quot;Byte&quot;</span> band=<span class="stringliteral">&quot;1&quot;</span>&gt;
    &lt;ColorInterp&gt;Gray&lt;/ColorInterp&gt;
    &lt;SimpleSource&gt;
      &lt;SourceFilename relativeToVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;utm.tif&lt;/SourceFilename&gt;
      &lt;SourceBand&gt;1&lt;/SourceBand&gt;
      &lt;SrcRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;512&quot;</span> ySize=<span class="stringliteral">&quot;512&quot;</span>/&gt;
      &lt;DstRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;512&quot;</span> ySize=<span class="stringliteral">&quot;512&quot;</span>/&gt;
    &lt;/SimpleSource&gt;
  &lt;/<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a>&gt;
&lt;/<a class="code" href="classVRTDataset.html">VRTDataset</a>&gt;
</pre></div><p>Many aspects of the VRT file are a direct XML encoding of the <a href="gdal_datamodel.html">GDAL Data Model</a> which should be reviewed for understanding of the semantics of various elements.</p>
<p>VRT files can be produced by translating to VRT format. The resulting file can then be edited to modify mappings, add metadata or other purposes. VRT files can also be produced programmatically by various means.</p>
<p>This tutorial will cover the .vrt file format (suitable for users editing .vrt files), and how .vrt files may be created and manipulated programmatically for developers.</p>
<h2><a class="anchor" id="gdal_vrttut_format">
.vrt Format</a></h2>
<p>Virtual files stored on disk are kept in an XML format with the following elements.</p>
<ul>
<li>
<p class="startli"><b><a class="el" href="classVRTDataset.html">VRTDataset</a></b>: This is the root element for the whole GDAL dataset. It must have the attributes rasterXSize and rasterYSize describing the width and height of the dataset in pixels. It may have SRS, GeoTransform, GCPList, Metadata, and <a class="el" href="classVRTRasterBand.html">VRTRasterBand</a> subelements.</p>
<div class="fragment"><pre class="fragment">&lt;<a class="code" href="classVRTDataset.html">VRTDataset</a> rasterXSize=<span class="stringliteral">&quot;512&quot;</span> rasterYSize=<span class="stringliteral">&quot;512&quot;</span>&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>SRS</b>: This element contains the spatial reference system (coordinate system) in OGC WKT format. Note that this must be appropriately escaped for XML, so items like quotes will have the ampersand escape sequences substituted. As as well WKT, and valid input to the SetFromUserInput() method (such as well known GEOGCS names, and PROJ.4 format) is also allowed in the SRS element.</p>
<div class="fragment"><pre class="fragment">  &lt;SRS&gt;PROJCS[&amp;quot;NAD27 / UTM zone 11N&amp;quot;,GEOGCS[&amp;quot;NAD27&amp;quot;,DATUM[&amp;quot;North_American_Datum_1927&amp;quot;,SPHEROID[&amp;quot;Clarke 1866&amp;quot;,6378206.4,294.9786982139006,AUTHORITY[&amp;quot;EPSG&amp;quot;,&amp;quot;7008&amp;quot;]],AUTHORITY[&amp;quot;EPSG&amp;quot;,&amp;quot;6267&amp;quot;]],PRIMEM[&amp;quot;Greenwich&amp;quot;,0],UNIT[&amp;quot;degree&amp;quot;,0.0174532925199433],AUTHORITY[&amp;quot;EPSG&amp;quot;,&amp;quot;4267&amp;quot;]],PROJECTION[&amp;quot;Transverse_Mercator&amp;quot;],PARAMETER[&amp;quot;latitude_of_origin&amp;quot;,0],PARAMETER[&amp;quot;central_meridian&amp;quot;,-117],PARAMETER[&amp;quot;scale_factor&amp;quot;,0.9996],PARAMETER[&amp;quot;false_easting&amp;quot;,500000],PARAMETER[&amp;quot;false_northing&amp;quot;,0],UNIT[&amp;quot;metre&amp;quot;,1,AUTHORITY[&amp;quot;EPSG&amp;quot;,&amp;quot;9001&amp;quot;]],AUTHORITY[&amp;quot;EPSG&amp;quot;,&amp;quot;26711&amp;quot;]]&lt;/SRS&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>GeoTransform</b>: This element contains a six value affine geotransformation for the dataset, mapping between pixel/line coordinates and georeferenced coordinates.</p>
<p></p>
<div class="fragment"><pre class="fragment">  &lt;GeoTransform&gt;440720.0,  60,  0.0,  3751320.0,  0.0, -60.0&lt;/GeoTransform&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>Metadata</b>: This element contains a list of metadata name/value pairs associated with the <a class="el" href="classVRTDataset.html">VRTDataset</a> as a whole, or a <a class="el" href="classVRTRasterBand.html">VRTRasterBand</a>. It has &lt;MDI&gt; (metadata item) subelements which have a "key" attribute and the value as the data of the element.</p>
<div class="fragment"><pre class="fragment">  &lt;Metadata&gt;
    &lt;MDI key=<span class="stringliteral">&quot;md_key&quot;</span>&gt;Metadata value&lt;/MDI&gt;
  &lt;/Metadata&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b><a class="el" href="classVRTRasterBand.html">VRTRasterBand</a></b>: This represents one band of a dataset. It will have a ataType attribute with the type of the pixel data associated with this band (use names Byte, UInt16, Int16, UInt32, Int32, Float32, Float64, CInt16, CInt32, CFloat32 or CFloat64) and the band this element represents (1 based). This element may have Metadata, ColorInterp, NoDataValue, ColorTable, and Description subelements as well as the various kinds of source elements such as SimpleSource. A raster band may have many "sources" indicating where the actual raster data should be fetched from, and how it should be mapped into the raster bands pixel space.</p>
<p class="endli"></p>
</li>
<li>
<p class="startli"><b>ColorInterp</b>: The data of this element should be the name of a color interpretation type. One of Gray, Palette, Red, Green, Blue, Alpha, Hue, Saturation, Lightness, Cyan, Magenta, Yellow, Black, or Unknown.</p>
<p></p>
<div class="fragment"><pre class="fragment">  &lt;ColorInterp&gt;Gray&lt;/ColorInterp&gt;: 
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>NoDataValue</b>: If this element exists a raster band has a nodata value associated with, of the value given as data in the element.</p>
<div class="fragment"><pre class="fragment">  &lt;NoDataValue&gt;-100.0&lt;/NoDataValue&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>ColorTable</b>: This element is parent to a set of Entry elements defining the entries in a color table. Currently only RGBA color tables are supported with c1 being red, c2 being green, c3 being blue and c4 being alpha. The entries are ordered and will be assumed to start from color table entry 0.</p>
<div class="fragment"><pre class="fragment">    &lt;ColorTable&gt;
      &lt;Entry c1=<span class="stringliteral">&quot;0&quot;</span> c2=<span class="stringliteral">&quot;0&quot;</span> c3=<span class="stringliteral">&quot;0&quot;</span> c4=<span class="stringliteral">&quot;255&quot;</span>/&gt;
      &lt;Entry c1=<span class="stringliteral">&quot;145&quot;</span> c2=<span class="stringliteral">&quot;78&quot;</span> c3=<span class="stringliteral">&quot;224&quot;</span> c4=<span class="stringliteral">&quot;255&quot;</span>/&gt;
    &lt;/ColorTable&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>Description</b>: This element contains the optional description of a raster band as it's text value.</p>
<div class="fragment"><pre class="fragment">  &lt;Description&gt;Crop Classification Layer&lt;/Description&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>UnitType</b>: This optional element contains the vertical units for elevation band data. One of "m" for meters or "ft" for feet. Default assumption is meters.</p>
<p></p>
<div class="fragment"><pre class="fragment">  &lt;UnitType&gt;ft&lt;/UnitType&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>Offset</b>: This optional element contains the offset that should be applied when computing "real" pixel values from scaled pixel values on a raster band. The default is 0.0.</p>
<p></p>
<div class="fragment"><pre class="fragment">  &lt;Offset&gt;0.0&lt;/Offset&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>Scale</b>: This optional element contains the scale that should be applied when computing "real" pixel values from scaled pixel values on a raster band. The default is 1.0.</p>
<p></p>
<div class="fragment"><pre class="fragment">  &lt;Scale&gt;0.0&lt;/Scale&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>CategoryNames</b>: This optional element contains a list of Category subelements with the names of the categories for classified raster band. </p>
<p></p>
<div class="fragment"><pre class="fragment">  &lt;CategoryNames&gt;
    &lt;Category&gt;Missing&lt;/Category&gt;
    &lt;Category&gt;Non-Crop&lt;/Category&gt;
    &lt;Category&gt;Wheat&lt;/Category&gt;
    &lt;Category&gt;Corn&lt;/Category&gt;
    &lt;Category&gt;Soybeans&lt;/Category&gt;
  &lt;/CategoryNames&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>SimpleSource</b>: The SimpleSource indicates that raster data should be read from a separate dataset, indicating the dataset, and band to be read from, and how the data should map into this bands raster space. The SimpleSource may have the SourceFilename, SourceBand, SrcRect, and DstRect subelements. The SrcRect element will indicate what rectangle on the indicated source file should be read, and the DstRect element indicates how that rectangle of source data should be mapped into the VRTRasterBands space.</p>
<p>The relativeToVRT attribute on the SourceFilename indicates whether the filename should be interpreted as relative to the .vrt file (value is 1) or not relative to the .vrt file (value is 0). The default is 0.</p>
<p>Some characteristics of the source band can be specified in the optional SourceProperties tag to enable the VRT driver to differ the opening of the source dataset until it really needs to read data from it. This is particularly useful when building VRTs with a big number of source datasets. The needed parameters are the raster dimensions, the size of the blocks and the data type. If the SourceProperties tag is not present, the source dataset will be opened at the same time as the VRT itself.</p>
<div class="fragment"><pre class="fragment">    &lt;SimpleSource&gt;
      &lt;SourceFilename relativeToVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;utm.tif&lt;/SourceFilename&gt;
      &lt;SourceBand&gt;1&lt;/SourceBand&gt;
      &lt;SourceProperties RasterXSize=<span class="stringliteral">&quot;512&quot;</span> RasterYSize=<span class="stringliteral">&quot;512&quot;</span> DataType=<span class="stringliteral">&quot;Byte&quot;</span> BlockXSize=<span class="stringliteral">&quot;128&quot;</span> BlockYSize=<span class="stringliteral">&quot;128&quot;</span>/&gt;
      &lt;SrcRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;512&quot;</span> ySize=<span class="stringliteral">&quot;512&quot;</span>/&gt;
      &lt;DstRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;512&quot;</span> ySize=<span class="stringliteral">&quot;512&quot;</span>/&gt;
    &lt;/SimpleSource&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>AveragedSource</b>: The AveragedSource is derived from the SimpleSource and shares the same properties except that it uses an averaging resampling instead of a nearest neighbour algorithm as in SimpleSource, when the size of the destination rectangle is not the same as the size of the source rectangle</p>
<p class="endli"></p>
</li>
<li>
<p class="startli"><b>ComplexSource</b>: The ComplexSource is derived from the SimpleSource (so it shares the SourceFilename, SourceBand, SrcRect and DestRect elements), but it provides support to rescale and offset the range of the source values. Certain regions of the source can be masked by specifying the NODATA value.</p>
<p>The ComplexSource supports adding a custom lookup table to transform the source values to the destination. The LUT can be specified using the following form:</p>
<div class="fragment"><pre class="fragment">    &lt;LUT&gt;[src value 1]:[dest value 1],[src value 2]:[dest value 2],...&lt;/LUT&gt;
</pre></div><p>The intermediary values are calculated using a linear interpolation between the bounding destination values of the corresponding range.</p>
<p>The ComplexSource supports fetching a color component from a source raster band that has a color table. The ColorTableComponent value is the index of the color component to extract : 1 for the red band, 2 for the green band, 3 for the blue band or 4 for the alpha band.</p>
<p>When transforming the source values the operations are executed in the following order:</p>
<ol>
<li>
Nodata masking </li>
<li>
Color table expansion </li>
<li>
Applying the scale ratio </li>
<li>
Applying the scale offset </li>
<li>
Table lookup </li>
</ol>
<div class="fragment"><pre class="fragment">    &lt;ComplexSource&gt;
      &lt;SourceFilename relativeToVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;utm.tif&lt;/SourceFilename&gt;
      &lt;SourceBand&gt;1&lt;/SourceBand&gt;
      &lt;ScaleOffset&gt;0&lt;/ScaleOffset&gt;
      &lt;ScaleRatio&gt;1&lt;/ScaleRatio&gt;
      &lt;ColorTableComponent&gt;1&lt;/ColorTableComponent&gt;
      &lt;LUT&gt;0:0,2345.12:64,56789.5:128,2364753.02:255&lt;/LUT&gt;
      &lt;NODATA&gt;0&lt;/NODATA&gt;
      &lt;SrcRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;512&quot;</span> ySize=<span class="stringliteral">&quot;512&quot;</span>/&gt;
      &lt;DstRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;512&quot;</span> ySize=<span class="stringliteral">&quot;512&quot;</span>/&gt;
    &lt;/ComplexSource&gt;
</pre></div><p class="endli"></p>
</li>
<li>
<p class="startli"><b>KernelFilteredSource</b>: This is a pixel source derived from the Simple Source (so it shares the SourceFilename, SourceBand, SrcRect and DestRect elements, but it also passes the data through a simple filtering kernel specified with the Kernel element. The Kernel element should have two child elements, Size and Coefs and optionally the boolean attribute normalized (defaults to false=0). The size must always be an odd number, and the Coefs must have Size * Size entries separated by spaces.</p>
<div class="fragment"><pre class="fragment">    &lt;KernelFilteredSource&gt;
      &lt;SourceFilename&gt;/debian/home/warmerda/openev/utm.tif&lt;/SourceFilename&gt;
      &lt;SourceBand&gt;1&lt;/SourceBand&gt;
      &lt;Kernel normalized=<span class="stringliteral">&quot;1&quot;</span>&gt;
        &lt;Size&gt;3&lt;/Size&gt;
        &lt;Coefs&gt;0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111&lt;/Coefs&gt;
      &lt;/Kernel&gt;
    &lt;/KernelFilteredSource&gt;
</pre></div><p class="endli"></p>
</li>
</ul>
<h2><a class="anchor" id="gdal_vrttut_vrt">
.vrt Descriptions for Raw Files</a></h2>
<p>So far we have described how to derive new virtual datasets from existing files supports by GDAL. However, it is also common to need to utilize raw binary raster files for which the regular layout of the data is known but for which no format specific driver exists. This can be accomplished by writing a .vrt file describing the raw file.</p>
<p>For example, the following .vrt describes a raw raster file containing floating point complex pixels in a file called <em>l2p3hhsso.img</em>. The image data starts from the first byte (ImageOffset=0). The byte offset between pixels is 8 (PixelOffset=8), the size of a CFloat32. The byte offset from the start of one line to the start of the next is 9376 bytes (LineOffset=9376) which is the width (1172) times the size of a pixel (8).</p>
<div class="fragment"><pre class="fragment">&lt;<a class="code" href="classVRTDataset.html">VRTDataset</a> rasterXSize=<span class="stringliteral">&quot;1172&quot;</span> rasterYSize=<span class="stringliteral">&quot;1864&quot;</span>&gt;
  &lt;<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a> dataType=<span class="stringliteral">&quot;CFloat32&quot;</span> band=<span class="stringliteral">&quot;1&quot;</span> subClass=<span class="stringliteral">&quot;VRTRawRasterBand&quot;</span>&gt;
    &lt;SourceFilename relativetoVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;l2p3hhsso.img&lt;/SourceFilename&gt;
    &lt;ImageOffset&gt;0&lt;/ImageOffset&gt;
    &lt;PixelOffset&gt;8&lt;/PixelOffset&gt;
    &lt;LineOffset&gt;9376&lt;/LineOffset&gt;
    &lt;ByteOrder&gt;MSB&lt;/ByteOrder&gt;
  &lt;/<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a>&gt;
&lt;/<a class="code" href="classVRTDataset.html">VRTDataset</a>&gt;
</pre></div><p>Some things to note are that the <a class="el" href="classVRTRasterBand.html">VRTRasterBand</a> has a subClass specifier of "VRTRawRasterBand". Also, the <a class="el" href="classVRTRasterBand.html">VRTRasterBand</a> contains a number of previously unseen elements but no "source" information. VRTRawRasterBands may never have sources (ie. SimpleSource), but should contain the following elements in addition to all the normal "metadata" elements previously described which are still supported.</p>
<ul>
<li>
<p class="startli"><b>SourceFilename</b>: The name of the raw file containing the data for this band. The relativeToVRT attribute can be used to indicate if the SourceFilename is relative to the .vrt file (1) or not (0).</p>
<p class="endli"></p>
</li>
<li>
<p class="startli"><b>ImageOffset</b>: The offset in bytes to the beginning of the first pixel of data of this image band. Defaults to zero.</p>
<p class="endli"></p>
</li>
<li>
<p class="startli"><b>PixelOffset</b>: The offset in bytes from the beginning of one pixel and the next on the same line. In packed single band data this will be the size of the <b>dataType</b> in bytes.</p>
<p class="endli"></p>
</li>
<li>
<p class="startli"><b>LineOffset</b>: The offset in bytes from the beginning of one scanline of data and the next scanline of data. In packed single band data this will be PixelOffset * rasterXSize.</p>
<p class="endli"></p>
</li>
<li>
<p class="startli"><b>ByteOrder</b>: Defines the byte order of the data on disk. Either LSB (Least Significant Byte first) such as the natural byte order on Intel x86 systems or MSB (Most Significant Byte first) such as the natural byte order on Motorola or Sparc systems. Defaults to being the local machine order.</p>
<p class="endli"></p>
</li>
</ul>
<p>A few other notes:</p>
<ul>
<li>
<p class="startli">The image data on disk is assumed to be of the same data type as the band <b>dataType</b> of the <a class="el" href="classVRTRawRasterBand.html">VRTRawRasterBand</a>.</p>
<p class="endli"></p>
</li>
<li>
<p class="startli">All the non-source attributes of the <a class="el" href="classVRTRasterBand.html">VRTRasterBand</a> are supported, including color tables, metadata, nodata values, and color interpretation.</p>
<p class="endli"></p>
</li>
<li>
<p class="startli">The <a class="el" href="classVRTRawRasterBand.html">VRTRawRasterBand</a> supports in place update of the raster, whereas the source based <a class="el" href="classVRTRasterBand.html">VRTRasterBand</a> is always read-only.</p>
<p class="endli"></p>
</li>
<li>
<p class="startli">The OpenEV tool includes a File menu option to input parameters describing a raw raster file in a GUI and create the corresponding .vrt file.</p>
<p class="endli"></p>
</li>
<li>
<p class="startli">Multiple bands in the one .vrt file can come from the same raw file. Just ensure that the ImageOffset, PixelOffset, and LineOffset definition for each band is appropriate for the pixels of that particular band.</p>
<p class="endli"></p>
</li>
</ul>
<p>Another example, in this case a 400x300 RGB pixel interleaved image.</p>
<div class="fragment"><pre class="fragment">&lt;<a class="code" href="classVRTDataset.html">VRTDataset</a> rasterXSize=<span class="stringliteral">&quot;400&quot;</span> rasterYSize=<span class="stringliteral">&quot;300&quot;</span>&gt;
  &lt;<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a> dataType=<span class="stringliteral">&quot;Byte&quot;</span> band=<span class="stringliteral">&quot;1&quot;</span> subClass=<span class="stringliteral">&quot;VRTRawRasterBand&quot;</span>&gt;
    &lt;ColorInterp&gt;Red&lt;/ColorInterp&gt;
    &lt;SourceFilename relativetoVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;rgb.raw&lt;/SourceFilename&gt;
    &lt;ImageOffset&gt;0&lt;/ImageOffset&gt;
    &lt;PixelOffset&gt;3&lt;/PixelOffset&gt;
    &lt;LineOffset&gt;1200&lt;/LineOffset&gt;
  &lt;/<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a>&gt;
  &lt;<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a> dataType=<span class="stringliteral">&quot;Byte&quot;</span> band=<span class="stringliteral">&quot;2&quot;</span> subClass=<span class="stringliteral">&quot;VRTRawRasterBand&quot;</span>&gt;
    &lt;ColorInterp&gt;Green&lt;/ColorInterp&gt;
    &lt;SourceFilename relativetoVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;rgb.raw&lt;/SourceFilename&gt;
    &lt;ImageOffset&gt;1&lt;/ImageOffset&gt;
    &lt;PixelOffset&gt;3&lt;/PixelOffset&gt;
    &lt;LineOffset&gt;1200&lt;/LineOffset&gt;
  &lt;/<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a>&gt;
  &lt;<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a> dataType=<span class="stringliteral">&quot;Byte&quot;</span> band=<span class="stringliteral">&quot;3&quot;</span> subClass=<span class="stringliteral">&quot;VRTRawRasterBand&quot;</span>&gt;
    &lt;ColorInterp&gt;Blue&lt;/ColorInterp&gt;
    &lt;SourceFilename relativetoVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;rgb.raw&lt;/SourceFilename&gt;
    &lt;ImageOffset&gt;2&lt;/ImageOffset&gt;
    &lt;PixelOffset&gt;3&lt;/PixelOffset&gt;
    &lt;LineOffset&gt;1200&lt;/LineOffset&gt;
  &lt;/<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a>&gt;
&lt;/<a class="code" href="classVRTDataset.html">VRTDataset</a>&gt;
</pre></div><h2><a class="anchor" id="gdal_vrttut_creation">
Programatic Creation of VRT Datasets</a></h2>
<p>The VRT driver supports several methods of creating VRT datasets. As of GDAL 1.2.0 the <a class="el" href="vrtdataset_8h_source.html">vrtdataset.h</a> include file should be installed with the core GDAL include files, allowing direct access to the VRT classes. However, even without that most capabilities remain available through standard GDAL interfaces.</p>
<p>To create a VRT dataset that is a clone of an existing dataset use the CreateCopy() method. For example to clone utm.tif into a wrk.vrt file in C++ the following could be used:</p>
<div class="fragment"><pre class="fragment">  <a class="code" href="classGDALDriver.html" title="Format specific driver.">GDALDriver</a> *poDriver = (<a class="code" href="classGDALDriver.html" title="Format specific driver.">GDALDriver</a> *) <a class="code" href="gdal_8h.html#ae8ae868eef1e4773283d137b0a1adfc4">GDALGetDriverByName</a>( <span class="stringliteral">&quot;VRT&quot;</span> );
  <a class="code" href="classGDALDataset.html" title="A set of associated raster bands, usually from one file.">GDALDataset</a> *poSrcDS, *poVRTDS;

  poSrcDS = (<a class="code" href="classGDALDataset.html" title="A set of associated raster bands, usually from one file.">GDALDataset</a> *) <a class="code" href="gdal_8h.html#a347b1025e090c5238196b658463addd3">GDALOpenShared</a>( <span class="stringliteral">&quot;utm.tif&quot;</span>, <a class="code" href="gdal_8h.html#a045e3967c208993f70257bfd40c9f1d7a5a021a550b9d5640307d3c0e7e35b732">GA_ReadOnly</a> );

  poVRTDS = 
    poDriver-&gt;<a class="code" href="classGDALDriver.html#ad0f7a33b0bd7f9d685bbd90d04fde629">CreateCopy</a>( <span class="stringliteral">&quot;wrk.vrt&quot;</span>, poSrcDS, FALSE, NULL, NULL, NULL );
  <span class="keyword">delete</span> poVRTDS;
  <span class="keyword">delete</span> poSrcDS;
</pre></div><p>To create a virtual copy of a dataset with some attributes added or changed such as metadata or coordinate system that are often hard to change on other formats, you might do the following. In this case, the virtual dataset is created "in memory" only by virtual of creating it with an empty filename, and then used as a modified source to pass to a CreateCopy() written out in TIFF format.</p>
<div class="fragment"><pre class="fragment">  poVRTDS = poDriver-&gt;<a class="code" href="classGDALDriver.html#ad0f7a33b0bd7f9d685bbd90d04fde629">CreateCopy</a>( <span class="stringliteral">&quot;&quot;</span>, poSrcDS, FALSE, NULL, NULL, NULL );

  poVRTDS-&gt;<a class="code" href="classGDALMajorObject.html#a3e157735f6ff6e11935c2a2dbcc24c92">SetMetadataItem</a>( <span class="stringliteral">&quot;SourceAgency&quot;</span>, <span class="stringliteral">&quot;United States Geological Survey&quot;</span>);
  poVRTDS-&gt;<a class="code" href="classGDALMajorObject.html#a3e157735f6ff6e11935c2a2dbcc24c92">SetMetadataItem</a>( <span class="stringliteral">&quot;SourceDate&quot;</span>, <span class="stringliteral">&quot;July 21, 2003&quot;</span> );

  poVRTDS-&gt;<a class="code" href="classGDALDataset.html#ad96adcf07f2979ad176e37a7f8638fb6">GetRasterBand</a>( 1 )-&gt;<a class="code" href="classGDALRasterBand.html#ac6f081d253dee55c372e54cfdd8f05a6">SetNoDataValue</a>( -999.0 );

  <a class="code" href="classGDALDriver.html" title="Format specific driver.">GDALDriver</a> *poTIFFDriver = (<a class="code" href="classGDALDriver.html" title="Format specific driver.">GDALDriver</a> *) <a class="code" href="gdal_8h.html#ae8ae868eef1e4773283d137b0a1adfc4">GDALGetDriverByName</a>( <span class="stringliteral">&quot;GTiff&quot;</span> );
  <a class="code" href="classGDALDataset.html" title="A set of associated raster bands, usually from one file.">GDALDataset</a> *poTiffDS;

  poTiffDS = 
    poTIFFDriver-&gt;<a class="code" href="classGDALDriver.html#ad0f7a33b0bd7f9d685bbd90d04fde629">CreateCopy</a>( <span class="stringliteral">&quot;wrk.tif&quot;</span>, poVRTDS, FALSE, NULL, NULL, NULL );
  <span class="keyword">delete</span> poTiffDS;
</pre></div><p>In this example a virtual dataset is created with the Create() method, and adding bands and sources programmatically, but still via the "generic" API. A special attribute of VRT datasets is that sources can be added to the bands by passing the XML describing the source into SetMetadata() on the special domain target "new_vrt_sources". The domain target "vrt_sources" may also be used, in which case any existing sources will be discarded before adding the new ones. In this example we construct a simple averaging filter source instead of using the simple source.</p>
<div class="fragment"><pre class="fragment">  <span class="comment">// construct XML for simple 3x3 average filter kernel source.</span>
  <span class="keyword">const</span> <span class="keywordtype">char</span> *pszFilterSourceXML  =
<span class="stringliteral">&quot;&lt;KernelFilteredSource&gt;&quot;</span>
<span class="stringliteral">&quot;  &lt;SourceFilename&gt;utm.tif&lt;/SourceFilename&gt;1&lt;SourceBand&gt;1&lt;/SourceBand&gt;&quot;</span>
<span class="stringliteral">&quot;  &lt;Kernel&gt;&quot;</span>
<span class="stringliteral">&quot;    &lt;Size&gt;3&lt;/Size&gt;&quot;</span>
<span class="stringliteral">&quot;    &lt;Coefs&gt;0.111 0.111 0.111 0.111 0.111 0.111 0.111 0.111 0.111&lt;/Coefs&gt;&quot;</span>
<span class="stringliteral">&quot;  &lt;/Kernel&gt;&quot;</span>
<span class="stringliteral">&quot;&lt;/KernelFilteredSource&gt;&quot;</span>;

  <span class="comment">// Create the virtual dataset. </span>
  poVRTDS = poDriver-&gt;<a class="code" href="classGDALDriver.html#a191dc4a5c8f48c1dea4083c711b8f7c4">Create</a>( <span class="stringliteral">&quot;&quot;</span>, 512, 512, 1, <a class="code" href="gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4a38a66c26861d368e95ba42106ee3ab92">GDT_Byte</a>, NULL );
  poVRTDS-&gt;<a class="code" href="classGDALDataset.html#ad96adcf07f2979ad176e37a7f8638fb6">GetRasterBand</a>(1)-&gt;<a class="code" href="classGDALMajorObject.html#a3e157735f6ff6e11935c2a2dbcc24c92">SetMetadataItem</a>(<span class="stringliteral">&quot;source_0&quot;</span>,pszFilterSourceXML<span class="stringliteral">&quot;,</span>
<span class="stringliteral">                                             &quot;</span>new_vrt_sources<span class="stringliteral">&quot;);</span>
</pre></div><p>A more general form of this that will produce a 3x3 average filtered clone of any input datasource might look like the following. In this case we deliberately set the filtered datasource as in the "vrt_sources" domain to override the SimpleSource created by the CreateCopy() method. The fact that we used CreateCopy() ensures that all the other metadata, georeferencing and so forth is preserved from the source dataset ... the only thing we are changing is the data source for each band.</p>
<div class="fragment"><pre class="fragment">  <span class="keywordtype">int</span>   nBand;
  <a class="code" href="classGDALDriver.html" title="Format specific driver.">GDALDriver</a> *poDriver = (<a class="code" href="classGDALDriver.html" title="Format specific driver.">GDALDriver</a> *) <a class="code" href="gdal_8h.html#ae8ae868eef1e4773283d137b0a1adfc4">GDALGetDriverByName</a>( <span class="stringliteral">&quot;VRT&quot;</span> );
  <a class="code" href="classGDALDataset.html" title="A set of associated raster bands, usually from one file.">GDALDataset</a> *poSrcDS, *poVRTDS;

  poSrcDS = (<a class="code" href="classGDALDataset.html" title="A set of associated raster bands, usually from one file.">GDALDataset</a> *) <a class="code" href="gdal_8h.html#a347b1025e090c5238196b658463addd3">GDALOpenShared</a>( pszSourceFilename, <a class="code" href="gdal_8h.html#a045e3967c208993f70257bfd40c9f1d7a5a021a550b9d5640307d3c0e7e35b732">GA_ReadOnly</a> );

  poVRTDS = poDriver-&gt;<a class="code" href="classGDALDriver.html#ad0f7a33b0bd7f9d685bbd90d04fde629">CreateCopy</a>( <span class="stringliteral">&quot;&quot;</span>, poSrcDS, FALSE, NULL, NULL, NULL );

  <span class="keywordflow">for</span>( nBand = 1; nBand &lt;= poVRTDS-&gt;<a class="code" href="classGDALDataset.html#a01ed7cc3d711651470212dac01af69a0">GetRasterCount</a>(); nBand++ )
  {
      <span class="keywordtype">char</span> szFilterSourceXML[10000];

      <a class="code" href="classGDALRasterBand.html" title="A single raster band (or channel).">GDALRasterBand</a> *poBand = poVRTDS-&gt;<a class="code" href="classGDALDataset.html#ad96adcf07f2979ad176e37a7f8638fb6">GetRasterBand</a>( nBand );

      sprintf( szFilterSourceXML, 
        <span class="stringliteral">&quot;&lt;KernelFilteredSource&gt;&quot;</span>
        <span class="stringliteral">&quot;  &lt;SourceFilename&gt;%s&lt;/SourceFilename&gt;1&lt;SourceBand&gt;%d&lt;/SourceBand&gt;&quot;</span>
        <span class="stringliteral">&quot;  &lt;Kernel&gt;&quot;</span>
        <span class="stringliteral">&quot;    &lt;Size&gt;3&lt;/Size&gt;&quot;</span>
        <span class="stringliteral">&quot;    &lt;Coefs&gt;0.111 0.111 0.111 0.111 0.111 0.111 0.111 0.111 0.111&lt;/Coefs&gt;&quot;</span>
        <span class="stringliteral">&quot;  &lt;/Kernel&gt;&quot;</span>
        <span class="stringliteral">&quot;&lt;/KernelFilteredSource&gt;&quot;</span>, 
        pszSourceFilename, nBand );
        
      poBand-&gt;<a class="code" href="classGDALMajorObject.html#a3e157735f6ff6e11935c2a2dbcc24c92">SetMetadataItem</a>( <span class="stringliteral">&quot;source_0&quot;</span>, szFilterSourceXML, <span class="stringliteral">&quot;vrt_sources&quot;</span> );
  }
</pre></div><h2>Using Derived Bands</h2>
<p>A specialized type of band is a 'derived' band which derives its pixel information from its source bands. With this type of band you must also specify a pixel function, which has the responsibility of generating the output raster. Pixel functions are created by an application and then registered with GDAL using a unique key.</p>
<p>Using derived bands you can create VRT datasets that manipulate bands on the fly without having to create new band files on disk. For example, you might want to generate a band using four source bands from a nine band input dataset (x0, x3, x4, and x8):</p>
<div class="fragment"><pre class="fragment">  band_value = sqrt((x3*x3+x4*x4)/(x0*x8));
</pre></div><p>You could write the pixel function to compute this value and then register it with GDAL with the name "MyFirstFunction". Then, the following VRT XML could be used to display this derived band:</p>
<div class="fragment"><pre class="fragment">&lt;<a class="code" href="classVRTDataset.html">VRTDataset</a> rasterXSize=<span class="stringliteral">&quot;1000&quot;</span> rasterYSize=<span class="stringliteral">&quot;1000&quot;</span>&gt;
  &lt;<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a> dataType=<span class="stringliteral">&quot;Float32&quot;</span> band=<span class="stringliteral">&quot;1&quot;</span> subClass=<span class="stringliteral">&quot;VRTDerivedRasterBand&quot;</span>&gt;&gt;
    &lt;Description&gt;Magnitude&lt;/Description&gt;
    &lt;PixelFunctionType&gt;MyFirstFunction&lt;/PixelFunctionType&gt;
    &lt;SimpleSource&gt;
      &lt;SourceFilename relativeToVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;nine_band.dat&lt;/SourceFilename&gt;
      &lt;SourceBand&gt;1&lt;/SourceBand&gt;
      &lt;SrcRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;1000&quot;</span> ySize=<span class="stringliteral">&quot;1000&quot;</span>/&gt;
      &lt;DstRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;1000&quot;</span> ySize=<span class="stringliteral">&quot;1000&quot;</span>/&gt;
    &lt;/SimpleSource&gt;
    &lt;SimpleSource&gt;
      &lt;SourceFilename relativeToVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;nine_band.dat&lt;/SourceFilename&gt;
      &lt;SourceBand&gt;4&lt;/SourceBand&gt;
      &lt;SrcRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;1000&quot;</span> ySize=<span class="stringliteral">&quot;1000&quot;</span>/&gt;
      &lt;DstRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;1000&quot;</span> ySize=<span class="stringliteral">&quot;1000&quot;</span>/&gt;
    &lt;/SimpleSource&gt;
    &lt;SimpleSource&gt;
      &lt;SourceFilename relativeToVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;nine_band.dat&lt;/SourceFilename&gt;
      &lt;SourceBand&gt;5&lt;/SourceBand&gt;
      &lt;SrcRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;1000&quot;</span> ySize=<span class="stringliteral">&quot;1000&quot;</span>/&gt;
      &lt;DstRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;1000&quot;</span> ySize=<span class="stringliteral">&quot;1000&quot;</span>/&gt;
    &lt;/SimpleSource&gt;
    &lt;SimpleSource&gt;
      &lt;SourceFilename relativeToVRT=<span class="stringliteral">&quot;1&quot;</span>&gt;nine_band.dat&lt;/SourceFilename&gt;
      &lt;SourceBand&gt;9&lt;/SourceBand&gt;
      &lt;SrcRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;1000&quot;</span> ySize=<span class="stringliteral">&quot;1000&quot;</span>/&gt;
      &lt;DstRect xOff=<span class="stringliteral">&quot;0&quot;</span> yOff=<span class="stringliteral">&quot;0&quot;</span> xSize=<span class="stringliteral">&quot;1000&quot;</span> ySize=<span class="stringliteral">&quot;1000&quot;</span>/&gt;
    &lt;/SimpleSource&gt;
  &lt;/<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a>&gt;
&lt;/<a class="code" href="classVRTDataset.html">VRTDataset</a>&gt;
</pre></div><p>In addition to the subclass specification (<a class="el" href="classVRTDerivedRasterBand.html">VRTDerivedRasterBand</a>) and the PixelFunctionType value, there is another new parameter that can come in handy: SourceTransferType. Typically the source rasters are obtained using the data type of the derived band. There might be times, however, when you want the pixel function to have access to higher resolution source data than the data type being generated. For example, you might have a derived band of type "Float", which takes a single source of type "CFloat32" or "CFloat64", and returns the imaginary portion. To accomplish this, set the SourceTransferType to "CFloat64". Otherwise the source would be converted to "Float" prior to calling the pixel function, and the imaginary portion would be lost.</p>
<div class="fragment"><pre class="fragment">&lt;<a class="code" href="classVRTDataset.html">VRTDataset</a> rasterXSize=<span class="stringliteral">&quot;1000&quot;</span> rasterYSize=<span class="stringliteral">&quot;1000&quot;</span>&gt;
  &lt;<a class="code" href="classVRTRasterBand.html">VRTRasterBand</a> dataType=<span class="stringliteral">&quot;Float32&quot;</span> band=<span class="stringliteral">&quot;1&quot;</span> subClass=<span class="stringliteral">&quot;VRTDerivedRasterBand&quot;</span>&gt;&gt;
    &lt;Description&gt;Magnitude&lt;/Description&gt;
    &lt;PixelFunctionType&gt;MyFirstFunction&lt;/PixelFunctionType&gt;
    &lt;SourceTransferType&gt;<span class="stringliteral">&quot;CFloat64&quot;</span>&lt;/SourceTransferType&gt;
    ...
</pre></div><h3>Writing Pixel Functions</h3>
<p>To register this function with GDAL (prior to accessing any VRT datasets with derived bands that use this function), an application calls GDALAddDerivedBandPixelFunc with a key and a GDALDerivedPixelFunc:</p>
<div class="fragment"><pre class="fragment">    <a class="code" href="gdal_8h.html#ae27e95ca0d86b0775d5c379e954828cf">GDALAddDerivedBandPixelFunc</a>(<span class="stringliteral">&quot;MyFirstFunction&quot;</span>, TestFunction);
</pre></div><p>A good time to do this is at the beginning of an application when the GDAL drivers are registered.</p>
<p>GDALDerivedPixelFunc is defined with a signature similar to IRasterIO:</p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>papoSources</em>&nbsp;</td><td>A pointer to packed rasters; one per source. The datatype of all will be the same, specified in the eSrcType parameter.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>nSources</em>&nbsp;</td><td>The number of source rasters.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>pData</em>&nbsp;</td><td>The buffer into which the data should be read, or from which it should be written. This buffer must contain at least nBufXSize * nBufYSize words of type eBufType. It is organized in left to right, top to bottom pixel order. Spacing is controlled by the nPixelSpace, and nLineSpace parameters.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>nBufXSize</em>&nbsp;</td><td>The width of the buffer image into which the desired region is to be read, or from which it is to be written.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>nBufYSize</em>&nbsp;</td><td>The height of the buffer image into which the desired region is to be read, or from which it is to be written.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>eSrcType</em>&nbsp;</td><td>The type of the pixel values in the papoSources raster array.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>eBufType</em>&nbsp;</td><td>The type of the pixel values that the pixel function must generate in the pData data buffer.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>nPixelSpace</em>&nbsp;</td><td>The byte offset from the start of one pixel value in pData to the start of the next pixel value within a scanline. If defaulted (0) the size of the datatype eBufType is used.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>nLineSpace</em>&nbsp;</td><td>The byte offset from the start of one scanline in pData to the start of the next.</td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>CE_Failure on failure, otherwise CE_None.</dd></dl>
<div class="fragment"><pre class="fragment"><span class="keyword">typedef</span> CPLErr
(*GDALDerivedPixelFunc)(<span class="keywordtype">void</span> **papoSources, <span class="keywordtype">int</span> nSources, <span class="keywordtype">void</span> *pData,
                        <span class="keywordtype">int</span> nXSize, <span class="keywordtype">int</span> nYSize,
                        <a class="code" href="gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4">GDALDataType</a> eSrcType, <a class="code" href="gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4">GDALDataType</a> eBufType,
                        <span class="keywordtype">int</span> nPixelSpace, <span class="keywordtype">int</span> nLineSpace);
</pre></div><p>The following is an implementation of the pixel function:</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;<a class="code" href="gdal_8h.html">gdal.h</a>&quot;</span>

CPLErr TestFunction(<span class="keywordtype">void</span> **papoSources, <span class="keywordtype">int</span> nSources, <span class="keywordtype">void</span> *pData,
                    <span class="keywordtype">int</span> nXSize, <span class="keywordtype">int</span> nYSize,
                    <a class="code" href="gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4">GDALDataType</a> eSrcType, <a class="code" href="gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4">GDALDataType</a> eBufType,
                    <span class="keywordtype">int</span> nPixelSpace, <span class="keywordtype">int</span> nLineSpace)
{

    <span class="keywordtype">int</span> ii, iLine, iCol;
    <span class="keywordtype">double</span> pix_val;
    <span class="keywordtype">double</span> x0, x3, x4, x8;

    <span class="comment">/* ---- Init ---- */</span>
    <span class="keywordflow">if</span> (nSources != 4) <span class="keywordflow">return</span> CE_Failure;

    <span class="comment">/* ---- Set pixels ---- */</span>
    <span class="keywordflow">for</span>( iLine = 0; iLine &lt; nYSize; iLine++ ) {
        <span class="keywordflow">for</span>( iCol = 0; iCol &lt; nXSize; iCol++ ) {
            ii = iLine * nXSize + iCol;

            <span class="comment">/* Source raster pixels may be obtained with SRCVAL macro */</span>
            x0 = <a class="code" href="gdal_8h.html#a61bb460bb8dad455391cfa2bc98cd3d8">SRCVAL</a>(papoSources[0], eSrcType, ii);
            x3 = <a class="code" href="gdal_8h.html#a61bb460bb8dad455391cfa2bc98cd3d8">SRCVAL</a>(papoSources[1], eSrcType, ii);
            x4 = <a class="code" href="gdal_8h.html#a61bb460bb8dad455391cfa2bc98cd3d8">SRCVAL</a>(papoSources[2], eSrcType, ii);
            x8 = <a class="code" href="gdal_8h.html#a61bb460bb8dad455391cfa2bc98cd3d8">SRCVAL</a>(papoSources[3], eSrcType, ii);

            pix_val = sqrt((x3*x3+x4*x4)/(x0*x8));

            <a class="code" href="gdal_8h.html#a14e39ec8cc3a962913673f984e0d5398">GDALCopyWords</a>(&amp;pix_val, <a class="code" href="gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4a69dbfcc12cc807423cb51cf4f9d54983">GDT_Float64</a>, 0,
                          ((GByte *)pData) + nLineSpace * iLine +
                          iCol * nPixelSpace, eBufType, nPixelSpace, 1);
        }
    }

    <span class="comment">/* ---- Return success ---- */</span>
    <span class="keywordflow">return</span> CE_None;
}
</pre></div><h2><a class="anchor" id="gdal_vrttut_mt">
Multi-threading issues</a></h2>
<p>When using VRT datasets in a multi-threading environment, you should be careful to open the VRT dataset by the thread that will use it afterwards. The reason for that is that the VRT dataset uses GDALOpenShared when opening the underlying datasets. So, if you open twice the same VRT dataset by the same thread, both VRT datasets will share the same handles to the underlying datasets. </p>
</div>
<hr>

Generated for GDAL by 
<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.6.2-20100208.
</body>
</html>