geopython / pygeoapi

pygeoapi is a Python server implementation of the OGC API suite of standards. The project emerged as part of the next generation OGC API efforts in 2018 and provides the capability for organizations to deploy a RESTful OGC API endpoint using OpenAPI, GeoJSON, and HTML. pygeoapi is open source and released under an MIT license.
https://pygeoapi.io
MIT License
459 stars 250 forks source link

Broken pagination for features #1658

Open barbuz opened 1 month ago

barbuz commented 1 month ago

Description When querying a features collection which should return a result with more features than the limit, there appears to be no "next" link in the result to get the next page. Additionally, following the "json" link removes the "offset" parameter from the query and goes to the first page of results.

Steps to Reproduce This is visible in the demo instance: https://demo.pygeoapi.io/master/collections/dutch_castles/items?limit=10&offset=20

And also in the corresponding json (with offset parameter manually added): https://demo.pygeoapi.io/master/collections/dutch_castles/items?f=json&limit=10&offset=20

And same for the stable version: https://demo.pygeoapi.io/stable/collections/dutch_castles/items?limit=10&offset=20 https://demo.pygeoapi.io/stable/collections/dutch_castles/items?f=json&limit=10&offset=20

Notice how there is a "prev" link to the previous page but no way to go to the next page.

Expected behavior All pages except the last should contain a "next" link. The "json" link should keep all the same parameters as the original query.

Screenshots/Tracebacks image

Environment

frafra commented 1 month ago

https://github.com/geopython/pygeoapi/blob/6c31a8e371d10750f265357bab62b45bfa9abc8f/pygeoapi/api/itemtypes.py#L532-L533

numberMatched is provider-dependent.

I see that the ogr provider computes numberMatched when asking for the hits (does it make sense to generate a "next" link for the hits?):

https://github.com/geopython/pygeoapi/blob/6c31a8e371d10750f265357bab62b45bfa9abc8f/pygeoapi/provider/ogr.py#L597-L601

This is the reply for the records:

https://github.com/geopython/pygeoapi/blob/6c31a8e371d10750f265357bab62b45bfa9abc8f/pygeoapi/provider/ogr.py#L550-L553

The main issue in using layer.GetFeatureCount() is that could kill performances in some cases, but we do not need to use that just to know if there are more records: we can increment numMatched if there is more, so that the next link is generated.

tomkralidis commented 12 hours ago

numberMatched (and numberReturned for that matter, even though it is mostly a function of len(features])) are optional properties of an OGC API - Features /collections/{collectionId}/items response. numberMatched may be expensive to calculate in some cases, which is why it is optional (some search engines exhibit the same behaviour).

Having said this, prev/next links are also optional parts of an OGC API - Features /collections/{collectionId}/items response.

As a result, providers are not required to implement paging, however it is great if they can do so efficiently.

@frafra what is the status of #1662?