drv_vrt.html 23.1 KB
Newer Older
xuebingbing's avatar
xuebingbing committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
<html>
<head>
<title>Virtual Format</title>
</head>

<body bgcolor="#ffffff">

<h1>Virtual Format</h1>

OGR Virtual Format is a driver that transforms features read from other
drivers based on criteria specified in an XML control file.  It is primarily
used to derive spatial layers from flat tables with spatial information in
attribute columns.  It can also be used to associate coordinate system
information with a datasource, merge layers from different datasources into
a single data source, or even just to provide an anchor file for access to
non-file oriented datasources.<p>

The virtual files are currently normally prepared by hand.<p>

<h2>Creation Issues</h2>

Before GDAL 1.7.0, the OGR VRT driver was read-only.<p>
Since GDAL 1.7.0, the CreateFeature(), SetFeature() and DeleteFeature() operations
are supported on a layer of a VRT dataset, if the following conditions are met :
<ul>
<li>the VRT dataset is opened in update mode</li>
<li>the underlying source layer supports those operations</li>
<li>the <i>SrcLayer</i> element is used (as opposed to the <i>SrcSQL</i> element)</li>
<li>the FID of the VRT features is the same as the FID of the source features, that
is to say, the <i>FID</i> element is not specified</li>
</ul><p>

<h1>Virtual File Format</h1>

The root element of the XML control file is <b>OGRVRTDataSource</b>.  It has
an <b>OGRVRTLayer</b> (or <b>OGRVRTWarpedLayer</b> or <b>OGRVRTUnionLayer</b> starting
with GDAL 1.10.0) child for each layer in the virtual datasource, and a
<b>Metadata</b> element.<p>

A <a href="http://svn.osgeo.org/gdal/trunk/gdal/data/ogrvrt.xsd">XML schema of the OGR VRT format</a>
is available. Starting with GDAL 1.11, when GDAL is configured with libXML2 support, that
schema will be used to validate the VRT documents. Non-conformities will be reported only as
warnings. That validation can be disabled by setting the GDAL_XML_VALIDATION configuration option to NO.<p>

<p>
<b>Metadata</b> (optional): (GDAL &gt;= 2.0) This element contains a list of metadata name/value
pairs associated with the dataset as a whole. It has
&lt;MDI&gt; (metadata item) subelements which have a "key" attribute and the value
as the data of the element. The Metadata element can be repeated multiple times,
in which case it must be accompanied with a "domain" attribute to indicate the
name of the metadata domain.
</p>

A <b>OGRVRTLayer</b> element should have a <b>name</b> attribute with the layer name, and may have the
following subelements:

<ul>
<li> <b>SrcDataSource</b> (mandatory): The value is the name of the datasource
that this layer will be derived from.  The element may optionally have
a <b>relativeToVRT</b> attribute which defaults to "0", but if "1" indicates
that the source datasource should be interpreted as relative to the virtual
file.  This can be any OGR supported dataset, including ODBC, CSV, etc.
The element may also have a <b>shared</b> attribute to control whether the
datasource should be opened in shared mode. Defaults to OFF for SrcLayer use and ON for SrcSQL use.</li>

<br>

<li> <b>OpenOptions</b> (optional): (GDAL &gt;= 2.0) This element may list a number of open
options as child elements of the form &lt;OOI key="key_name"&gt;value_name&lt;/OOI&gt;</li>

<br>

<li> <b>Metadata</b> (optional): (GDAL &gt;= 2.0) This element contains a list of metadata name/value
pairs associated with the layer as a whole. It has
&lt;MDI&gt; (metadata item) subelements which have a "key" attribute and the value
as the data of the element. The Metadata element can be repeated multiple times,
in which case it must be accompanied with a "domain" attribute to indicate the
name of the metadata domain.
</li>

<br>

<li> <b>SrcLayer</b> (optional): The value is the name of the layer on the
source data source from which this virtual layer should be derived.  If this
element isn't provided, then the SrcSQL element must be provided.</li>

<br>

<li> <b>SrcSQL</b> (optional): An SQL statement to execute to generate the
desired layer result.  This should be provided instead of the SrcLayer for
statement derived results.   Some limitations may apply for SQL derived
layers. Starting with OGR 1.10, an optional <b>dialect</b> attribute can be specified
on the SrcSQL element to specify which SQL "dialect" should be used :
possible values are currently <a href="ogr_sql.html">OGRSQL</a> or
<a href="ogr_sql_sqlite.html">SQLITE</a>. If <i>dialect</i> is not specified,
the default dialect of the datasource will be used.</li>

