titiler.extensions


Nametitiler.extensions JSON
Version 0.19.1 PyPI version JSON
download
home_pageNone
SummaryExtensions for TiTiler Factories.
upload_time2024-11-14 13:30:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords cog stac mosaicjson fastapi dynamic tile server gdal rasterio ogc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## titiler.extensions

Extent TiTiler Tiler Factories

## Installation

```bash
python -m pip install -U pip

# From Pypi
python -m pip install titiler.extensions

# Or from sources
git clone https://github.com/developmentseed/titiler.git
cd titiler && python -m pip install -e src/titiler/core -e src/titiler/extensions
```

## Available extensions

#### cogValidateExtension

- Goal: adds a `/validate` endpoint which return the content of rio-cogeo `info` method
- Additional requirements: `titiler.extensions["cogeo"]`

#### cogViewerExtension

- Goal: adds a `/viewer` endpoint which return an HTML viewer for simple COGs

#### stacViewerExtension

- Goal: adds a `/viewer` endpoint which return an HTML viewer for STAC item

#### wmsExtension

- Goal: adds a `/wms` endpoint to support OGC Web Map Service (`GetTile` and `GetCapabilities`) specification

## Use extensions

Extensions must be set at TilerFactory's creation using the `extensions=` options.

```python
from fastapi import FastAPI
from titiler.core.factory import TilerFactory
from titiler.extensions import cogValidateExtension

# Create a FastAPI application
app = FastAPI(description="A lightweight Cloud Optimized GeoTIFF tile server")

# Create a set of endpoints using TiTiler TilerFactory
tiler = TilerFactory(
    router_prefix="/cog",
    extensions=[
        cogValidateExtension()  # the cogeoExtension will add a rio-cogeo /validate endpoint
    ]
)

# Register endpoints to the application
app.include_router(tiler.router, prefix="/cog")
```

See [titiler.application](../application) for a full example.


## Create your own

