[gdal-dev] Vector VRT with OGRVRTUnionLayer
Jon Morris
Jon.Morris at jbarisk.com
Tue May 6 09:35:16 PDT 2025
Hello all,
I'm trying to write a tool to create vector VRTs and need a bit of clarification with OGRVRTUnionLayers.
Is it possible to have a union layer when the input layers have different geometry types? Currently I'm trying Polygon and Multipolygon and I'm not clear whether this should make a valid VRT or if I need to convert one of my input layers so the geometry types are the same.
Also, I want to support Shapefile, FileGDB, and PostGIS input layers - the geometry field names are different for each of these. The example in the doc shows that fields can be renamed - `<GeometryField name="vrt_geom_field_2" field="pg_geom_field_2">` but Shapefiles don't appear to have a geometry field name. Trying `field=""` does not work.
Here's an example VRT that I have created (using GDAL test data autotest/ogr/data/poly.shp and autotest/ogr/data/filegdb/curves.gdb):
<OGRVRTDataSource>
<Metadata />
<OGRVRTUnionLayer name="merged">
<SourceLayerFieldName>Input layer</SourceLayerFieldName>
<OGRVRTLayer name="poly">
<SrcDataSource relativeToVRT="1">poly.shp</SrcDataSource>
<SrcLayer>poly</SrcLayer>
</OGRVRTLayer>
<OGRVRTLayer name="polygon">
<SrcDataSource relativeToVRT="1">curves.gdb</SrcDataSource>
<SrcLayer>polygon</SrcLayer>
</OGRVRTLayer>
<ExtentXMin>3.339061908000076</ExtentXMin>
<ExtentYMin>38.30604436200008</ExtentYMin>
<ExtentXMax>481645.3125</ExtentXMax>
<ExtentYMax>4765610.5</ExtentYMax>
</OGRVRTUnionLayer>
</OGRVRTDataSource>
Ogrinfo shows separate entries for geometry, extent, wkt, and geometry column. How can I get the union layer to only show one of each?
$ ogrinfo -al -so test.vrt
INFO: Open of `test.vrt'
using driver `OGR_VRT' successful.
Layer name: merged
Geometry (): Polygon
Geometry (SHAPE): Multi Polygon
Feature Count: 15
Extent (): (3.339062, 38.306044) - (481645.312500, 4765610.500000)
Extent (SHAPE): (3.339062, 38.306044) - (12.092784, 49.244892)
SRS WKT ():
PROJCRS["OSGB36 / British National Grid",
BASEGEOGCRS["OSGB36",
DATUM["Ordnance Survey of Great Britain 1936",
ELLIPSOID["Airy 1830",6377563.396,299.3249646,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4277]],
CONVERSION["British National Grid",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",49,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",-2,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",0.9996012717,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",400000,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",-100000,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["(E)",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["(N)",north,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Engineering survey, topographic mapping."],
AREA["United Kingdom (UK) - offshore to boundary of UKCS within 49°45'N to 61°N and 9°W to 2°E; onshore Great Britain (England, Wales and Scotland). Isle of Man onshore."],
BBOX[49.75,-9,61.01,2.01]],
ID["EPSG",27700]]
Data axis to CRS axis mapping: 1,2
SRS WKT (SHAPE):
GEOGCRS["WGS 84",
ENSEMBLE["World Geodetic System 1984 ensemble",
MEMBER["World Geodetic System 1984 (Transit)"],
MEMBER["World Geodetic System 1984 (G730)"],
MEMBER["World Geodetic System 1984 (G873)"],
MEMBER["World Geodetic System 1984 (G1150)"],
MEMBER["World Geodetic System 1984 (G1674)"],
MEMBER["World Geodetic System 1984 (G1762)"],
MEMBER["World Geodetic System 1984 (G2139)"],
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]],
ENSEMBLEACCURACY[2.0]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
USAGE[
SCOPE["Horizontal component of 3D system."],
AREA["World."],
BBOX[-90,-180,90,180]],
ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Geometry Column 1 =
Geometry Column 2 = SHAPE
Input layer: String (0.0)
AREA: Real (12.3)
EAS_ID: Integer64 (11.0)
PRFEDEA: String (16.0)
SHAPE_Length: Real (0.0) DEFAULT FILEGEODATABASE_SHAPE_LENGTH
SHAPE_Area: Real (0.0) DEFAULT FILEGEODATABASE_SHAPE_AREA
When I open the VRT programmatically and iterate through the features, FIDs 10-14 (i.e. those from the FGDB layer) have no geometry. Do I need to add something like `<GeometryField name="SHAPE" />` to each layer so the geometry fields are found?
Thanks,
Jon
Jon Morris
Software Developer
--
e: Jon.Morris at jbarisk.com
d:+44 (0)1756 587229
t: +44 (0)1756 799919
www.jbarisk.com
All JBA Risk Management's email messages contain confidential information and are intended only for the individual(s) named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by email if you have received this email by mistake and delete this email from your system.
JBA Risk Management Limited is registered in England, company number 07732946, 1 Broughton Park, Old Lane North, Broughton, Skipton, North Yorkshire, BD23 3FD, England.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250506/5bb07f7b/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image670191.png
Type: image/png
Size: 7388 bytes
Desc: image670191.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250506/5bb07f7b/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image526410.png
Type: image/png
Size: 5172 bytes
Desc: image526410.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250506/5bb07f7b/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image877390.png
Type: image/png
Size: 774 bytes
Desc: image877390.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250506/5bb07f7b/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image078618.png
Type: image/png
Size: 797 bytes
Desc: image078618.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250506/5bb07f7b/attachment-0007.png>
More information about the gdal-dev
mailing list