How can I return a paginated GeoJSON payload from an API, including page information?
The pagination applies to the number of features in a feature collection. If the standards specify pagination, links to the details would be useful. As far as I know the pagination for JSON/GeoJSON is not specified in specs e.g.
- https://www.rfc-editor.org/rfc/rfc7946 (geojson)
- https://www.rfc-editor.org/rfc/rfc8142 (geojsons)
For example, consider these two options. The first option is to add a "pages" data-structure to the GeoJSON, e.g.
{
"type": "FeatureCollection",
"features": [{
"geometry": {
"coordinates": [
[
[-123.3948022, 41.254734],
[-123.3948022, 41.2537144],
[-123.3907336, 41.2537144],
[-123.3907336, 41.254734],
[-123.3948022, 41.254734]
]
],
"type": "Polygon"
},
"properties": {
"level": 0
},
"type": "Feature"
}, {
"geometry": {
"coordinates": [
[
[-123.3907336, 41.254734],
[-123.3907336, 41.2537144],
[-123.3893774, 41.2537144],
[-123.3893774, 41.254734],
[-123.3907336, 41.254734]
]
],
"type": "Polygon"
},
"properties": {
"level": 2
},
"type": "Feature"
}],
"pages": {
"next": {
"limit": 2,
"offset": 2
},
"page": {
"limit": 2,
"offset": 0
},
"prev": null
}
}
The second option creates a nested JSON payload with separate geojson and pages fields, i.e. the pseudo-JSON is like:
{
"geojson": { ... },
"pages": {
"next": {
"limit": 2,
"offset": 2
},
"page": {
"limit": 2,
"offset": 0
},
"prev": null
}
}
Or similarly, but without the extra "pages" nesting:
{
"geojson": { ... },
"next": {
"limit": 2,
"offset": 2
},
"page": {
"limit": 2,
"offset": 0
},
"prev": null
}