Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFS: do not emit twice DescribeFeatureType request on servers with complex features and a single layer #8577

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions autotest/ogr/ogr_wfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ def test_ogr_wfs_vsimem_wfs110_one_layer_xmldescriptionfile_to_be_updated(

ds = ogr.Open("/vsimem/ogr_wfs_xmldescriptionfile_to_be_updated.xml")
lyr = ds.GetLayer(0)
lyr.GetLayerDefn()
assert lyr.GetLayerDefn().GetFieldCount() == 8
ds = None

f = gdal.VSIFOpenL("/vsimem/ogr_wfs_xmldescriptionfile_to_be_updated.xml", "rb")
Expand All @@ -1438,31 +1438,36 @@ def test_ogr_wfs_vsimem_wfs110_one_layer_xmldescriptionfile_to_be_updated(
</FeatureTypeList>
</WFS_Capabilities>
<OGRWFSLayer name="my_layer">
<schema foo="http://foo" gml="http://www.opengis.net/gml" xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://foo">
<import namespace="http://www.opengis.net/gml" schemaLocation="http://foo/schemas/gml/3.1.1/base/gml.xsd" />
<complexType name="my_layerType">
<complexContent>
<extension base="gml:AbstractFeatureType">
<sequence>
<element maxOccurs="1" minOccurs="0" name="str" nillable="true" type="xsd:string" />
<element maxOccurs="1" minOccurs="0" name="boolean" nillable="true" type="xsd:boolean" />
<element maxOccurs="1" minOccurs="0" name="short" nillable="true" type="xsd:short" />
<element maxOccurs="1" minOccurs="0" name="int" nillable="true" type="xsd:int" />
<element maxOccurs="1" minOccurs="0" name="float" nillable="true" type="xsd:float" />
<element maxOccurs="1" minOccurs="0" name="double" nillable="true" type="xsd:double" />
<element maxOccurs="1" minOccurs="0" name="dt" nillable="true" type="xsd:dateTime" />
<element maxOccurs="1" minOccurs="0" name="shape" nillable="true" type="gml:PointPropertyType" />
</sequence>
</extension>
</complexContent>
</complexType>
<element name="my_layer" substitutionGroup="gml:_Feature" type="foo:my_layerType" />
</schema>
<xsd:schema xmlns:foo="http://foo" xmlns:gml="http://www.opengis.net/gml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://foo">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://foo/schemas/gml/3.1.1/base/gml.xsd" />
<xsd:complexType name="my_layerType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="str" nillable="true" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="boolean" nillable="true" type="xsd:boolean" />
<xsd:element maxOccurs="1" minOccurs="0" name="short" nillable="true" type="xsd:short" />
<xsd:element maxOccurs="1" minOccurs="0" name="int" nillable="true" type="xsd:int" />
<xsd:element maxOccurs="1" minOccurs="0" name="float" nillable="true" type="xsd:float" />
<xsd:element maxOccurs="1" minOccurs="0" name="double" nillable="true" type="xsd:double" />
<xsd:element maxOccurs="1" minOccurs="0" name="dt" nillable="true" type="xsd:dateTime" />
<xsd:element maxOccurs="1" minOccurs="0" name="shape" nillable="true" type="gml:PointPropertyType" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="my_layer" substitutionGroup="gml:_Feature" type="foo:my_layerType" />
</xsd:schema>
</OGRWFSLayer>
</OGRWFSDataSource>
"""
)

ds = ogr.Open("/vsimem/ogr_wfs_xmldescriptionfile_to_be_updated.xml")
lyr = ds.GetLayer(0)
assert lyr.GetLayerDefn().GetFieldCount() == 8
ds = None

with gdaltest.tempfile(
"/vsimem/ogr_wfs_xmldescriptionfile_to_be_updated.xml",
"""<OGRWFSDataSource>
Expand Down
9 changes: 6 additions & 3 deletions ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,10 +1148,13 @@ OGRFeatureDefn *OGRWFSLayer::GetLayerDefn()
if (poFeatureDefn)
return poFeatureDefn;

poDS->LoadMultipleLayerDefn(GetName(), pszNS, pszNSVal);
if (poDS->GetLayerCount() > 1)
{
poDS->LoadMultipleLayerDefn(GetName(), pszNS, pszNSVal);

if (poFeatureDefn)
return poFeatureDefn;
if (poFeatureDefn)
return poFeatureDefn;
}

return BuildLayerDefn();
}
Expand Down
Loading