<br>

<li> <b>FID</b> (optional): Name of the source attribute column from which the
FID of features should be derived.  If not provided, the FID of the source
features will be used directly.
<br>
<br>
<ul>
<li>Logic for GDAL &gt;= 2.4: Different situations are possible:
<ul>
<li>
<pre>&lt;FID&gt;source_field_name&lt;/FID&gt;</pre>
A FID column will be
reported as source_field_name with the content of source field source_field_name.
</li>
<li>
<pre>&lt;FID name="dest_field_name"&gt;source_field_name&lt;/FID&gt;</pre>
A FID column will be
reported as dest_field_name with the content of source field source_field_name.
dest_field_name can potentially be set to the empty string.
</li>
<li>
<pre>&lt;FID /&gt;</pre>
No FID column is reported. The FID value of VRT features is the FID value of
the source features.
</li>
<li>
<pre>&lt;FID name="dest_field_name"/&gt;</pre>
A FID column will be
reported as dest_field_name with the content of the implicit source FID column.
The FID value of VRT features is the FID value of the source features.
</li>
</ul>
<br>
</li>
<li>Logic for GDAL &lt; 2.4:
The layer will report the FID column name only
if it is also reported as a regular field. Starting with GDAL 2.0, a "name"
attribute can be specified on the FID element so that the FID column name is
always reported.
</li>
</ul>
</li>

<br>

<li> <b>Style</b> (optional): Name of the attribute column from which the
style of features should be derived.  If not provided, the style of the source
features will be used directly.</li>

<br>

<li> <b>GeometryType</b> (optional): The geometry type to be assigned to the
layer.
If not provided it will be taken from the source layer.  The value should
be one of "wkbNone", "wkbUnknown", "wkbPoint", "wkbLineString", "wkbPolygon",
"wkbMultiPoint",
"wkbMultiLineString", "wkbMultiPolygon", or "wkbGeometryCollection".
Optionally "25D" may be appended to mark it as including Z coordinates.
Defaults to "wkbUnknown" indicating that any geometry type is allowed.</li>

<br>

<li> <b>LayerSRS</b> (optional): The value of this element is the spatial
reference to use for the layer.  If not provided, it is inherited from the
source layer.  The value may be WKT or any other input that is accepted
by the OGRSpatialReference::SetUserInput() method. If the value is NULL, then
no SRS will be used for the layer.</li>

<br>

<li> <b>GeometryField</b> (optional): This element is used to define
how the geometry for features should be derived.<br>
If not provided the geometry of the source feature is copied directly.<br>
The type of geometry encoding is indicated with the <b>encoding</b> attribute which may have the
value "WKT", "WKB" or "PointFromColumns".<br>
If the encoding is "WKT" or "WKB" then the <b>field</b> attribute will have
the name of the field containing the WKT or WKB geometry.<br>
If the encoding is "PointFromColumns" then the <b>x</b>, <b>y</b>, <b>z</b> and <b>m</b> attributes
will have the names of the columns to be used for the X, Y, Z and M coordinates.
The <b>z</b> and <b>m</b> attributes are optional (m only supported since OGR 2.1.1).<br>
The optional <b>reportSrcColumn</b> attribute can be used to specify
whether the source geometry fields (the fields set in the <b>field</b>, <b>x</b>, <b>y</b>, <b>z</b>, <b>m</b> attributes) should be reported as fields of the VRT layer. It defaults to TRUE.
If set to FALSE, the source geometry fields will only be used to build the geometry of the features of the VRT layer.</li>
<p>
Starting with OGR 1.11, the GeometryField element can be repeated as many times
as necessary to create multiple geometry fields. It accepts a <b>name</b>
attribute (recommended) that will be used to define the VRT geometry field name. When <b>encoding</b> is
not specified, the <b>field</b> attribute will be used to determine the corresponding
geometry field name in the source layer. If neither <b>encoding</b> nor <b>field</b>
are specified, it is assumed that the name of source geometry field is the value
of the <b>name</b> attribute.
</p>
<p>
Starting with GDAL 2.0, the optional <b>nullable</b> attribute can be used to specify
whether the geometry field is nullable. It defaults to "true".</li>
</p>
<p>
When several geometry fields are used, the following child elements of <b>GeometryField</b>
can be defined to explicitly set the geometry type, SRS, source region, or extent.
<ul>
<li><b>GeometryType</b> (optional) : same syntax as OGRVRTLayer-level <b>GeometryType</b>.</li>
<li><b>SRS</b> (optional) : same syntax as OGRVRTLayer-level <b>LayerSRS</b> (note SRS vs LayerSRS)</li>
<li><b>SrcRegion</b> (optional) : same syntax as OGRVRTLayer-level <b>SrcRegion</b></li>
<li><b>ExtentXMin</b>, <b>ExtentYMin</b>, <b>ExtentXMax</b> and <b>ExtentXMax</b> (optional) :
same syntax as OGRVRTLayer-level elements of same name</li>
</ul>
</p>
<p>If no <b>GeometryField</b> element is specified, all the geometry fields of the
source layer will be exposed by the VRT layer. In order not to expose any geometry
field of the source layer, you need to specify OGRVRTLayer-level <b>GeometryType</b>
element to wkbNone.
</p>
<br>

<li> <b>SrcRegion</b> (optional, from GDAL 1.7.0) : This element is used
to define an initial spatial filter for the source features. This spatial
filter will be combined with any spatial filter explicitly set on the VRT
layer with the SetSpatialFilter() method. The value of the element must be
a valid WKT string defining a polygon. An optional <b>clip</b> attribute
can be set to "TRUE" to clip the geometries to the source region, otherwise
the source geometries are not modified.</li>

<br>

<li> <b>Field</b> (optional, from GDAL 1.7.0): One or more attribute fields
may be defined with Field elements.  If no Field elements are defined, the
fields of the source layer/sql will be defined on the VRT layer.  The Field
may have the following attributes:
<ul>
<li> <b>name</b> (required): the name of the field.
<li> <b>type</b>: the field type, one of "Integer", "IntegerList",
"Real", "RealList", "String", "StringList", "Binary", "Date", "Time",
or "DateTime". Defaults to "String".
<li> <b>subtype</b>: (GDAL &gt;= 2.0) the field subtype, one of "None", "Boolean",
"Int16", "Float32". Defaults to "None".
<li> <b>width</b>: the field width. Defaults to unknown.
<li> <b>precision</b>: the field width. Defaults to zero.
<li> <b>src</b>: the name of the source field to be copied to this one.
Defaults to the value of "name".
<li> <b>nullable</b> (GDAL &gt;= 2.0) can be used to specify
whether the field is nullable. It defaults to "true".</li>
</ul>
</li>

<br>

<li> <b>FeatureCount</b> (optional, from GDAL 1.10.0) : This element is used
to define the feature count of the layer (when no spatial or attribute filter is set).
This can be useful on static data, when getting the feature count from the source layer is slow.</li>

<br>

<li> <b>ExtentXMin</b>, <b>ExtentYMin</b>, <b>ExtentXMax</b> and <b>ExtentXMax</b> (optional, from GDAL 1.10.0) :
Those elements are used to define the extent of the layer. This can be useful on static data, when
getting the extent from the source layer is slow.</li>

<br>

</ul>

<p>

A <b>OGRVRTWarpedLayer</b> element (GDAL &gt;= 1.10.0) is used to do on-the-fly reprojection of
a source layer. It may have the following subelements:

<ul>

<li> <b>OGRVRTLayer</b>, <b>OGRVRTWarpedLayer</b> or <b>OGRVRTUnionLayer</b> (mandatory):
the source layer to reproject.</li>
<br>

<li> <b>SrcSRS</b> (optional): The value of this element is the spatial
reference to use for the layer before reprojection. If not specified, it is deduced from
the source layer.</li>
<br>

<li> <b>TargetSRS</b> (mandatory): The value of this element is the spatial
reference to use for the layer after reprojection. </li>
<br>

<li> <b>ExtentXMin</b>, <b>ExtentYMin</b>, <b>ExtentXMax</b> and <b>ExtentXMax</b> (optional, from GDAL 1.10.0) :
Those elements are used to define the extent of the layer. This can be useful on static data, when
getting the extent from the source layer is slow.</li>
<br>

<li> <b>WarpedGeomFieldName</b> (optional, from GDAL 1.11) : The value of this element
is the geometry field name of the source layer to wrap. If not specified, the first geometry
field will be used. If there are several geometry fields, only the one matching
WarpedGeomFieldName will be warped; the other ones will be untouched.</li>
<br>

