-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
**render_params.kwargs
ito pass custom render params (#259)
* add `**render_params.kwargs` ito pass custom render params * update changelog
- Loading branch information
1 parent
989d1b4
commit 272d62d
Showing
6 changed files
with
101 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# """Test TiTiler Custom Render Params.""" | ||
|
||
from dataclasses import dataclass | ||
from typing import Optional, Union | ||
|
||
import numpy | ||
|
||
from titiler.dependencies import RenderParams | ||
from titiler.endpoints import factory | ||
|
||
from .conftest import DATA_DIR, parse_img | ||
|
||
from fastapi import FastAPI, Query | ||
|
||
from starlette.testclient import TestClient | ||
|
||
|
||
@dataclass | ||
class CustomRenderParams(RenderParams): | ||
|
||
output_nodata: Optional[Union[str, int, float]] = Query( | ||
None, title="Tiff Ouptut Nodata value", | ||
) | ||
output_compression: Optional[str] = Query( | ||
None, title="Tiff compression schema", | ||
) | ||
|
||
def __post_init__(self): | ||
super().__post_init__() | ||
if self.output_nodata is not None: | ||
self.kwargs["nodata"] = ( | ||
numpy.nan if self.output_nodata == "nan" else float(self.output_nodata) | ||
) | ||
if self.output_compression is not None: | ||
self.kwargs["compress"] = self.output_compression | ||
|
||
|
||
def test_CustomRender(): | ||
"""Test Custom Render Params dependency.""" | ||
app = FastAPI() | ||
cog = factory.TilerFactory(render_dependency=CustomRenderParams) | ||
app.include_router(cog.router) | ||
client = TestClient(app) | ||
|
||
response = client.get(f"/tiles/8/87/48.tif?url={DATA_DIR}/cog.tif") | ||
assert response.status_code == 200 | ||
assert response.headers["content-type"] == "image/tiff; application=geotiff" | ||
meta = parse_img(response.content) | ||
assert meta["driver"] == "GTiff" | ||
assert meta["nodata"] is None | ||
assert meta["count"] == 2 | ||
assert not meta.get("compress") | ||
|
||
response = client.get( | ||
f"/tiles/8/87/48.tif?url={DATA_DIR}/cog.tif&return_mask=false&output_nodata=0&output_compression=deflate" | ||
) | ||
assert response.status_code == 200 | ||
assert response.headers["content-type"] == "image/tiff; application=geotiff" | ||
meta = parse_img(response.content) | ||
assert meta["driver"] == "GTiff" | ||
assert meta["nodata"] == 0 | ||
assert meta["count"] == 1 | ||
assert meta["compress"] == "deflate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters