WIP: add bbox endpoint for forms, dataviews, and merged datasets#3066
Closed
FrankApiyo wants to merge 1 commit into
Closed
WIP: add bbox endpoint for forms, dataviews, and merged datasets#3066FrankApiyo wants to merge 1 commit into
FrankApiyo wants to merge 1 commit into
Conversation
Adds GET /api/v1/forms/{id}/bbox, /dataviews/{id}/bbox, and
/merged-datasets/{id}/bbox returning {"bbox": [min_lng, min_lat, max_lng,
max_lat] | null} — the extent of geolocated submissions.
Motivation: Zonkey's tile-based map view (Martin + form_tiles()) cannot
compute bounds client-side since features are paged per MVT tile. A
dedicated endpoint lets the frontend fit the viewport on load without
fetching the full submission set.
Implementation:
- onadata/libs/utils/bbox_tools.py: shared `compute_instance_bbox` helper
using Django GIS Extent aggregate. Mirrors the filter shape of the
`form_tiles()` PostGIS function (non-deleted, geom non-null, optional
dataview query filter) so the fit matches the data Martin serves.
- Three viewset @action methods (XForm/DataView/MergedXForm) wrapping the
helper. Permissions inherit from the existing viewset class.
- Tests:
* XForm: extent with the gps fixture, null when no geoms
* DataView + MergedXForm: null-shape verification (helper itself is
covered by the XForm extent test since all three viewset actions
share it)
Returns null rather than 404 when a target has no geolocated rows so
callers can fall back to a default view cleanly.
5 tasks
Member
Author
|
Superseded by #3072 — rebased onto main and renamed branch from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
GET /api/v1/forms/{id}/bbox,/api/v1/dataviews/{id}/bbox, and/api/v1/merged-datasets/{id}/bbox.Each returns
{"bbox": [min_lng, min_lat, max_lng, max_lat] | null}— the extent of geolocated submissions (null when the target has no geolocated rows, so callers can fall back to a default view cleanly).Motivation
Zonkey's tile-based map view (Martin +
form_tiles()) cannot compute bounds client-side since features are paged per MVT tile. A dedicated endpoint lets the frontend fit the viewport on first load without fetching the full submission set.Design
onadata/libs/utils/bbox_tools.py— sharedcompute_instance_bbox(xform_ids, dataview=None)helper using Django GISExtentaggregateform_tiles()PostGIS function (non-deleted, geom non-null, optional dataview query filter) so the fit matches the data Martin serves@actionmethods (XFormViewSet,DataViewViewSet,MergedXFormViewSet) wrap the helper; permissions inherit from each viewset's existing classTest plan
test_bbox_returns_extent_of_geolocated_submissions— XForm with the gps fixture returns a valid 4-tuple bboxtest_bbox_null_when_no_geolocated_submissions— returns{"bbox": null}for forms without geomsConsumers
TileMapView) →useFormBboxhook →fitBoundson map load. Work in progress on the martin branch of zonkey.Why WIP
Marking WIP pending:
bbox_toolshelper should live inlibs/utils/or somewhere closer to the logger models