</ul>

<p>

A <b>OGRVRTUnionLayer</b> element (GDAL &gt;= 1.10.0) is used to concatenate the content of source
layers. It should have a <b>name</b> and may have the following subelements:

<ul>

<li> <b>OGRVRTLayer</b>, <b>OGRVRTWarpedLayer</b> or <b>OGRVRTUnionLayer</b> (mandatory and may be repeated):
a source layer to add in the union.</li>
<br>

<li> <b>PreserveSrcFID</b> (optional) : may be ON or OFF. If set to ON, the FID from the source layer
will be used, otherwise a counter will be used. Defaults to OFF.</li>
<br>

<li> <b>SourceLayerFieldName</b> (optional) : if specified, an additional field (named with
the value of SourceLayerFieldName) will be added in the layer field definition. For each feature,
the value of this field will be set with the name of the layer from which the feature comes from.</li>
<br>

<li> <b>GeometryType</b> (optional) : see above for the syntax. If not specified, the geometry type
will be deduced from the geometry type of all source layers.</li>
<br>

<li> <b>LayerSRS</b> (optional) : see above for the syntax. If not specified, the SRS will be the
SRS of the first source layer.</li>
<br>

<li> <b>FieldStrategy</b> (optional, exclusive with <b>Field</b> or <b>GeometryField</b>) :
may be <b>FirstLayer</b> to use the fields from the first layer found,
<b>Union</b> to use a super-set of all the fields from all source layers, or
<b>Intersection</b> to use a sub-set of all the common fields from all source layers. Defaults to <b>Union</b>.</li>
<br>

<li> <b>Field</b> (optional, exclusive with <b>FieldStrategy</b>) : see above for the syntax. Note: the src attribute
is not supported in the context of a OGRVRTUnionLayer element (field names are assumed to be identical).</li>
<br>

<li> <b>GeometryField</b> (optional, exclusive with <b>FieldStrategy</b>, GDAL &gt;= 1.11) : the <b>name</b> attribute and
the following sub-elements <b>GeometryType</b>, <b>SRS</b> and <b>Extent[X|Y][Min|Max]</b> are available.</li>
<br>

<li> <b>FeatureCount</b> (optional) : see above for the syntax</li>
<br>

<li> <b>ExtentXMin</b>, <b>ExtentYMin</b>, <b>ExtentXMax</b> and <b>ExtentXMax</b> (optional) : see above for the syntax</li>
<br>

</ul>


<h2>Example: ODBC Point Layer</h2>

In the following example (disease.ovf) the worms table from the ODBC
database DISEASE is used to form a spatial layer.  The virtual file
uses the "x" and "y" columns to get the spatial location.  It also marks
the layer as a point layer, and as being in the WGS84 coordinate system.<p>

<pre>&lt;OGRVRTDataSource&gt;

    &lt;OGRVRTLayer name="worms"&gt;
        &lt;SrcDataSource&gt;ODBC:DISEASE,worms&lt;/SrcDataSource&gt;
 	&lt;SrcLayer&gt;worms&lt;/SrcLayer&gt;
	&lt;GeometryType&gt;wkbPoint&lt;/GeometryType&gt;
        &lt;LayerSRS&gt;WGS84&lt;/LayerSRS&gt;
	&lt;GeometryField encoding="PointFromColumns" x="x" y="y"/&gt;
    &lt;/OGRVRTLayer&gt;

&lt;/OGRVRTDataSource&gt;
</pre>

<h2>Example: Renaming attributes</h2>

It can be useful in some circumstances to be able to rename the field names
from a source layer to other names. This is particularly true when you want
to transcode to a format whose schema is fixed, such as GPX
(&lt;name&gt;, &lt;desc&gt, etc.).  This can be accomplished using
SQL this way:<p>

<pre>&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTLayer name="remapped_layer"&gt;
        &lt;SrcDataSource&gt;your_source.shp&lt;/SrcDataSource&gt;
        &lt;SrcSQL&gt;SELECT src_field_1 AS name, src_field_2 AS desc FROM your_source_layer_name&lt;/SrcSQL&gt;
    &lt;/OGRVRTLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

This can also be accomplished (from GDAL 1.7.0) using explicit field
definitions:

