Skip to content

Commit

Permalink
remove circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
lubojr committed Jun 27, 2024
1 parent 22deadf commit a25dd36
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
37 changes: 5 additions & 32 deletions src/eodash_catalog/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
get_or_create_collection,
)
from eodash_catalog.thumbnails import generate_thumbnail
from eodash_catalog.utils import create_geojson_point, retrieveExtentFromWMSWMTS
from eodash_catalog.utils import (
create_geojson_point,
generate_veda_cog_link,
retrieveExtentFromWMSWMTS,
)


def process_STAC_Datacube_Endpoint(config, endpoint, data, catalog):
Expand Down Expand Up @@ -478,37 +482,6 @@ def handle_GeoDB_Tiles_endpoint(config, endpoint, data, catalog):
raise NotImplementedError


def generate_veda_cog_link(endpoint, file_url):
bidx = ""
if "Bidx" in endpoint:
# Check if an array was provided
if hasattr(endpoint["Bidx"], "__len__"):
for band in endpoint["Bidx"]:
bidx = bidx + f"&bidx={band}"
else:
bidx = "&bidx={}".format(endpoint["Bidx"])

colormap = ""
if "Colormap" in endpoint:
colormap = "&colormap={}".format(endpoint["Colormap"])
# TODO: For now we assume a already urlparsed colormap definition
# it could be nice to allow a json and better convert it on the fly
# colormap = "&colormap=%s"%(urllib.parse.quote(str(endpoint["Colormap"])))

colormap_name = ""
if "ColormapName" in endpoint:
colormap_name = "&colormap_name={}".format(endpoint["ColormapName"])

rescale = ""
if "Rescale" in endpoint:
rescale = "&rescale={},{}".format(endpoint["Rescale"][0], endpoint["Rescale"][1])

file_url = f"url={file_url}&" if file_url else ""

target_url = f"https://staging-raster.delta-backend.com/cog/tiles/WebMercatorQuad/{{z}}/{{x}}/{{y}}?{file_url}resampling_method=nearest{bidx}{colormap}{colormap_name}{rescale}"
return target_url


def generate_veda_tiles_link(endpoint, item):
collection = "collection={}".format(endpoint["CollectionId"])
assets = ""
Expand Down
2 changes: 1 addition & 1 deletion src/eodash_catalog/thumbnails.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import requests

from eodash_catalog.endpoints import generate_veda_cog_link
from eodash_catalog.utils import generate_veda_cog_link


def fetch_and_save_thumbnail(data, url):
Expand Down
31 changes: 31 additions & 0 deletions src/eodash_catalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,34 @@ def recursive_save(stac_object: Catalog, no_items: bool = False) -> None:

def iter_len_at_least(i, n: int) -> int:
return sum(1 for _ in zip(range(n), i, strict=False)) == n


def generate_veda_cog_link(endpoint, file_url):
bidx = ""
if "Bidx" in endpoint:
# Check if an array was provided
if hasattr(endpoint["Bidx"], "__len__"):
for band in endpoint["Bidx"]:
bidx = bidx + f"&bidx={band}"
else:
bidx = "&bidx={}".format(endpoint["Bidx"])

colormap = ""
if "Colormap" in endpoint:
colormap = "&colormap={}".format(endpoint["Colormap"])
# TODO: For now we assume a already urlparsed colormap definition
# it could be nice to allow a json and better convert it on the fly
# colormap = "&colormap=%s"%(urllib.parse.quote(str(endpoint["Colormap"])))

colormap_name = ""
if "ColormapName" in endpoint:
colormap_name = "&colormap_name={}".format(endpoint["ColormapName"])

rescale = ""
if "Rescale" in endpoint:
rescale = "&rescale={},{}".format(endpoint["Rescale"][0], endpoint["Rescale"][1])

file_url = f"url={file_url}&" if file_url else ""

target_url = f"https://staging-raster.delta-backend.com/cog/tiles/WebMercatorQuad/{{z}}/{{x}}/{{y}}?{file_url}resampling_method=nearest{bidx}{colormap}{colormap_name}{rescale}"
return target_url

0 comments on commit a25dd36

Please sign in to comment.