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

Rename query parameters #694

Merged
merged 2 commits into from
Aug 29, 2023
Merged
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
28 changes: 22 additions & 6 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
# Release Notes

## 0.14.0 (unreleased)

### titiler.core

* replace `-` by `_` in query parameters **breaking change**
- `coord-crs` -> `coord_crs`
- `dst-crs` -> `dst_crs`

* replace `buffer` and `color_formula` endpoint parameters by external dependencies (`BufferParams` and `ColorFormulaParams`)

### titiler.extension

* rename `geom-densify-pts` to `geometry_densify` **breaking change**
* rename `geom-precision` to `geometry_precision` **breaking change**


## 0.13.3 (2023-08-27)

- fix Factories `url_for` method and avoid changing `Request.path_params` object
* fix Factories `url_for` method and avoid changing `Request.path_params` object

## 0.13.2 (2023-08-24)

### titiler.extensions

- replace mapbox-gl by maplibre
- replace Stamen by OpenStreetMap tiles
- simplify band selection handling (author @tayden, https://github.com/developmentseed/titiler/pull/688)
* replace mapbox-gl by maplibre
* replace Stamen by OpenStreetMap tiles
* simplify band selection handling (author @tayden, https://github.com/developmentseed/titiler/pull/688)

## 0.13.1 (2023-08-21)

### titiler.core

- fix `LowerCaseQueryStringMiddleware` unexpectedly truncating query parameters (authors @jthetzel and @jackharrhy, @https://github.com/developmentseed/titiler/pull/677)
* fix `LowerCaseQueryStringMiddleware` unexpectedly truncating query parameters (authors @jthetzel and @jackharrhy, @https://github.com/developmentseed/titiler/pull/677)

## titiler.application

- add `cors_allow_methods` in `ApiSettings` to control the CORS allowed methods (author @ubi15, https://github.com/developmentseed/titiler/pull/684)
* add `cors_allow_methods` in `ApiSettings` to control the CORS allowed methods (author @ubi15, https://github.com/developmentseed/titiler/pull/684)

## 0.13.0 (2023-07-27)

Expand Down
8 changes: 4 additions & 4 deletions docs/src/endpoints/cog.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Example:
- **url** (str): Cloud Optimized GeoTIFF URL. **Required**
- **bidx** (array[int]): Dataset band indexes (e.g `bidx=1`, `bidx=1&bidx=2&bidx=3`).
- **expression** (str): rio-tiler's band math expression (e.g `expression=b1/b2`).
- **coord-crs** (str): Coordinate Reference System of the input coordinates. Default to `epsg:4326`.
- **coord_crs** (str): Coordinate Reference System of the input coordinates. Default to `epsg:4326`.
- **max_size** (int): Max image size, default is 1024.
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
Expand Down Expand Up @@ -149,7 +149,7 @@ Example:
- **url** (str): Cloud Optimized GeoTIFF URL. **Required**
- **bidx** (array[int]): Dataset band indexes (e.g `bidx=1`, `bidx=1&bidx=2&bidx=3`).
- **expression** (str): rio-tiler's band math expression (e.g `expression=b1/b2`).
- **coord-crs** (str): Coordinate Reference System of the input geometry coordinates. Default to `epsg:4326`.
- **coord_crs** (str): Coordinate Reference System of the input geometry coordinates. Default to `epsg:4326`.
- **max_size** (int): Max image size, default is 1024.
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
Expand Down Expand Up @@ -184,7 +184,7 @@ Note: if `height` and `width` are provided `max_size` will be ignored.
- **url** (str): Cloud Optimized GeoTIFF URL. **Required**
- **bidx** (array[int]): Dataset band indexes (e.g `bidx=1`, `bidx=1&bidx=2&bidx=3`).
- **expression** (str): rio-tiler's band math expression (e.g `expression=b1/b2`).
- **coord-crs** (str): Coordinate Reference System of the input coordinates. Default to `epsg:4326`.
- **coord_crs** (str): Coordinate Reference System of the input coordinates. Default to `epsg:4326`.
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
Expand Down Expand Up @@ -323,7 +323,7 @@ Example:
- **url** (str): Cloud Optimized GeoTIFF URL. **Required**
- **bidx** (array[int]): Dataset band indexes (e.g `bidx=1`, `bidx=1&bidx=2&bidx=3`).
- **expression** (str): rio-tiler's band math expression (e.g `expression=b1/b2`).
- **coord-crs** (str): Coordinate Reference System of the input geometry coordinates. Default to `epsg:4326`.
- **coord_crs** (str): Coordinate Reference System of the input geometry coordinates. Default to `epsg:4326`.
- **max_size** (int): Max image size from which to calculate statistics, default is 1024.
- **height** (int): Force image height from which to calculate statistics.
- **width** (int): Force image width from which to calculate statistics.
Expand Down
8 changes: 4 additions & 4 deletions docs/src/endpoints/stac.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Example:
- **expression** (str): rio-tiler's math expression with asset names (e.g `Asset1_b1/Asset2_b1`).
- **asset_as_band** (bool): tell rio-tiler that each asset is a 1 band dataset, so expression `Asset1/Asset2` can be passed.
- **asset_bidx** (array[str]): Per asset band math expression (e.g `Asset1|1,2,3`).
- **coord-crs** (str): Coordinate Reference System of the input coordinates. Default to `epsg:4326`.
- **coord_crs** (str): Coordinate Reference System of the input coordinates. Default to `epsg:4326`.
- **max_size** (int): Max image size, default is 1024.
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
Expand Down Expand Up @@ -163,7 +163,7 @@ Example:
- **expression** (str): rio-tiler's math expression with asset names (e.g `Asset1_b1/Asset2_b1`).
- **asset_as_band** (bool): tell rio-tiler that each asset is a 1 band dataset, so expression `Asset1/Asset2` can be passed.
- **asset_bidx** (array[str]): Per asset band math expression (e.g `Asset1|1,2,3`).
- **coord-crs** (str): Coordinate Reference System of the input geometry coordinates. Default to `epsg:4326`.
- **coord_crs** (str): Coordinate Reference System of the input geometry coordinates. Default to `epsg:4326`.
- **max_size** (int): Max image size, default is 1024.
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
Expand Down Expand Up @@ -200,7 +200,7 @@ Example:
- **expression** (str): rio-tiler's math expression with asset names (e.g `Asset1_b1/Asset2_b1`).
- **asset_as_band** (bool): tell rio-tiler that each asset is a 1 band dataset, so expression `Asset1/Asset2` can be passed.
- **asset_bidx** (array[str]): Per asset band math expression (e.g `Asset1|1,2,3`).
- **coord-crs** (str): Coordinate Reference System of the input coordinates. Default to `epsg:4326`.
- **coord_crs** (str): Coordinate Reference System of the input coordinates. Default to `epsg:4326`.
- **nodata** (str, int, float): Overwrite internal Nodata value.
- **unscale** (bool): Apply dataset internal Scale/Offset.
- **resampling** (str): rasterio resampling method. Default is `nearest`.
Expand Down Expand Up @@ -392,7 +392,7 @@ Example:
- **expression** (str): rio-tiler's math expression with asset names (e.g `Asset1_b1/Asset2_b1`).
- **asset_as_band** (bool): tell rio-tiler that each asset is a 1 band dataset, so expression `Asset1/Asset2` can be passed.
- **asset_bidx** (array[str]): Per asset band math expression (e.g `Asset1|1,2,3`).
- **coord-crs** (str): Coordinate Reference System of the input geometry coordinates. Default to `epsg:4326`.
- **coord_crs** (str): Coordinate Reference System of the input geometry coordinates. Default to `epsg:4326`.
- **max_size** (int): Max image size from which to calculate statistics, default is 1024.
- **height** (int): Force image height from which to calculate statistics.
- **width** (int): Force image width from which to calculate statistics.
Expand Down
14 changes: 7 additions & 7 deletions src/titiler/core/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_TilerFactory():
assert response.json()["band_names"] == ["b1"]

response = client.get(
f"/point/-6259272.328324187,12015838.020930404?url={DATA_DIR}/cog.tif&coord-crs=EPSG:3857"
f"/point/-6259272.328324187,12015838.020930404?url={DATA_DIR}/cog.tif&coord_crs=EPSG:3857"
)
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
Expand Down Expand Up @@ -1591,7 +1591,7 @@ def custom_rescale_params() -> Optional[RescaleType]:


def test_dst_crs_option():
"""test dst-crs parameter."""
"""test dst_crs parameter."""
app = FastAPI()
app.include_router(TilerFactory().router)

Expand All @@ -1605,7 +1605,7 @@ def test_dst_crs_option():
32621
) # return the image in the original CRS

response = client.get(f"/preview.tif?url={DATA_DIR}/cog.tif&dst-crs=epsg:4326")
response = client.get(f"/preview.tif?url={DATA_DIR}/cog.tif&dst_crs=epsg:4326")
meta = parse_img(response.content)
assert meta["crs"] == CRS.from_epsg(4326)
assert not meta["crs"] == CRS.from_epsg(32621)
Expand All @@ -1622,20 +1622,20 @@ def test_dst_crs_option():

# Force output in epsg:32621
response = client.get(
f"/crop/-56.228,72.715,-54.547,73.188.tif?url={DATA_DIR}/cog.tif&dst-crs=epsg:32621"
f"/crop/-56.228,72.715,-54.547,73.188.tif?url={DATA_DIR}/cog.tif&dst_crs=epsg:32621"
)
meta = parse_img(response.content)
assert meta["crs"] == CRS.from_epsg(32621)

# coord-crs + dst-crs
# coord_crs + dst_crs
response = client.get(
f"/crop/-6259272.328324187,12015838.020930404,-6072144.264300693,12195445.265479913.tif?url={DATA_DIR}/cog.tif&coord-crs=epsg:3857"
f"/crop/-6259272.328324187,12015838.020930404,-6072144.264300693,12195445.265479913.tif?url={DATA_DIR}/cog.tif&coord_crs=epsg:3857"
)
meta = parse_img(response.content)
assert meta["crs"] == CRS.from_epsg(3857)

response = client.get(
f"/crop/-6259272.328324187,12015838.020930404,-6072144.264300693,12195445.265479913.tif?url={DATA_DIR}/cog.tif&coord-crs=epsg:3857&dst-crs=epsg:32621"
f"/crop/-6259272.328324187,12015838.020930404,-6072144.264300693,12195445.265479913.tif?url={DATA_DIR}/cog.tif&coord_crs=epsg:3857&dst_crs=epsg:32621"
)
meta = parse_img(response.content)
assert meta["crs"] == CRS.from_epsg(32621)
31 changes: 29 additions & 2 deletions src/titiler/core/titiler/core/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def CoordCRSParams(
crs: Annotated[
Optional[str],
Query(
alias="coord-crs",
alias="coord_crs",
description="Coordinate Reference System of the input coords. Default to `epsg:4326`.",
),
] = None,
Expand All @@ -502,7 +502,7 @@ def DstCRSParams(
crs: Annotated[
Optional[str],
Query(
alias="dst-crs",
alias="dst_crs",
description="Output Coordinate Reference System.",
),
] = None,
Expand All @@ -512,3 +512,30 @@ def DstCRSParams(
return CRS.from_user_input(crs)

return None


def BufferParams(
buffer: Annotated[
Optional[float],
Query(
gt=0,
title="Tile buffer.",
description="Buffer on each side of the given tile. It must be a multiple of `0.5`. Output **tilesize** will be expanded to `tilesize + 2 * buffer` (e.g 0.5 = 257x257, 1.0 = 258x258).",
),
] = None,
) -> Optional[float]:
"""Tile buffer Parameter."""
return buffer


def ColorFormulaParams(
color_formula: Annotated[
Optional[str],
Query(
title="Color Formula",
description="rio-color formula (info: https://github.com/mapbox/rio-color)",
),
] = None,
) -> Optional[str]:
"""ColorFormula Parameter."""
return color_formula
94 changes: 13 additions & 81 deletions src/titiler/core/titiler/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
BandsExprParamsOptional,
BandsParams,
BidxExprParams,
BufferParams,
ColorFormulaParams,
ColorMapParams,
CoordCRSParams,
DatasetParams,
Expand Down Expand Up @@ -521,23 +523,10 @@ def tile(
src_path=Depends(self.path_dependency),
layer_params=Depends(self.layer_dependency),
dataset_params=Depends(self.dataset_dependency),
buffer: Annotated[
Optional[float],
Query(
gt=0,
title="Tile buffer.",
description="Buffer on each side of the given tile. It must be a multiple of `0.5`. Output **tilesize** will be expanded to `tilesize + 2 * buffer` (e.g 0.5 = 257x257, 1.0 = 258x258).",
),
] = None,
buffer=Depends(BufferParams),
post_process=Depends(self.process_dependency),
rescale=Depends(self.rescale_dependency),
color_formula: Annotated[
Optional[str],
Query(
title="Color Formula",
description="rio-color formula (info: https://github.com/mapbox/rio-color)",
),
] = None,
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
reader_params=Depends(self.reader_dependency),
Expand Down Expand Up @@ -625,23 +614,10 @@ def tilejson(
] = None,
layer_params=Depends(self.layer_dependency),
dataset_params=Depends(self.dataset_dependency),
buffer: Annotated[
Optional[float],
Query(
gt=0,
title="Tile buffer.",
description="Buffer on each side of the given tile. It must be a multiple of `0.5`. Output **tilesize** will be expanded to `tilesize + 2 * buffer` (e.g 0.5 = 257x257, 1.0 = 258x258).",
),
] = None,
buffer=Depends(BufferParams),
post_process=Depends(self.process_dependency),
rescale=Depends(self.rescale_dependency),
color_formula: Annotated[
Optional[str],
Query(
title="Color Formula",
description="rio-color formula (info: https://github.com/mapbox/rio-color)",
),
] = None,
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
reader_params=Depends(self.reader_dependency),
Expand Down Expand Up @@ -718,23 +694,10 @@ def map_viewer(
] = None,
layer_params=Depends(self.layer_dependency),
dataset_params=Depends(self.dataset_dependency),
buffer: Annotated[
Optional[float],
Query(
gt=0,
title="Tile buffer.",
description="Buffer on each side of the given tile. It must be a multiple of `0.5`. Output **tilesize** will be expanded to `tilesize + 2 * buffer` (e.g 0.5 = 257x257, 1.0 = 258x258).",
),
] = None,
buffer=Depends(BufferParams),
post_process=Depends(self.process_dependency),
rescale=Depends(self.rescale_dependency),
color_formula: Annotated[
Optional[str],
Query(
title="Color Formula",
description="rio-color formula (info: https://github.com/mapbox/rio-color)",
),
] = None,
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
reader_params=Depends(self.reader_dependency),
Expand Down Expand Up @@ -793,23 +756,10 @@ def wmts(
] = None,
layer_params=Depends(self.layer_dependency),
dataset_params=Depends(self.dataset_dependency),
buffer: Annotated[
Optional[float],
Query(
gt=0,
title="Tile buffer.",
description="Buffer on each side of the given tile. It must be a multiple of `0.5`. Output **tilesize** will be expanded to `tilesize + 2 * buffer` (e.g 0.5 = 257x257, 1.0 = 258x258).",
),
] = None,
buffer=Depends(BufferParams),
post_process=Depends(self.process_dependency),
rescale=Depends(self.rescale_dependency),
color_formula: Annotated[
Optional[str],
Query(
title="Color Formula",
description="rio-color formula (info: https://github.com/mapbox/rio-color)",
),
] = None,
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
reader_params=Depends(self.reader_dependency),
Expand Down Expand Up @@ -940,13 +890,7 @@ def preview(
image_params=Depends(self.img_dependency),
post_process=Depends(self.process_dependency),
rescale=Depends(self.rescale_dependency),
color_formula: Annotated[
Optional[str],
Query(
title="Color Formula",
description="rio-color formula (info: https://github.com/mapbox/rio-color)",
),
] = None,
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
reader_params=Depends(self.reader_dependency),
Expand Down Expand Up @@ -1018,13 +962,7 @@ def part(
image_params=Depends(self.img_dependency),
post_process=Depends(self.process_dependency),
rescale=Depends(self.rescale_dependency),
color_formula: Annotated[
Optional[str],
Query(
title="Color Formula",
description="rio-color formula (info: https://github.com/mapbox/rio-color)",
),
] = None,
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
reader_params=Depends(self.reader_dependency),
Expand Down Expand Up @@ -1089,13 +1027,7 @@ def geojson_crop(
image_params=Depends(self.img_dependency),
post_process=Depends(self.process_dependency),
rescale=Depends(self.rescale_dependency),
color_formula: Annotated[
Optional[str],
Query(
title="Color Formula",
description="rio-color formula (info: https://github.com/mapbox/rio-color)",
),
] = None,
color_formula=Depends(ColorFormulaParams),
colormap=Depends(self.colormap_dependency),
render_params=Depends(self.render_dependency),
reader_params=Depends(self.reader_dependency),
Expand Down
4 changes: 2 additions & 2 deletions src/titiler/extensions/titiler/extensions/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ def create_stac(
geom_densify_pts: Annotated[
Optional[int],
Query(
alias="geom-densify-pts",
alias="geometry_densify",
ge=0,
description="Number of points to add to each edge to account for nonlinear edges transformation.",
),
] = 0,
geom_precision: Annotated[
Optional[int],
Query(
alias="geom-precision",
alias="geometry_precision",
ge=-1,
description="Round geometry coordinates to this number of decimal.",
),
Expand Down
Loading
Loading