<pre>
&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTLayer name="remapped_layer"&gt;
        &lt;SrcDataSource&gt;your_source.shp&lt;/SrcDataSource&gt;
        &lt;SrcLayer&gt;your_source&lt;/SrcSQL&gt;
        &lt;Field name="name" src="src_field_1" /&gt;
        &lt;Field name="desc" src="src_field_2" type="String" width="45" /&gt;
    &lt;/OGRVRTLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

<h2>Example: Transparent spatial filtering (GDAL &gt;= 1.7.0)</h2>

The following example will only return features from the source layer that
intersect the (0,40)-(10,50) region. Furthermore, returned geometries will be clipped
to fit into that region.<p>

<pre>&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTLayer name="source"&gt;
        &lt;SrcDataSource&gt;source.shp&lt;/SrcDataSource&gt;
        &lt;SrcRegion clip="true"&gt;POLYGON((0 40,10 40,10 50,0 50,0 40))&lt;/SrcRegion&gt;
    &lt;/OGRVRTLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

<h2>Example: Reprojected layer (GDAL &gt;= 1.10.0)</h2>

The following example will return the source.shp layer reprojected to EPSG:4326.<p>

<pre>&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTWarpedLayer&gt;
        &lt;OGRVRTLayer name="source"&gt;
            &lt;SrcDataSource&gt;source.shp&lt;/SrcDataSource&gt;
        &lt;/OGRVRTLayer&gt;
        &lt;TargetSRS&gt;EPSG:4326&lt;/TargetSRS&gt;
    &lt;/OGRVRTWarpedLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

<h2>Example: Union layer (GDAL &gt;= 1.10.0)</h2>

The following example will return a layer that is the concatenation of source1.shp
and source2.shp.<p>

<pre>&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTUnionLayer name="unionLayer"&gt;
        &lt;OGRVRTLayer name="source1"&gt;
            &lt;SrcDataSource&gt;source1.shp&lt;/SrcDataSource&gt;
        &lt;/OGRVRTLayer&gt;
        &lt;OGRVRTLayer name="source2"&gt;
            &lt;SrcDataSource&gt;source2.shp&lt;/SrcDataSource&gt;
        &lt;/OGRVRTLayer&gt;
    &lt;/OGRVRTUnionLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

<h2>Example: SQLite/Spatialite SQL dialect (GDAL &gt;=1.10.0)</h2>

The following example will return four different layers which are generated in a fly
from the same polygon shapefile. The first one is the shapefile layer as it stands.
The second layer gives simplified polygons by applying SpatiaLite function "Simplify"
with parameter tolerance=10. In the third layer the original geometries are replaced by
their convex hulls. In the fourth layer SpatiaLite function PointOnSurface is used for
replacing the original geometries by points which are inside the corresponding source
polygons. Note that for using the last three layers of this VRT file GDAL must be
compiled with SQLite and SpatiaLite.<p>

<pre>
&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTLayer name="polygons"&gt;
        &lt;SrcDataSource&gt;polygons.shp&lt;/SrcDataSource&gt;
        &lt;/OGRVRTLayer&gt;
    &lt;OGRVRTLayer name="polygons_as_simplified"&gt;
        &lt;SrcDataSource&gt;polygons.shp&lt;/SrcDataSource&gt;
        &lt;SrcSQL dialect="sqlite"&gt;SELECT Simplify(geometry,10) from polygons&lt;/SrcSQL&gt;
    &lt;/OGRVRTLayer&gt;
    &lt;OGRVRTLayer name="polygons_as_hulls"&gt;
        &lt;SrcDataSource&gt;polygons.shp&lt;/SrcDataSource&gt;
        &lt;SrcSQL dialect="sqlite"&gt;SELECT ConvexHull(geometry) from polygons&lt;/SrcSQL&gt;
    &lt;/OGRVRTLayer&gt;
    &lt;OGRVRTLayer name="polygons_as_points"&gt;
        &lt;SrcDataSource&gt;polygons.shp&lt;/SrcDataSource&gt;
        &lt;SrcSQL dialect="sqlite"&gt;SELECT PointOnSurface(geometry) from polygons&lt;/SrcSQL&gt;
    &lt;/OGRVRTLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

<h2>Example: Multiple geometry fields (GDAL &gt;= 1.11)</h2>

