Skip to content

Commit

Permalink
Bbox server side filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Feb 19, 2025
1 parent 1b3be7e commit 424fb7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 10 additions & 1 deletion app/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.http import FileResponse
from django.http import HttpResponse
from django.http import StreamingHttpResponse
from django.contrib.gis.geos import Polygon
from app.vendor import zipfly
from rest_framework import status, serializers, viewsets, filters, exceptions, permissions, parsers
from rest_framework.decorators import action
Expand Down Expand Up @@ -175,7 +176,15 @@ def list(self, request, project_pk=None):
for a in assets:
query['available_assets__contains'] = "{" + a + "}"

# TODO bounding box filtering
bbox = request.query_params.get('bbox')
if bbox is not None:
try:
xmin, ymin, xmax, ymax = [float(v) for v in bbox.split(",")]
except:
raise exceptions.ValidationError("Invalid bbox parameter")

geom = Polygon.from_bbox((xmin, ymin, xmax, ymax))
query['orthophoto_extent__intersects'] = geom

tasks = self.queryset.filter(**query)
tasks = filters.OrderingFilter().filter_queryset(self.request, tasks, self)
Expand Down
8 changes: 4 additions & 4 deletions app/static/app/js/components/MapPreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ _('Example:'),
}

computeBbox = exifData => {
// minx, maxx, miny, maxy
let bbox = [Infinity, -Infinity, Infinity, -Infinity];
// minx, miny, maxx, maxy
let bbox = [Infinity, Infinity, -Infinity, -Infinity];
exifData.forEach(ed => {
if (ed.gps){
bbox[0] = Math.min(bbox[0], ed.gps.longitude);
bbox[1] = Math.max(bbox[1], ed.gps.longitude);
bbox[2] = Math.min(bbox[2], ed.gps.latitude);
bbox[1] = Math.min(bbox[1], ed.gps.latitude);
bbox[2] = Math.max(bbox[2], ed.gps.longitude);
bbox[3] = Math.max(bbox[3], ed.gps.latitude);
}
});
Expand Down
4 changes: 1 addition & 3 deletions app/static/app/js/components/NewTaskPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ class NewTaskPanel extends React.Component {
}

loadAlignTasks = (bbox) => {
// TODO: filter by bbox
this.setState({alignTasks: [], alignTo: "auto", loadingAlignTasks: true});

this.alignTasksRequest =
$.getJSON(`/api/projects/${this.props.projectId}/tasks/?ordering=-created_at&status=${statusCodes.COMPLETED}&available_assets=georeferenced_model.laz`, tasks => {
$.getJSON(`/api/projects/${this.props.projectId}/tasks/?ordering=-created_at&status=${statusCodes.COMPLETED}&available_assets=georeferenced_model.laz&bbox=${bbox.join(",")}`, tasks => {
if (Array.isArray(tasks)){
this.setState({loadingAlignTasks: false, alignTasks: tasks});
}else{
Expand Down Expand Up @@ -179,7 +178,6 @@ class NewTaskPanel extends React.Component {

handleImagesBboxChange = (bbox) => {
if (this.props.showAlign){
console.log("TODO! Load alignment tasks that fit within", bbox);
this.loadAlignTasks(bbox);
}
}
Expand Down

0 comments on commit 424fb7a

Please sign in to comment.