From de107a4eea5d9f1b720ab64e17ff0dffff9085d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Fri, 10 Nov 2023 12:14:36 +0100 Subject: [PATCH] support different crs, spatial sorting --- metadata_catalogue/datasets/libs/csw_query.py | 6 +++++- metadata_catalogue/datasets/managers.py | 8 +++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/metadata_catalogue/datasets/libs/csw_query.py b/metadata_catalogue/datasets/libs/csw_query.py index 770202b..00e0ae2 100644 --- a/metadata_catalogue/datasets/libs/csw_query.py +++ b/metadata_catalogue/datasets/libs/csw_query.py @@ -1,6 +1,7 @@ import operator from functools import reduce +import pyproj from django.contrib.gis.geos import Polygon from django.db.models import Q @@ -11,7 +12,10 @@ def bbox_to_geometry(bbox): xmin, ymin = bbox["gml:lowerCorner"].split(" ") xmax, ymax = bbox["gml:upperCorner"].split(" ") p = Polygon.from_bbox((xmin, ymin, xmax, ymax)) - p.srid = 4326 + if "@srsName" in bbox: + p.srid = pyproj.CRS.from_string(bbox["@srsName"]).to_epsg() + else: + p.srid = 4326 return p diff --git a/metadata_catalogue/datasets/managers.py b/metadata_catalogue/datasets/managers.py index 3118cc5..18e02d7 100644 --- a/metadata_catalogue/datasets/managers.py +++ b/metadata_catalogue/datasets/managers.py @@ -4,9 +4,7 @@ from .libs.csw_mapping import CSWMapping from .libs.csw_query import Group -SORT_CONFIG = { - "title": "metadata__title", -} +SORT_CONFIG = {"title": "metadata__title", "csw_wkt_geometry": "metadata__bounding_box"} class DatasetQuerySet(models.QuerySet): @@ -28,8 +26,8 @@ def csw_filter(self, filter): def csw_sort(self, sort): try: return self.order_by(f'{"-" if sort["order"] == "DESC" else ""}{SORT_CONFIG[sort["propertyname"]]}') - except KeyError: - logger.warn(f"Not implemented! {sort.propertyname}") + except (AttributeError, KeyError): + logger.warn(f"Not implemented! {sort}") return self