GMLAS driver: not correct geometry fields
What is the bug?
Some schemas require geometry without geometry field like "geometryProperty" but raw gml like "gml:MultiPoint". And when geometry field in xsd is a reference element like <xs:element ref="gml:MultiPoint"/> GMLAS driver creates double geometry tag like:
<gml:MultiPoint>
<gml:MultiPoint srsName="http://www.opengis.net/def/crs/EPSG/0/3857" gml:id=".geom0">
<gml:pointMember>
<gml:Point gml:id=".geom0.0"><gml:pos>4418260.8283802 5558756.23924428</gml:pos></gml:Point>
</gml:pointMember>
</gml:MultiPoint>
</gml:MultiPoint>
Steps to reproduce the issue
Test schema
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:test="http://test" targetNamespace="http://test" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.opengis.net/gml/3.2" schemaLocation="http://schemas.opengis.net/gml/3.2.1/gml.xsd"/>
<xs:complexType name="Test_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="TEXT" type="xs:string" minOccurs="0" />
<xs:element ref="gml:MultiPoint"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Test" type="test:Test_Type" substitutionGroup="gml:AbstractFeature" />
</xs:schema>
test data:
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ test-file.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy><gml:Envelope srsName="urn:ogc:def:crs:EPSG::3857"><gml:lowerCorner>4414847.71501257 5537234.21000161</gml:lowerCorner><gml:upperCorner>4423394.18084224 5561668.98272843</gml:upperCorner></gml:Envelope></gml:boundedBy>
<ogr:featureMember>
<ogr:Test gml:id="Test.0">
<ogr:geometryProperty><gml:MultiPoint srsName="urn:ogc:def:crs:EPSG::3857"><gml:pointMember><gml:Point><gml:pos>4418260.8283802 5558756.23924428</gml:pos></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometryProperty>
<ogr:TEXT>some-text</ogr:TEXT>
</ogr:Test>
</ogr:featureMember>
</ogr:FeatureCollection>
ogr2ogr command
ogr2ogr -f GMLAS -dsco INPUT_XSD=test-schema.xsd result-file.gml test-file.gml
result:
<?xml version="1.0" encoding="utf-8" ?>
<wfs:FeatureCollection
timeStamp="2024-06-27T08:26:17Z"
numberMatched="unknown"
numberReturned="2"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="http://test"
xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gsr="http://www.isotc211.org/2005/gsr"
xmlns:gss="http://www.isotc211.org/2005/gss"
xmlns:gts="http://www.isotc211.org/2005/gts"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://test C:\IT\Csharp\Projects\GmlasTest\data\test-schema.xsd" >
<wfs:member>
<test:Test>
<test:TEXT>some-text</test:TEXT>
<gml:MultiPoint><gml:MultiPoint srsName="http://www.opengis.net/def/crs/EPSG/0/3857" gml:id=".geom0"><gml:pointMember><gml:Point gml:id=".geom0.0"><gml:pos>4418260.8283802 5558756.23924428</gml:pos></gml:Point></gml:pointMember></gml:MultiPoint></gml:MultiPoint>
</test:Test>
</wfs:member>
</wfs:FeatureCollection>
We got double gml:MultiPoint tag. It looks like GMLAS recognizes gml:MultiPoint like geometry field name in this case.
Expected result:
<?xml version="1.0" encoding="utf-8" ?>
<wfs:FeatureCollection
timeStamp="2024-06-27T08:26:17Z"
numberMatched="unknown"
numberReturned="2"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="http://test"
xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gsr="http://www.isotc211.org/2005/gsr"
xmlns:gss="http://www.isotc211.org/2005/gss"
xmlns:gts="http://www.isotc211.org/2005/gts"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://test C:\IT\Csharp\Projects\GmlasTest\data\test-schema.xsd" >
<wfs:member>
<test:Test>
<test:TEXT>some-text</test:TEXT>
<gml:MultiPoint srsName="http://www.opengis.net/def/crs/EPSG/0/3857" gml:id=".geom0"><gml:pointMember><gml:Point gml:id=".geom0.0"><gml:pos>4418260.8283802 5558756.23924428</gml:pos></gml:Point></gml:pointMember></gml:MultiPoint>
</test:Test>
</wfs:member>
</wfs:FeatureCollection>
Versions and provenance
OS: Windows 11 GDAL: v3.9.0
I'm not sure the GMLAS driver is ready for such a untypical advanced use case. Furthermore the write side of the GMLAS driver is quite couple with its read side. Cf https://gdal.org/drivers/vector/gmlas.html#creation-support
Here would would need to force the input dataset to be read by the GMLAS driver as well with GMLAS:test-file.gml, and hencure that your input file fully validates. But even with that, the subtlety of the xs:choice on geometry, might easily confuse the driver.
I'm not sure the GMLAS driver is ready for such a untypical advanced use case. Furthermore the write side of the GMLAS driver is quite couple with its read side. Cf https://gdal.org/drivers/vector/gmlas.html#creation-support Here would would need to force the input dataset to be read by the GMLAS driver as well with
GMLAS:test-file.gml, and hencure that your input file fully validates. But even with that, the subtlety of the xs:choice on geometry, might easily confuse the driver.
Should have deleted choice not to confuse, it is just like in real schema, where i faced this problem) In this issue i'm talking about double tags when in xsd geometry field looks like this "<xs:element ref="gml:MultiSurface"/> "
In this case "gml:MultiSurface" is recognized by GMLAS like geometry field name and we got "gml:MultiSurface<gml:MultiSurface" regardless of the input file format
Should have deleted choice not to confuse, it is just like in real schema, where i faced this problem)
Please update precisely the initial post with a valid schema and sample. Details matter a lot in that area (but the GMLAS driver is very tricky and it is likely that a fix to address your use case would go beyond usual maintenance activities)
Should have deleted choice not to confuse, it is just like in real schema, where i faced this problem)
Please update precisely the initial post with a valid schema and sample. Details matter a lot in that area (but the GMLAS driver is very tricky and it is likely that a fix to address your use case would go beyond usual maintenance activities)
Okay, Thank you! Updated the post.