Replies: 2 comments
-
|
it would help to get any error message you're getting. We usually try to update all the example but there is a possibility that we missed something |
Beta Was this translation helpful? Give feedback.
-
|
I've copied https://developmentseed.org/titiler/examples/code/mosaic_from_urls/ into a single file you can run with Mosaic example app code#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "fastapi>=0.116.1",
# "titiler-mosaic>=0.23.1",
# "uvicorn>=0.35.0",
# ]
# ///
from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers
from titiler.mosaic.errors import MOSAIC_STATUS_CODES
from fastapi import FastAPI
from dataclasses import dataclass
from typing import List
from titiler.mosaic.factory import MosaicTilerFactory
from fastapi import Query
from typing import Type, List, Tuple, Dict, Union
import attr
from rio_tiler.io import BaseReader, COGReader, MultiBandReader, MultiBaseReader
from rio_tiler.constants import WEB_MERCATOR_TMS, WGS84_CRS
from rasterio.crs import CRS
from morecantile import TileMatrixSet
from cogeo_mosaic.backends.base import BaseBackend
from cogeo_mosaic.mosaic import MosaicJSON
@attr.s
class MultiFilesBackend(BaseBackend):
input: List[str] = attr.ib()
reader: Union[
Type[BaseReader],
Type[MultiBaseReader],
Type[MultiBandReader],
] = attr.ib(default=COGReader)
reader_options: Dict = attr.ib(factory=dict)
geographic_crs: CRS = attr.ib(default=WGS84_CRS)
tms: TileMatrixSet = attr.ib(default=WEB_MERCATOR_TMS)
minzoom: int = attr.ib(default=0)
maxzoom: int = attr.ib(default=30)
# default values for bounds
bounds: Tuple[float, float, float, float] = attr.ib(default=(-180, -90, 180, 90))
crs: CRS = attr.ib(init=False, default=WGS84_CRS)
# mosaic_def is outside the __init__ method
mosaic_def: MosaicJSON = attr.ib(init=False)
_backend_name = "MultiFiles"
def __attrs_post_init__(self):
"""Post Init."""
# Construct a FAKE/Empty mosaicJSON
# mosaic_def has to be defined.
self.mosaic_def = MosaicJSON(
mosaicjson="0.0.2",
name="it's fake but it's ok",
minzoom=self.minzoom,
maxzoom=self.maxzoom,
tiles=[], # we set `tiles` to an empty list.
)
def write(self, overwrite: bool = True):
"""This method is not used but is required by the abstract class."""
pass
def update(self):
"""We overwrite the default method."""
pass
def _read(self) -> MosaicJSON:
"""This method is not used but is required by the abstract class."""
pass
def assets_for_tile(self, x: int, y: int, z: int) -> List[str]:
"""Retrieve assets for tile."""
return self.get_assets()
def assets_for_point(self, lng: float, lat: float) -> List[str]:
"""Retrieve assets for point."""
return self.get_assets()
def get_assets(self) -> List[str]:
"""assets are just files we give in path"""
return self.input
@property
def _quadkeys(self) -> List[str]:
return []
@dataclass
class MosaicTiler(MosaicTilerFactory):
"""Custom MosaicTilerFactory.
Note this is a really simple MosaicTiler Factory with only few endpoints.
"""
def register_routes(self):
"""This Method register routes to the router."""
self.tile()
self.tilejson()
def DatasetPathParams(url: str = Query(..., description="Dataset URL")) -> List[str]:
"""Create dataset path from args"""
return url.split(",")
mosaic = MosaicTiler(backend=MultiFilesBackend, path_dependency=DatasetPathParams)
app = FastAPI()
app.include_router(mosaic.router)
add_exception_handlers(app, DEFAULT_STATUS_CODES)
add_exception_handlers(app, MOSAIC_STATUS_CODES)The error is: "TypeError: MosaicTiler.init() got an unexpected keyword argument 'backend'" But I was more interested in general advice. Like even once I seemed to have fixed that there were more errors. And I felt the code itself was not a good place to look for usage details. Like there's nothing in class MosaicTilerFactory(BaseFactory):
"""MosaicTiler Factory."""
backend: Type[BaseBackend] = MosaicBackend
backend_dependency: Type[DefaultDependency] = DefaultDependencyThat's fine if there just isn't any documentation. I just wonder if I'm missing something that would help me. I guess I'll just have to ask a lot of questions here on Github? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm struggling to get the mosaic example working: https://developmentseed.org/titiler/examples/code/mosaic_from_urls/
I'm using 0.23.1
Should the examples work as is? Or is the more I need to know? Or should I be using an older more compatible version?
Beta Was this translation helpful? Give feedback.
All reactions