Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a reproject query parameter to be passed as a reproject_method argument to rio-tiler #714

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ cd titiler

python -m pip install \
pre-commit \
-e src/titiler/core["test"] \
-e src/titiler/extensions["test,cogeo,stac"] \
-e src/titiler/mosaic["test"] \
-e src/titiler/application["test"]
-e "src/titiler/core[test]" \
-e "src/titiler/extensions[test,cogeo,stac]" \
-e "src/titiler/mosaic[test]" \
-e "src/titiler/application[test]"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was just some invalid syntax. It tripped me up so I thought I'd sneak this change in to help others.

Copy link
Contributor Author

@DanSchoppe DanSchoppe Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```

**pre-commit**
Expand Down
8 changes: 7 additions & 1 deletion docs/src/advanced/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class BidxExprParams(ExpressionParams, BidxParams):

#### dataset_dependency

Overwrite nodata value, apply rescaling or change default resampling.
Overwrite nodata value, apply rescaling, or change the default method used for resampling or reprojection.

```python
@dataclass
Expand All @@ -139,12 +139,18 @@ class DatasetParams(DefaultDependency):
alias="resampling",
description="Resampling method.",
)
reproject_method: ResamplingName = Query(
ResamplingName.nearest, # type: ignore
alias="reproject",
description="Reproject method.",
)

def __post_init__(self):
"""Post Init."""
if self.nodata is not None:
self.nodata = numpy.nan if self.nodata == "nan" else float(self.nodata)
self.resampling_method = self.resampling_method.value # type: ignore
self.reproject_method = self.reproject_method.value # type: ignore
```

#### render_dependency
Expand Down
9 changes: 9 additions & 0 deletions docs/src/endpoints/cog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The `/cog` routes are based on `titiler.core.factory.TilerFactory` but with `cog
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -80,6 +81,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -118,6 +120,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -154,6 +157,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -188,6 +192,7 @@ Note: if `height` and `width` are provided `max_size` will be ignored.
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.

Example:

Expand All @@ -212,6 +217,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -246,6 +252,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -304,6 +311,7 @@ Advanced raster statistics
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **categorical** (bool): Return statistics for categorical dataset, default is false.
- **c** (array[float]): Pixels values for categories.
- **p** (array[int]): Percentile values.
Expand All @@ -330,6 +338,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **categorical** (bool): Return statistics for categorical dataset, default is false.
- **c** (array[float]): Pixels values for categories.
- **p** (array[int]): Percentile values.
Expand Down
10 changes: 10 additions & 0 deletions docs/src/endpoints/stac.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The `/stac` routes are based on `titiler.core.factory.MultiBaseTilerFactory` but
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -87,6 +88,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -129,6 +131,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -168,6 +171,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -204,6 +208,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.

!!! important
**assets** OR **expression** is required
Expand Down Expand Up @@ -232,6 +237,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -270,6 +276,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **rescale** (array[str]): Comma (',') delimited Min,Max range (e.g `rescale=0,1000`, `rescale=0,1000&rescale=0,3000&rescale=0,2000`).
- **color_formula** (str): rio-color formula.
- **colormap** (str): JSON encoded custom Colormap.
Expand Down Expand Up @@ -345,6 +352,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **categorical** (bool): Return statistics for categorical dataset, default is false.
- **c** (array[float]): Pixels values for categories.
- **p** (array[int]): Percentile values.
Expand All @@ -370,6 +378,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **categorical** (bool): Return statistics for categorical dataset, default is false.
- **c** (array[float]): Pixels values for categories.
- **p** (array[int]): Percentile values.
Expand Down Expand Up @@ -399,6 +408,7 @@ Example:
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
- **reproject** (str): rasterio resampling method to use for reprojection. Default is `nearest`.
- **categorical** (bool): Return statistics for categorical dataset, default is false.
- **c** (array[float]): Pixels values for categories.
- **p** (array[int]): Percentile values.
Expand Down
5 changes: 5 additions & 0 deletions src/titiler/core/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,16 @@ def is_nan(params=Depends(dependencies.DatasetParams)):
assert not response.json()["nodata"]
assert not response.json()["unscale"]
assert response.json()["resampling_method"] == "nearest"
assert response.json()["reproject_method"] == "nearest"

response = client.get("/?resampling=cubic")
assert not response.json()["nodata"]
assert not response.json()["unscale"]
assert response.json()["resampling_method"] == "cubic"
assert response.json()["reproject_method"] == "nearest"

response = client.get("/?reproject=bilinear")
assert response.json()["reproject_method"] == "bilinear"

response = client.get("/?nodata=10")
assert response.json()["nodata"] == 10.0
Expand Down
10 changes: 9 additions & 1 deletion src/titiler/core/titiler/core/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rio_tiler.colormap import cmap as default_cmap
from rio_tiler.colormap import parse_color
from rio_tiler.errors import MissingAssets, MissingBands
from rio_tiler.types import RIOResampling
from rio_tiler.types import RIOResampling, WarpResampling
from typing_extensions import Annotated


Expand Down Expand Up @@ -365,12 +365,20 @@ class DatasetParams(DefaultDependency):
description="Resampling method.",
),
] = "nearest"
reproject_method: Annotated[
WarpResampling,
Query(
alias="reproject",
description="Reprojection method.",
),
] = "nearest"

def __post_init__(self):
"""Post Init."""
if self.nodata is not None:
self.nodata = numpy.nan if self.nodata == "nan" else float(self.nodata)
self.resampling_method = self.resampling_method
self.reproject_method = self.reproject_method


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion src/titiler/core/titiler/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class BaseTilerFactory(metaclass=abc.ABCMeta):
# Path Dependency
path_dependency: Callable[..., Any] = DatasetPathParams

# Rasterio Dataset Options (nodata, unscale, resampling)
# Rasterio Dataset Options (nodata, unscale, resampling, reproject)
dataset_dependency: Type[DefaultDependency] = DatasetParams

# Indexes/Expression Dependencies
Expand Down
Loading