Awesome! Thanks Jukka, that has fixed it. I didn't know wkbUnknown could also 
be used as a wildcard, but with that tag I don't need to set geometry fields, 
GDAL manages to find everything and make it appear as if everything is in one 
layer.

Jon


e: jon.mor...@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.
-----Original Message-----
From: Rahkonen Jukka <jukka.rahko...@maanmittauslaitos.fi> 
Sent: 06 May 2025 21:36
To: gdal-dev@lists.osgeo.org; Jon Morris <jon.mor...@jbarisk.com>
Subject: Re: Vector VRT with OGRVRTUnionLayer

CAUTION: This email originated from outside of JBA and contains one or more 
links. DO NOT click links unless you recognise the sender's email address and 
are absolutely certain that the content is safe.
See the Phishing page on IMS on SP for more information about how to spot and 
report suspicious messages.

Hi,

Partial answer based on editing the example 
https://gdal.org/en/stable/drivers/vector/vrt.html#example-union-layer

Sources: polygon shapefile and point shapefile
Output: one layer with unknown/any geometry type

unionlayer.vrt
========
<OGRVRTDataSource>
    <OGRVRTUnionLayer name="unionLayer">
        <OGRVRTLayer name="poly">
            <SrcDataSource>poly.shp</SrcDataSource>
            <GeometryType>wkbUnknown</GeometryType>
        </OGRVRTLayer>
        <OGRVRTLayer name="point">
            <SrcDataSource>point.shp</SrcDataSource>
            <GeometryType>wkbUnknown</GeometryType>
        </OGRVRTLayer>
    </OGRVRTUnionLayer>
</OGRVRTDataSource>

ogrinfo unionlayer.vrt -al
INFO: Open of `unionlayer.vrt'
      using driver `OGR_VRT' successful.

Layer name: unionLayer
Geometry: Unknown (any)
Feature Count: 2
Extent: (258.000000, 176.000000) - (507.000000, 345.000000) Layer SRS WKT:
(unknown)
OGRFeature(unionLayer):0
  POLYGON ((365 311,507 281,332 176,258 237,365 311))

OGRFeature(unionLayer):1
  POINT (282 345)

-Jukka Rahkonen-

________________________________________
Lähettäjä: gdal-dev käyttäjän Jon Morris via gdal-dev puolesta
Lähetetty: Tiistai 6. toukokuuta 2025 19.35
Vastaanottaja: gdal-dev@lists.osgeo.org
Aihe: [gdal-dev] Vector VRT with OGRVRTUnionLayer

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.vrtINFO: Open of `test.vrt'      
using driver `OGR_VRT' successful. Layer name: mergedGeometry (): 
PolygonGeometry (SHAPE): Multi PolygonFeature Count: 15Extent (): (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,2SRS 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,1Geometry Column 1 =Geometry Column 2 = SHAPEInput 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_LENGTHSHAPE_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 MorrisSoftware 
Developer-- e: jon.mor...@jbarisk.comd:+44 (0)1756 587229t: +44 (0)1756 
799919www.jbarisk.com[X][X][X][X]   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.
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to