Skip to content

Commit

Permalink
WFS: Don't issue STARTINDEX if feature count is small
Browse files Browse the repository at this point in the history
Backports OSGeo#8146

Datasources with no primary key cannot be naturally ordered by the
server, and so using the STARTINDEX argument causes a 400 error with the
response:

> Cannot do natural order without a primary key, please add it or
> specify a manual sort over existing attributes

This change avoids issuing STARTINDEX if:
* the feature count is known by the time the first GetFeature request is
  issued
* the feature count is less than the page size.

In other words, this change allows us to use small datasets that have no
primary key, while still allowing paging in larger datasets (as long
as they have a primary key)
  • Loading branch information
craigds committed Jul 26, 2023
1 parent d5d57fd commit 8720561
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions gdal/ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,22 @@ CPLString OGRWFSLayer::MakeGetFeatureURL(int nRequestMaxFeatures, int bRequestHi

if (poDS->IsPagingAllowed() && !bRequestHits)
{
osURL = CPLURLAddKVP(osURL, "STARTINDEX",
CPLSPrintf("%d", nPagingStartIndex +
poDS->GetBaseStartIndex()));
nRequestMaxFeatures = poDS->GetPageSize();
/* If the feature count is known and is less than the page size, we don't
* need to do paging. Skipping the pagination parameters improves compatibility
* with remote datasources that don't have a primary key.
* Without a primary key, the WFS server can't support paging, since there
* is no natural sort order defined. */
if (nFeatures < 0 ||
(nRequestMaxFeatures && nFeatures > nRequestMaxFeatures))
{
osURL =
CPLURLAddKVP(osURL, "STARTINDEX",
CPLSPrintf("%d", nPagingStartIndex +
poDS->GetBaseStartIndex()));
bPagingActive = true;
}
nFeatureCountRequested = nRequestMaxFeatures;
bPagingActive = true;
}

if (nRequestMaxFeatures)
Expand Down

0 comments on commit 8720561

Please sign in to comment.