📄 gdal_vrttut.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>GDAL: GDAL Virtual Format Tutorial</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.1 --><div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul></div><h1><a class="anchor" name="gdal_vrttut">GDAL Virtual Format Tutorial</a></h1><h2><a class="anchor" name="gdal_vrttut_intro">Introduction</a></h2>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>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"><VRTDataset rasterXSize=<span class="stringliteral">"512"</span> rasterYSize=<span class="stringliteral">"512"</span>> <GeoTransform>440720.0, 60.0, 0.0, 3751320.0, 0.0, -60.0</GeoTransform> <VRTRasterBand dataType=<span class="stringliteral">"Byte"</span> band=<span class="stringliteral">"1"</span>> <ColorInterp>Gray</ColorInterp> <SimpleSource> <SourceFilename relativeToVRT=<span class="stringliteral">"1"</span>>utm.tif</SourceFilename> <SourceBand>1</SourceBand> <SrcRect xOff=<span class="stringliteral">"0"</span> yOff=<span class="stringliteral">"0"</span> xSize=<span class="stringliteral">"512"</span> ySize=<span class="stringliteral">"512"</span>/> <DstRect xOff=<span class="stringliteral">"0"</span> yOff=<span class="stringliteral">"0"</span> xSize=<span class="stringliteral">"512"</span> ySize=<span class="stringliteral">"512"</span>/> </SimpleSource> </VRTRasterBand></VRTDataset></pre></div><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>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.<h2><a class="anchor" name="gdal_vrttut_format">.vrt Format</a></h2>Virtual files stored on disk are kept in an XML format with the following elements.<p><ul><li><b>VRTDataset</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 VRTRasterBand subelements.<p><div class="fragment"><pre class="fragment"><VRTDataset rasterXSize=<span class="stringliteral">"512"</span> rasterYSize=<span class="stringliteral">"512"</span>></pre></div><p></li><li><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"> <SRS>PROJCS[&quot;NAD27 / UTM zone 11N&quot;,GEOGCS[&quot;NAD27&quot;,DATUM[&quot;North_American_Datum_1927&quot;,SPHEROID[&quot;Clarke 1866&quot;,6378206.4,294.9786982139006,AUTHORITY[&quot;EPSG&quot;,&quot;7008&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6267&quot;]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,&quot;4267&quot;]],PROJECTION[&quot;Transverse_Mercator&quot;],PARAMETER[&quot;latitude_of_origin&quot;,0],PARAMETER[&quot;central_meridian&quot;,-117],PARAMETER[&quot;scale_factor&quot;,0.9996],PARAMETER[&quot;false_easting&quot;,500000],PARAMETER[&quot;false_northing&quot;,0],UNIT[&quot;metre&quot;,1,AUTHORITY[&quot;EPSG&quot;,&quot;9001&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;26711&quot;]]</SRS></pre></div><p></li><li><b>GeoTransform</b>: This element contains a six value affine geotransformation for the dataset, mapping between pixel/line coordinates and georeferenced coordinates. The list of values is the data of the SRS element, and the values are separated by commas. <p>The parameter order is as follows: [0] top left x; [1] w-e pixel resolution; [2] rotation, 0 if image is "north up"; [3] top left y; [4] rotation, 0 if image is "north up"; [5] n-s pixel resolution.<p><div class="fragment"><pre class="fragment"> <GeoTransform>440720.0, 60, 0.0, 3751320.0, 0.0, -60.0</GeoTransform></pre></div><p></li><li><b>Metadata</b>: This element contains a list of metadata name/value pairs associated with the VRTDataset as a whole, or a VRTRasterBand. It has <MDI> (metadata item) subelements which have a "key" attribute and the value as the data of the element.<p><div class="fragment"><pre class="fragment"> <Metadata> <MDI key=<span class="stringliteral">"md_key"</span>>Metadata value</MDI> </Metadata></pre></div><p></li><li><b>VRTRasterBand</b>: This represents one band of a dataset. It will have a dataType 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></li><li><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><div class="fragment"><pre class="fragment"> <ColorInterp>Gray</ColorInterp>: </pre></div><p></li><li><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"> <NoDataValue>-100.0</NoDataValue></pre></div><p></li><li><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"> <ColorTable> <Entry c1=<span class="stringliteral">"0"</span> c2=<span class="stringliteral">"0"</span> c3=<span class="stringliteral">"0"</span> c4=<span class="stringliteral">"255"</span>/> <Entry c1=<span class="stringliteral">"145"</span> c2=<span class="stringliteral">"78"</span> c3=<span class="stringliteral">"224"</span> c4=<span class="stringliteral">"255"</span>/> </ColorTable></pre></div><p></li><li><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"> <Description>Crop Classification Layer</Description></pre></div><p></li><li><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><div class="fragment"><pre class="fragment"> <UnitType>ft</UnitType></pre></div><p></li><li><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><div class="fragment"><pre class="fragment"> <Offset>0.0</Offset></pre></div><p></li><li><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><div class="fragment"><pre class="fragment"> <Scale>0.0</Scale></pre></div><p></li><li><b>CategoryNames</b>: This optional element contains a list of Category subelements with the names of the categories for classified raster band.<p><p><div class="fragment"><pre class="fragment"> <CategoryNames> <Category>Missing</Category> <Category>Non-Crop</Category> <Category>Wheat</Category> <Category>Corn</Category> <Category>Soybeans</Category> </CategoryNames></pre></div><p></li><li><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>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><div class="fragment"><pre class="fragment"> <SimpleSource> <SourceFilename relativeToVRT=<span class="stringliteral">"1"</span>>utm.tif</SourceFilename> <SourceBand>1</SourceBand> <SrcRect xOff=<span class="stringliteral">"0"</span> yOff=<span class="stringliteral">"0"</span> xSize=<span class="stringliteral">"512"</span> ySize=<span class="stringliteral">"512"</span>/> <DstRect xOff=<span class="stringliteral">"0"</span> yOff=<span class="stringliteral">"0"</span> xSize=<span class="stringliteral">"512"</span> ySize=<span class="stringliteral">"512"</span>/> </SimpleSource></pre></div><p></li><li><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"> <KernelFilteredSource> <SourceFilename>/debian/home/warmerda/openev/utm.tif</SourceFilename> <SourceBand>1</SourceBand> <Kernel normalized=<span class="stringliteral">"1"</span>> <Size>3</Size> <Coefs>0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111</Coefs> </Kernel>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -