Bbox server side filtering

pull/1615/head
Piero Toffanin 2025-02-19 17:45:03 -05:00
rodzic 1b3be7eee2
commit 424fb7a2cc
3 zmienionych plików z 15 dodań i 8 usunięć

Wyświetl plik

@ -17,6 +17,7 @@ from django.db import transaction
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
@ -175,7 +176,15 @@ class TaskViewSet(viewsets.ViewSet):
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)

Wyświetl plik

@ -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);
}
});

Wyświetl plik

@ -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{
@ -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);
}
}