<p>
The following example will expose all the attribute and geometry fields of the
source layer:
</p>
<pre>&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTLayer name="test"&gt;
        &lt;SrcDataSource&gt;PG:dbname=testdb&lt;/SrcDataSource&gt;
    &lt;/OGRVRTLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

<p>
To expose only part (or all!) of the fields:
</p>
<pre>&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTLayer name="other_test"&gt;
        &lt;SrcDataSource&gt;PG:dbname=testdb&lt;/SrcDataSource&gt;
        &lt;SrcLayer&gt;test&lt;/SrcLayer&gt;
        &lt;GeometryField name="pg_geom_field_1" /&gt;
        &lt;GeometryField name="vrt_geom_field_2" field="pg_geom_field_2"&gt;
            &lt;GeometryType&gt;wkbPolygon&lt;/GeometryType&gt;
            &lt;SRS&gt;EPSG:4326&lt;/SRS&gt;
            &lt;ExtentXMin&gt;-180&lt;/ExtentXMin&gt;
            &lt;ExtentYMin&gt;-90&lt;/ExtentYMin&gt;
            &lt;ExtentXMax&gt;180&lt;/ExtentXMax&gt;
            &lt;ExtentYMax&gt;90&lt;/ExtentYMax&gt;
        &lt;/GeometryField&gt;
        &lt;Field name="vrt_field_1" src="src_field_1" /&gt;
    &lt;/OGRVRTLayer&gt;w
&lt;/OGRVRTDataSource&gt;
</pre>

To reproject the 'pg_geom_field_2' geometry field to EPSG:4326:<p>

<pre>&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTWarpedLayer&gt;
        &lt;OGRVRTLayer name="other_test"&gt;
            &lt;SrcDataSource&gt;PG:dbname=testdb&lt;/SrcDataSource&gt;
        &lt;/OGRVRTLayer&gt;
        &lt;WarpedGeomFieldName&gt;pg_geom_field_2&lt;/WarpedGeomFieldName&gt;
        &lt;TargetSRS&gt;EPSG:32631&lt;/TargetSRS&gt;
    &lt;/OGRVRTWarpedLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

To make the union of several multi-geometry layers and keep only a few of them:<p>

<pre>&lt;OGRVRTDataSource&gt;
    &lt;OGRVRTUnionLayer name="unionLayer"&gt;
        &lt;OGRVRTLayer name="source1"&gt;
            &lt;SrcDataSource&gt;PG:dbname=testdb&lt;/SrcDataSource&gt;
        &lt;/OGRVRTLayer&gt;
        &lt;OGRVRTLayer name="source2"&gt;
            &lt;SrcDataSource&gt;PG:dbname=testdb&lt;/SrcDataSource&gt;
        &lt;/OGRVRTLayer&gt;
        &lt;GeometryField name="pg_geom_field_2"&gt;
            &lt;GeometryType&gt;wkbPolygon&lt;/GeometryType&gt;
            &lt;SRS&gt;EPSG:4326&lt;/SRS&gt;
            &lt;ExtentXMin&gt;-180&lt;/ExtentXMin&gt;
            &lt;ExtentYMin&gt;-90&lt;/ExtentYMin&gt;
            &lt;ExtentXMax&gt;180&lt;/ExtentXMax&gt;
            &lt;ExtentYMax&gt;90&lt;/ExtentYMax&gt;
        &lt;/GeometryField&gt;
        &lt;GeometryField name="pg_geom_field_3" /&gt;
        &lt;Field name="src_field_1" /&gt;
    &lt;/OGRVRTUnionLayer&gt;
&lt;/OGRVRTDataSource&gt;
</pre>

<h2>Other Notes</h2>

<ul>

<li> When the <i>GeometryField</i> is "WKT" spatial filtering is applied
after extracting all rows from the source datasource.  Essentially that means
there is no fast spatial filtering on WKT derived geometries. <p>

<li> When the <i>GeometryField</i> is "PointFromColumns", and a <i>SrcLayer</i> (as opposed
to <i>SrcSQL</i>) is used, and a spatial filter is in effect on the virtual layer
then the spatial filter will be internally translated into an attribute filter
on the X and Y columns in the <i>SrcLayer</i>.  In cases where fast spatial filtering
is important it can be helpful to index the X and Y columns in the source
datastore, if that is possible.  For instance if the source is an RDBMS.
You can turn off that feature by setting the <i>useSpatialSubquery</i> attribute
of the GeometryField element to FALSE.<p>

</ul>

</body>
</html>