From 1459dd0d72183de57bd547cbbb2727f98d94c3c0 Mon Sep 17 00:00:00 2001 From: Gabriele Tramonte Date: Fri, 3 May 2024 11:12:43 +0200 Subject: [PATCH] adding projection to api get map --- api/app/main.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/api/app/main.py b/api/app/main.py index f5db887..df46646 100644 --- a/api/app/main.py +++ b/api/app/main.py @@ -2,7 +2,7 @@ __version__ = "2.0" import os from typing import Optional, Dict - +from geokube.core.coord_system import TransverseMercator, GeogCS from datetime import datetime from fastapi import FastAPI, HTTPException, Request, status, Query @@ -220,9 +220,19 @@ async def get_map( # vertical: Optional[Union[float, List[float], Dict[str, float]]] # filters: Optional[Dict] # format: Optional[str] - query = map_to_geoquery(variables=layers, bbox=bbox, time=time, - format="png", width=width, height=height, - transparent=transparent, bgcolor=bgcolor, dpi=dpi, cmap=cmap) + + if crs == "3857": + airy1830 = GeogCS(6377563.396, 6356256.909) + osgb = TransverseMercator(49, -2, 400000, -100000, 0.9996012717, ellipsoid=airy1830) + query = map_to_geoquery(variables=layers, bbox=bbox, time=time, + format="png", width=width, height=height, + transparent=transparent, bgcolor=bgcolor, + dpi=dpi, cmap=cmap, projection=osgb) + else: + query = map_to_geoquery(variables=layers, bbox=bbox, time=time, + format="png", width=width, height=height, + transparent=transparent, bgcolor=bgcolor, + dpi=dpi, cmap=cmap) try: return dataset_handler.sync_query( user_id=request.user.id, @@ -292,9 +302,20 @@ async def get_map_with_filters( # vertical: Optional[Union[float, List[float], Dict[str, float]]] # filters: Optional[Dict] # format: Optional[str] - query = map_to_geoquery(variables=layers, bbox=bbox, time=time, filters=filters_dict, - format="png", width=width, height=height, - transparent=transparent, bgcolor=bgcolor, dpi=dpi, cmap=cmap) + + if crs == "3857": + airy1830 = GeogCS(6377563.396, 6356256.909) + osgb = TransverseMercator(49, -2, 400000, -100000, 0.9996012717, ellipsoid=airy1830) + query = map_to_geoquery(variables=layers, bbox=bbox, time=time, filters=filters_dict, + format="png", width=width, height=height, + transparent=transparent, bgcolor=bgcolor, + dpi=dpi, cmap=cmap, projection=osgb) + else: + query = map_to_geoquery(variables=layers, bbox=bbox, time=time, filters=filters_dict, + format="png", width=width, height=height, + transparent=transparent, bgcolor=bgcolor, + dpi=dpi, cmap=cmap) + try: return dataset_handler.sync_query( user_id=request.user.id,