```python
from dataclasses import dataclass, field
from typing import Tuple, List, Optional

from starlette.responses import Response
from fastapi import Depends, FastAPI, Query
from titiler.core.factory import BaseTilerFactory, FactoryExtension, TilerFactory
from titiler.core.dependencies import RescalingParams
from titiler.core.factory import TilerFactory
from titiler.core.resources.enums import ImageType


@dataclass
class thumbnailExtension(FactoryExtension):
    """Add endpoint to a TilerFactory."""

    # Set some options
    max_size: int = field(default=128)

    # Register method is mandatory and must take a BaseTilerFactory object as input
    def register(self, factory: BaseTilerFactory):
        """Register endpoint to the tiler factory."""

        # register an endpoint to the factory's router
        @factory.router.get(
            "/thumbnail",
            responses={
                200: {
                    "content": {
                        "image/png": {},
                        "image/jpeg": {},
                    },
                    "description": "Return an image.",
                }
            },
            response_class=Response,
        )
        def thumbnail(
            # we can reuse the factory dependency
            src_path: str = Depends(factory.path_dependency),
            layer_params=Depends(factory.layer_dependency),
            dataset_params=Depends(factory.dataset_dependency),
            post_process=Depends(factory.process_dependency),
            rescale: Optional[List[Tuple[float, ...]]] = Depends(RescalingParams),
            color_formula: Optional[str] = Query(
                None,
                title="Color Formula",
                description="rio-color formula (info: https://github.com/mapbox/rio-color)",
            ),
            colormap=Depends(factory.colormap_dependency),
            render_params=Depends(factory.render_dependency),
            reader_params=Depends(factory.reader_dependency),
            env=Depends(factory.environment_dependency),
        ):
            with rasterio.Env(**env):
                with factory.reader(src_path, **reader_params) as src:
                    image = src.preview(
                        max_size=self.max_size,
                        **layer_params,
                        **dataset_params,
                    )

            if post_process:
                image = post_process(image)

            if rescale:
                image.rescale(rescale)

            if color_formula:
                image.apply_color_formula(color_formula)

            format = ImageType.jpeg if image.mask.all() else ImageType.png

            content = image.render(
                img_format=format.driver,
                colormap=colormap,
                **format.profile,
                **render_params,
            )

            return Response(content, media_type=format.mediatype)

# Use it
app = FastAPI()
tiler = TilerFactory(
    extensions=[
        thumbnailExtension(max_size=64)
    ]
)
app.include_router(tiler.router)
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "titiler.extensions",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "COG, STAC, MosaicJSON, Fastapi, Dynamic tile server, GDAL, Rasterio, OGC",
    "author": null,
    "author_email": "Vincent Sarago <vincent@developmentseed.com>",
    "download_url": "https://files.pythonhosted.org/packages/67/41/b0a1870f7789163002aa689d3d54803b5a684566bd5f4fc57a1a18b9f57f/titiler.extensions-0.19.1.tar.gz",
    "platform": null,
    "description": "## titiler.extensions\n\nExtent TiTiler Tiler Factories\n\n## Installation\n\n```bash\npython -m pip install -U pip\n\n# From Pypi\npython -m pip install titiler.extensions\n\n# Or from sources\ngit clone https://github.com/developmentseed/titiler.git\ncd titiler && python -m pip install -e src/titiler/core -e src/titiler/extensions\n```\n\n## Available extensions\n\n#### cogValidateExtension\n\n- Goal: adds a `/validate` endpoint which return the content of rio-cogeo `info` method\n- Additional requirements: `titiler.extensions[\"cogeo\"]`\n\n#### cogViewerExtension\n\n- Goal: adds a `/viewer` endpoint which return an HTML viewer for simple COGs\n\n#### stacViewerExtension\n\n- Goal: adds a `/viewer` endpoint which return an HTML viewer for STAC item\n\n#### wmsExtension\n\n- Goal: adds a `/wms` endpoint to support OGC Web Map Service (`GetTile` and `GetCapabilities`) specification\n\n## Use extensions\n\nExtensions must be set at TilerFactory's creation using the `extensions=` options.\n\n```python\nfrom fastapi import FastAPI\nfrom titiler.core.factory import TilerFactory\nfrom titiler.extensions import cogValidateExtension\n\n# Create a FastAPI application\napp = FastAPI(description=\"A lightweight Cloud Optimized GeoTIFF tile server\")\n\n# Create a set of endpoints using TiTiler TilerFactory\ntiler = TilerFactory(\n    router_prefix=\"/cog\",\n    extensions=[\n        cogValidateExtension()  # the cogeoExtension will add a rio-cogeo /validate endpoint\n    ]\n)\n\n# Register endpoints to the application\napp.include_router(tiler.router, prefix=\"/cog\")\n```\n\nSee [titiler.application](../application) for a full example.\n\n\n## Create your own\n\n```python\nfrom dataclasses import dataclass, field\nfrom typing import Tuple, List, Optional\n\nfrom starlette.responses import Response\nfrom fastapi import Depends, FastAPI, Query\nfrom titiler.core.factory import BaseTilerFactory, FactoryExtension, TilerFactory\nfrom titiler.core.dependencies import RescalingParams\nfrom titiler.core.factory import TilerFactory\nfrom titiler.core.resources.enums import ImageType\n\n\n@dataclass\nclass thumbnailExtension(FactoryExtension):\n    \"\"\"Add endpoint to a TilerFactory.\"\"\"\n\n    # Set some options\n    max_size: int = field(default=128)\n\n    # Register method is mandatory and must take a BaseTilerFactory object as input\n    def register(self, factory: BaseTilerFactory):\n        \"\"\"Register endpoint to the tiler factory.\"\"\"\n\n        # register an endpoint to the factory's router\n        @factory.router.get(\n            \"/thumbnail\",\n            responses={\n                200: {\n                    \"content\": {\n                        \"image/png\": {},\n                        \"image/jpeg\": {},\n                    },\n                    \"description\": \"Return an image.\",\n                }\n            },\n            response_class=Response,\n        )\n        def thumbnail(\n            # we can reuse the factory dependency\n            src_path: str = Depends(factory.path_dependency),\n            layer_params=Depends(factory.layer_dependency),\n            dataset_params=Depends(factory.dataset_dependency),\n            post_process=Depends(factory.process_dependency),\n            rescale: Optional[List[Tuple[float, ...]]] = Depends(RescalingParams),\n            color_formula: Optional[str] = Query(\n                None,\n                title=\"Color Formula\",\n                description=\"rio-color formula (info: https://github.com/mapbox/rio-color)\",\n            ),\n            colormap=Depends(factory.colormap_dependency),\n            render_params=Depends(factory.render_dependency),\n            reader_params=Depends(factory.reader_dependency),\n            env=Depends(factory.environment_dependency),\n        ):\n            with rasterio.Env(**env):\n                with factory.reader(src_path, **reader_params) as src:\n                    image = src.preview(\n                        max_size=self.max_size,\n                        **layer_params,\n                        **dataset_params,\n                    )\n\n            if post_process:\n                image = post_process(image)\n\n            if rescale:\n                image.rescale(rescale)\n\n            if color_formula:\n                image.apply_color_formula(color_formula)\n\n            format = ImageType.jpeg if image.mask.all() else ImageType.png\n\n            content = image.render(\n                img_format=format.driver,\n                colormap=colormap,\n                **format.profile,\n                **render_params,\n            )\n\n            return Response(content, media_type=format.mediatype)\n\n# Use it\napp = FastAPI()\ntiler = TilerFactory(\n    extensions=[\n        thumbnailExtension(max_size=64)\n    ]\n)\napp.include_router(tiler.router)\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Extensions for TiTiler Factories.",
    "version": "0.19.1",
    "project_urls": {
        "Changelog": "https://developmentseed.org/titiler/release-notes/",
        "Documentation": "https://developmentseed.org/titiler/",
        "Homepage": "https://developmentseed.org/titiler/",
        "Issues": "https://github.com/developmentseed/titiler/issues",
        "Source": "https://github.com/developmentseed/titiler"
    },
    "split_keywords": [
        "cog",
        " stac",
        " mosaicjson",
        " fastapi",
        " dynamic tile server",
        " gdal",
        " rasterio",
        " ogc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a45d4366a34364e9aecbfa5235d5822dbaa686f98ea6c7aaa74a162e96b336fd",
                "md5": "bcbd7b4aa9bc051f131f0b60f3d91268",
                "sha256": "94d734fd8463f8865eb9a79c9c66f04febf05d81541d5d0c53f50676da934bfe"
            },
            "downloads": -1,
            "filename": "titiler.extensions-0.19.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bcbd7b4aa9bc051f131f0b60f3d91268",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 31017,
            "upload_time": "2024-11-14T13:30:13",
            "upload_time_iso_8601": "2024-11-14T13:30:13.829390Z",
            "url": "https://files.pythonhosted.org/packages/a4/5d/4366a34364e9aecbfa5235d5822dbaa686f98ea6c7aaa74a162e96b336fd/titiler.extensions-0.19.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6741b0a1870f7789163002aa689d3d54803b5a684566bd5f4fc57a1a18b9f57f",
                "md5": "95b2ee92cc20b24f695c5bbf41d9239f",
                "sha256": "c33d8f3163225a0f2f2a55fedc83fa106787a8fcd4744d6b3c31568baa18a27c"
            },
            "downloads": -1,
            "filename": "titiler.extensions-0.19.1.tar.gz",
            "has_sig": false,
            "md5_digest": "95b2ee92cc20b24f695c5bbf41d9239f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 27517,
            "upload_time": "2024-11-14T13:30:15",
            "upload_time_iso_8601": "2024-11-14T13:30:15.052722Z",
            "url": "https://files.pythonhosted.org/packages/67/41/b0a1870f7789163002aa689d3d54803b5a684566bd5f4fc57a1a18b9f57f/titiler.extensions-0.19.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-14 13:30:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "developmentseed",
    "github_project": "titiler",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "titiler.extensions"
}
        
Elapsed time: 0.73432s