From b0d290bfcb6e5f057d4fb64fda21feb2aeb72ead Mon Sep 17 00:00:00 2001 From: Matthew Iannucci Date: Thu, 17 Oct 2024 08:56:09 -0400 Subject: [PATCH] Add xyz tile support (#92) --- requirements.txt | 1 + xpublish_wms/wms/get_map.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index e6bd387..716e682 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ cartopy cf_xarray datashader matplotlib +mercantile Pillow xarray xpublish>=0.3.0,<0.4.0 diff --git a/xpublish_wms/wms/get_map.py b/xpublish_wms/wms/get_map.py index dd9d519..e9f5660 100644 --- a/xpublish_wms/wms/get_map.py +++ b/xpublish_wms/wms/get_map.py @@ -9,6 +9,7 @@ import datashader as dsh import datashader.transfer_functions as tf import matplotlib.cm as cm +import mercantile import numpy as np import pandas as pd import xarray as xr @@ -87,7 +88,7 @@ def get_minmax(self, ds: xr.Dataset, query: dict) -> dict: entire_layer = False if "bbox" not in query: # When BBOX is not specified, we are just going to slice the layer in time and elevation - # and return the min and max values for the entire layer so bbox can just be the whoel world + # and return the min and max values for the entire layer so bbox can just be the whole world entire_layer = True query["bbox"] = "-180,-90,180,90" query["width"] = 1 @@ -134,7 +135,12 @@ def ensure_query_types(self, ds: xr.Dataset, query: dict): # Grid self.crs = query.get("crs", None) or query.get("srs") - self.bbox = [float(x) for x in query["bbox"].split(",")] + tile = query.get("tile", None) + if tile is not None: + tile = [float(x) for x in query["tile"].split(",")] + self.bbox = mercantile.xy_bounds(*tile) + else: + self.bbox = [float(x) for x in query["bbox"].split(",")] self.width = int(query["width"]) self.height = int(query["height"])