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
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 25, 2023
1 parent 810d4ac commit bb5dfb5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ogr/ogrsf_frmts/wfs/ogrwfslayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,22 @@ CPLString OGRWFSLayer::MakeGetFeatureURL(int nRequestMaxFeatures,

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 bb5dfb5

Please sign in to comment.