Skip to content

Commit

Permalink
Point to return masked values (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago authored Nov 5, 2024
1 parent e137d67 commit 40c4143
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@

* add `gif` media type

* `/point` endpoint returned masked values (`None` is nodata)

### titiler.mosaic

* Rename `reader` attribute to `backend` in `MosaicTilerFactory` **breaking change**
Expand All @@ -102,6 +104,8 @@

* add OGC Tiles `/tiles` and `/tiles/{tileMatrixSet}` endpoints

* `/point` endpoint returned masked values (`None` is nodata)

### titiler.extensions

* Encode URL for cog_viewer and stac_viewer (author @guillemc23, https://github.com/developmentseed/titiler/pull/961)
Expand Down
7 changes: 7 additions & 0 deletions src/titiler/core/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ def test_TilerFactory():
assert len(response.json()["values"]) == 1
assert response.json()["band_names"] == ["b1"]

# Masked values
response = client.get(f"/point/-59.337,73.9898?url={DATA_DIR}/cog.tif&nodata=1")
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
assert response.json()["values"] == [None]
assert response.json()["band_names"] == ["b1"]

response = client.get(
f"/point/-6259272.328324187,12015838.020930404?url={DATA_DIR}/cog.tif&coord_crs=EPSG:3857"
)
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 @@ -1178,7 +1178,7 @@ def point(

return {
"coordinates": [lon, lat],
"values": pts.data.tolist(),
"values": pts.array.tolist(),
"band_names": pts.band_names,
}

Expand Down
4 changes: 2 additions & 2 deletions src/titiler/core/titiler/core/models/responses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""TiTiler response models."""

from typing import Dict, List, Union
from typing import Dict, List, Optional, Union

from geojson_pydantic.features import Feature, FeatureCollection
from geojson_pydantic.geometries import Geometry, MultiPolygon, Polygon
Expand All @@ -19,7 +19,7 @@ class Point(BaseModel):
"""

coordinates: List[float]
values: List[float]
values: List[Optional[float]]
band_names: List[str]


Expand Down
19 changes: 19 additions & 0 deletions src/titiler/mosaic/tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ def test_MosaicTilerFactory():
params={"url": mosaic_file},
)
assert response.status_code == 200
assert response.json()["coordinates"]
v = response.json()["values"]
assert len(v) == 1
values = v[0][1]
assert len(values) == 3
assert values[0]

# Masked values
response = client.get(
"/mosaic/point/-75.759,46.3847",
params={"url": mosaic_file},
)
assert response.status_code == 200
assert response.json()["coordinates"]
v = response.json()["values"]
assert len(v) == 1
values = v[0][1]
assert len(values) == 3
assert values[0] is None

response = client.get(
"/mosaic/point/-7903683.846322423,5780349.220256353",
Expand Down
2 changes: 1 addition & 1 deletion src/titiler/mosaic/titiler/mosaic/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ def point(
return {
"coordinates": [lon, lat],
"values": [
(src, pts.data.tolist(), pts.band_names) for src, pts in values
(src, pts.array.tolist(), pts.band_names) for src, pts in values
],
}

Expand Down
4 changes: 2 additions & 2 deletions src/titiler/mosaic/titiler/mosaic/models/responses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""TiTiler.mosaic response models."""

from typing import List, Tuple
from typing import List, Optional, Tuple

from pydantic import BaseModel

Expand All @@ -14,4 +14,4 @@ class Point(BaseModel):
"""

coordinates: List[float]
values: List[Tuple[str, List[float], List[str]]]
values: List[Tuple[str, List[Optional[float]], List[str]]]

0 comments on commit 40c4143

Please sign in to comment.