Skip to content

Commit

Permalink
WFS: avoid GetFeature request to be emitted twice in GML streaming mo…
Browse files Browse the repository at this point in the history
…de (fixes OSGeo#8666, master only)
  • Loading branch information
rouault authored and craigds committed Nov 6, 2023
1 parent 3c1c505 commit be32ef4
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,61 +740,59 @@ GDALDataset *OGRWFSLayer::FetchGetFeature(int nRequestMaxFeatures)
osStreamingName += osURL;
}

GDALDataset *poOutputDS = nullptr;

/* Try streaming when the output format is GML and that we have a .xsd
*/
/* that we are able to understand */
CPLString osXSDFileName =
CPLSPrintf("/vsimem/tempwfs_%p/file.xsd", this);
VSIStatBufL sBuf;
GDALDriver *poDriver = nullptr;
if ((osOutputFormat.empty() ||
osOutputFormat.ifind("GML") != std::string::npos) &&
VSIStatL(osXSDFileName, &sBuf) == 0 &&
GDALGetDriverByName("GML") != nullptr)
(poDriver = GDALDriver::FromHandle(GDALGetDriverByName("GML"))) !=
nullptr &&
poDriver->pfnOpen)
{
bStreamingDS = true;
const char *const apszAllowedDrivers[] = {"GML", nullptr};
const char *apszOpenOptions[6] = {nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr};
apszOpenOptions[0] = CPLSPrintf("XSD=%s", osXSDFileName.c_str());
apszOpenOptions[1] = CPLSPrintf(
"EMPTY_AS_NULL=%s", poDS->IsEmptyAsNull() ? "YES" : "NO");
int iGMLOOIdex = 2;
CPLStringList aosOptions;
aosOptions.SetNameValue("XSD", osXSDFileName.c_str());
aosOptions.SetNameValue("EMPTY_AS_NULL",
poDS->IsEmptyAsNull() ? "YES" : "NO");
if (CPLGetConfigOption("GML_INVERT_AXIS_ORDER_IF_LAT_LONG",
nullptr) == nullptr)
{
apszOpenOptions[iGMLOOIdex] =
CPLSPrintf("INVERT_AXIS_ORDER_IF_LAT_LONG=%s",
poDS->InvertAxisOrderIfLatLong() ? "YES" : "NO");
iGMLOOIdex++;
aosOptions.SetNameValue(
"INVERT_AXIS_ORDER_IF_LAT_LONG",
poDS->InvertAxisOrderIfLatLong() ? "YES" : "NO");
}
if (CPLGetConfigOption("GML_CONSIDER_EPSG_AS_URN", nullptr) ==
nullptr)
{
apszOpenOptions[iGMLOOIdex] =
CPLSPrintf("CONSIDER_EPSG_AS_URN=%s",
poDS->GetConsiderEPSGAsURN().c_str());
iGMLOOIdex++;
aosOptions.SetNameValue("CONSIDER_EPSG_AS_URN",
poDS->GetConsiderEPSGAsURN().c_str());
}
if (CPLGetConfigOption("GML_EXPOSE_GML_ID", nullptr) == nullptr)
{
apszOpenOptions[iGMLOOIdex] = CPLSPrintf(
"EXPOSE_GML_ID=%s", poDS->ExposeGMLId() ? "YES" : "NO");
aosOptions.SetNameValue("EXPOSE_GML_ID",
poDS->ExposeGMLId() ? "YES" : "NO");
// iGMLOOIdex ++;
}

GDALOpenInfo oOpenInfo(osStreamingName.c_str(), GA_ReadOnly);
if (oOpenInfo.nHeaderBytes)
if (oOpenInfo.nHeaderBytes && m_nNumberMatched < 0)
{
const char *pszData =
reinterpret_cast<const char *>(oOpenInfo.pabyHeader);
ReadNumberMatched(pszData);
}
oOpenInfo.papszOpenOptions = aosOptions.List();

poOutputDS = (GDALDataset *)GDALOpenEx(
osStreamingName, GDAL_OF_VECTOR, apszAllowedDrivers,
apszOpenOptions, nullptr);
auto poOutputDS = poDriver->Open(&oOpenInfo, true);
if (poOutputDS)
{
return poOutputDS;
}
}
/* Try streaming when the output format is FlatGeobuf */
else if ((osOutputFormat.empty() ||
Expand All @@ -810,7 +808,6 @@ GDALDataset *OGRWFSLayer::FetchGetFeature(int nRequestMaxFeatures)
apszAllowedDrivers, nullptr, nullptr);
if (poFlatGeobuf_DS)
{
bStreamingDS = true;
return poFlatGeobuf_DS;
}
}
Expand All @@ -819,11 +816,6 @@ GDALDataset *OGRWFSLayer::FetchGetFeature(int nRequestMaxFeatures)
bStreamingDS = false;
}

if (poOutputDS)
{
return poOutputDS;
}

if (bStreamingDS)
{
/* In case of failure, read directly the content to examine */
Expand Down Expand Up @@ -978,7 +970,8 @@ GDALDataset *OGRWFSLayer::FetchGetFeature(int nRequestMaxFeatures)
return nullptr;
}

ReadNumberMatched(pszData);
if (m_nNumberMatched < 0)
ReadNumberMatched(pszData);

CPLString osTmpFileName;

Expand Down

0 comments on commit be32ef4

Please sign in to comment.