Skip to content

Commit 424fb7a

Browse files
committed
Bbox server side filtering
1 parent 1b3be7e commit 424fb7a

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

app/api/tasks.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from django.http import FileResponse
1818
from django.http import HttpResponse
1919
from django.http import StreamingHttpResponse
20+
from django.contrib.gis.geos import Polygon
2021
from app.vendor import zipfly
2122
from rest_framework import status, serializers, viewsets, filters, exceptions, permissions, parsers
2223
from rest_framework.decorators import action
@@ -175,7 +176,15 @@ def list(self, request, project_pk=None):
175176
for a in assets:
176177
query['available_assets__contains'] = "{" + a + "}"
177178

178-
# TODO bounding box filtering
179+
bbox = request.query_params.get('bbox')
180+
if bbox is not None:
181+
try:
182+
xmin, ymin, xmax, ymax = [float(v) for v in bbox.split(",")]
183+
except:
184+
raise exceptions.ValidationError("Invalid bbox parameter")
185+
186+
geom = Polygon.from_bbox((xmin, ymin, xmax, ymax))
187+
query['orthophoto_extent__intersects'] = geom
179188

180189
tasks = self.queryset.filter(**query)
181190
tasks = filters.OrderingFilter().filter_queryset(self.request, tasks, self)

app/static/app/js/components/MapPreview.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ _('Example:'),
226226
}
227227

228228
computeBbox = exifData => {
229-
// minx, maxx, miny, maxy
230-
let bbox = [Infinity, -Infinity, Infinity, -Infinity];
229+
// minx, miny, maxx, maxy
230+
let bbox = [Infinity, Infinity, -Infinity, -Infinity];
231231
exifData.forEach(ed => {
232232
if (ed.gps){
233233
bbox[0] = Math.min(bbox[0], ed.gps.longitude);
234-
bbox[1] = Math.max(bbox[1], ed.gps.longitude);
235-
bbox[2] = Math.min(bbox[2], ed.gps.latitude);
234+
bbox[1] = Math.min(bbox[1], ed.gps.latitude);
235+
bbox[2] = Math.max(bbox[2], ed.gps.longitude);
236236
bbox[3] = Math.max(bbox[3], ed.gps.latitude);
237237
}
238238
});

app/static/app/js/components/NewTaskPanel.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ class NewTaskPanel extends React.Component {
7676
}
7777

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

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

180179
handleImagesBboxChange = (bbox) => {
181180
if (this.props.showAlign){
182-
console.log("TODO! Load alignment tasks that fit within", bbox);
183181
this.loadAlignTasks(bbox);
184182
}
185183
}

0 commit comments

Comments
 (0)