diff --git a/autotest/ogr/ogr_wfs.py b/autotest/ogr/ogr_wfs.py index bfd94cea31fe..ad52f61170c1 100755 --- a/autotest/ogr/ogr_wfs.py +++ b/autotest/ogr/ogr_wfs.py @@ -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") @@ -1438,31 +1438,36 @@ 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) + assert lyr.GetLayerDefn().GetFieldCount() == 8 + ds = None + with gdaltest.tempfile( "/vsimem/ogr_wfs_xmldescriptionfile_to_be_updated.xml", """ diff --git a/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp b/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp index 19535bdfc701..76b210005467 100644 --- a/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp +++ b/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp @@ -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(); }