Skip to content

Commit

Permalink
support different crs, spatial sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Nov 10, 2023
1 parent d0f99cf commit de107a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 5 additions & 1 deletion metadata_catalogue/datasets/libs/csw_query.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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


Expand Down
8 changes: 3 additions & 5 deletions metadata_catalogue/datasets/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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


Expand Down

0 comments on commit de107a4

Please sign in to comment.